:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --accent: #0066cc;
  --muted: #666666;
  --border: #cccccc;
  --flash-white: #ffffff;
  --touch-min: 44px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Screen Toggle */
.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
}

/* Header/Main Layout */
header {
  width: 100%;
  padding: 1rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

main {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  gap: 1.5rem;
}

/* Photo Frame Utility */
.photo-frame {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.photo-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Home Screen */
#screen-home main {
  justify-content: center;
  gap: 2rem;
}

.carousel-container {
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1;
}

.carousel {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#carousel-img {
  max-width: 100%;
  max-height: 100%;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

.empty-state p {
  font-size: 0.95rem;
  line-height: 1.5;
}

#camera-error {
  width: 100%;
  max-width: 400px;
  color: #cc0000;
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.4;
  min-height: 2em;
}

/* Camera Screen */
#screen-camera {
  justify-content: flex-start;
}

#screen-camera header {
  display: none;
}

#screen-camera main {
  flex: 1;
  padding: 0;
  justify-content: center;
  width: 100%;
}

.camera-main {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 0;
}

.camera-container {
  position: relative;
  width: 100%;
  flex: 1;
  background: #000;
  border-radius: 0;
  overflow: hidden;
  margin-bottom: 0;
}

#camera-video {
  width: 100%;
  height: 100%;
  display: block;
  transform: scaleX(-1);
}

.countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 4rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
  z-index: 10;
  min-width: 100px;
  text-align: center;
}

#flash-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--flash-white);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
}

#flash-overlay.flash-active {
  animation: flashPulse 0.15s ease-out;
}

@keyframes flashPulse {
  0% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #flash-overlay.flash-active {
    animation: none;
    opacity: 0;
  }
}

/* Grid Screen */
.grid-container {
  width: 100%;
  max-width: 90vw;
  max-height: 70vh;
  overflow-y: auto;
}

.grid-frame {
  width: 100%;
  padding: 10px;
  position: relative;
}

.frame-overlay-canvas {
  position: absolute;
  top: 10px;
  left: 10px;
  width: auto;
  height: auto;
  display: block;
}

.grid-photos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  height: 100%;
}

.grid-cell {
  position: relative;
  background: #f5f5f5;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-cell img {
  width: 100%;
  height: auto;
  max-height: 100%;
  display: block;
  object-fit: contain;
}


/* Edit Screen */
#screen-edit header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
}

#back-btn {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
}

.edit-frame {
  width: 100%;
  max-width: 90vw;
  max-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#edit-canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
}

.dots-indicator {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

.dot.active {
  background: var(--accent);
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-text {
  background: none;
  color: var(--accent);
  padding: 0;
  min-height: auto;
  min-width: auto;
  text-align: left;
  font-size: 1rem;
}

.btn-text:hover {
  opacity: 0.8;
}

.btn-secondary {
  background: var(--muted);
  color: white;
}

.btn-secondary:hover {
  opacity: 0.9;
}

.button-row {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.swipe-hint {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin: 0.5rem 0;
}

/* Responsive */
#capture-btn {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
}

@media (max-width: 480px) {
  header h1 {
    font-size: 1.25rem;
  }

  .countdown {
    font-size: 3rem;
  }

  main {
    padding: 0.75rem;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Prevent overscroll */
html {
  overscroll-behavior: none;
}
