* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", sans-serif;
  background: #0a0a0a;
  color: #f5f5f5;
  overflow: hidden;
  touch-action: manipulation;
}

#app { height: 100vh; height: 100dvh; }

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
.screen.active { display: flex; }

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4px 8px;
}
.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.shot-counter {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  color: #999;
}

/* Preview */
.preview-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.preview-box {
  position: absolute;
  inset: 0;
  margin: auto;
  aspect-ratio: 4 / 3;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  border-radius: 18px;
  overflow: hidden;
}
#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}
#preview.no-mirror { transform: none; }

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 180px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 30px rgba(0,0,0,0.5);
  pointer-events: none;
  animation: pulse 1s ease-out;
}
.countdown.hidden { display: none; }
@keyframes pulse {
  0% { transform: scale(1.5); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.flashing { animation: flash 0.4s ease-out; }
@keyframes flash {
  0% { opacity: 0; }
  10% { opacity: 1; }
  100% { opacity: 0; }
}

.flip-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.4);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Thumbs */
.thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 0;
}
.thumb {
  aspect-ratio: 4 / 3;
  background: #222;
  border-radius: 6px;
  border: 1.5px solid #333;
  background-size: cover;
  background-position: center;
}
.thumb.filled { border-color: #fff; }

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0;
}
.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.control-row label {
  font-size: 13px;
  color: #999;
  min-width: 70px;
  flex-shrink: 0;
}
.opts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.opts.scroll-x {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.opts.scroll-x::-webkit-scrollbar { display: none; }
.opt {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #333;
  background: #1a1a1a;
  color: #ddd;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.opt.active {
  background: #fff;
  color: #000;
  border-color: #fff;
  font-weight: 600;
}
.opt .swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 6px;
  border: 1px solid rgba(255,255,255,0.2);
}

/* Buttons */
.primary-btn, .secondary-btn {
  padding: 16px;
  border-radius: 14px;
  border: none;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 12px;
}
.primary-btn { background: #fff; color: #000; }
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.secondary-btn { background: #1a1a1a; color: #fff; border: 1px solid #333; }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Review */
.review-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
}
#composite {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.review-controls { padding-top: 0; }

/* Done / QR */
.qr-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
}
#qrcode {
  background: #fff;
  padding: 20px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
#qrcode canvas, #qrcode img { display: block; }
.qr-hint {
  font-size: 16px;
  color: #ddd;
  text-align: center;
}
.qr-url {
  font-size: 13px;
  color: #888;
  word-break: break-all;
  text-align: center;
  font-family: ui-monospace, monospace;
}
.qr-expiry {
  font-size: 12px;
  color: #666;
}

/* Status & Errors */
.status, .error {
  padding: 10px;
  text-align: center;
  font-size: 14px;
  border-radius: 8px;
  margin-top: 8px;
}
.status { color: #aaa; }
.error { color: #ff6b6b; background: rgba(255,107,107,0.1); }
.hidden { display: none !important; }

/* Landscape — side-by-side layout (only on .active to not break screen switching) */
@media (orientation: landscape) and (min-width: 768px) {
  #capture-screen.active {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      "header  header"
      "preview controls"
      "thumbs  controls"
      "start   start";
    gap: 12px;
    padding: 12px;
  }
  #capture-screen.active .header      { grid-area: header; }
  #capture-screen.active .preview-wrap{ grid-area: preview; min-height: 0; }
  #capture-screen.active .controls    { grid-area: controls; align-self: start; }
  #capture-screen.active .thumbs      { grid-area: thumbs; }
  #capture-screen.active #start-btn   { grid-area: start; margin-top: 0; }
}
