:root {
  --bg: #000000;
  --panel: #1e1e1ecc;
  --border: #3c3c3c;
  --text: #d4d4d4;
  --ok: #4ec9b0;
  --warn: #ce9178;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
}

/* The mirrored camera feed is the background -- object-fit: cover fills
   the viewport regardless of its native aspect ratio, scaleX(-1) mirrors
   it so it feels like looking in a mirror. */
#webcam-video {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  transform: scaleX(-1);
  background: #000;
}

/* Transparent overlay: the viewfinder frame outline and the vintage
   filtered crop are drawn here, on top of the live video. */
#effects-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1;
}

#status-bar {
  position: fixed;
  top: 1rem;
  left: calc(var(--strip-width, 132px) + 1rem);
  z-index: 10;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(6px);
  /* Leaves room for the (?) help button on narrow viewports (its own
     right:1rem offset plus its widest -- 40px on mobile -- size, with a
     little breathing room) and wraps onto a second line rather than
     overflowing under/behind it. */
  max-width: calc(100vw - var(--strip-width, 132px) - 5rem);
}

#brand {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.85;
}

.status-pill {
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #2d2d2d;
  border: 1px solid var(--border);
  color: var(--text);
}

/* Active style name -- cycled by a left-hand pinch. Small and unobtrusive,
   bottom-center, out of the way of the frame/countdown/skip UI above it.
   Anchored next to the strip (like #status-bar is at the top) rather than
   centered, so it can't collide with the pattern-picker swatches growing
   in from the right. */
#style-label {
  position: fixed;
  bottom: 1rem;
  left: calc(var(--strip-width, 132px) + 1rem);
  z-index: 10;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.6);
  border: 1px solid var(--border);
  color: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(4px);
  pointer-events: none;
}

/* Persistent signature, bottom-center -- matches the same "/by hhan/"
   caption baked into every saved strip. Sits low enough (0.35rem from the
   edge) to clear .size-gesture-cancel-btn's 2.5rem position when that's
   showing, and plain black like the strip caption, with just enough of a
   light glow to stay legible over a dark video feed rather than vanishing
   into it. */
#on-screen-signature {
  position: fixed;
  bottom: 0.1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-size: 0.6rem;
  line-height: 1;
  color: #000;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

/* Help button -- always on top (above any modal backdrop) so it's
   reachable to reopen the guide at any time. */
#help-button {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 50;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(6px);
  /* Some browsers don't clip backdrop-filter tightly to border-radius,
     letting the blur bleed into a soft square behind the circle. Force
     an exact circular clip so the blur stops at the button's edge. */
  clip-path: circle(50%);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Right-edge toolbar: the beauty-filter toggles stacked above the strip
   pattern swatches, one vertically-centered column -- this element (not
   #pattern-picker) now owns all the fixed positioning/responsive sizing,
   so the two groups scroll/scale together as one unit. */
#right-toolbar {
  position: fixed;
  top: 50%;
  /* Scales down on narrow viewports along with the swatches themselves,
     so the column doesn't eat into the (already width-capped) middle
     framing area any more than it has to. */
  right: clamp(0.4rem, 2vw, 1rem);
  transform: translateY(-50%);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  /* min(vw, vh) so a short LANDSCAPE viewport shrinks the gap same as a
     narrow portrait one does -- vw alone stays large in landscape and
     the column would overflow its own max-height below instead. */
  gap: clamp(0.3rem, min(1.5vw, 1.5vh), 0.6rem);
  /* Safety net if the combined button count ever grows enough to not fit
     vertically centered -- scrolls instead of running into the top/bottom
     UI. */
  max-height: 80vh;
  overflow-y: auto;
}

#beauty-picker,
#pattern-picker {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: clamp(0.3rem, min(1.5vw, 1.5vh), 0.6rem);
}

/* Thin separator between the beauty toggles and the pattern swatches --
   same shrink behavior as the swatches so it never reads as wider than
   the column it's dividing. */
#right-toolbar-divider {
  width: clamp(22px, min(5vw, 5vh), 36px);
  height: 1px;
  background: var(--border);
  margin: 0.1rem 0;
  flex: 0 0 auto;
}

.pattern-swatch {
  position: relative;
  /* Same 60px as before on desktop; shrinks on a narrow phone-portrait
     viewport (9vw) OR a short phone-landscape one (9vh) -- min() picks
     whichever dimension is actually tight -- so the column stays out of
     the way of the middle framing area and doesn't overflow its own
     max-height, but never below 38px, still comfortably tappable. */
  width: clamp(38px, min(9vw, 9vh), 60px);
  height: clamp(38px, min(9vw, 9vh), 60px);
  border-radius: 50%;
  border: 2px solid var(--border);
  background-size: cover;
  background-position: center;
  background-color: var(--panel);
  padding: 0;
  cursor: pointer;
  flex: 0 0 auto;
  --dwell-progress: 0;
}

.pattern-swatch.active {
  border-color: var(--ok);
  box-shadow: 0 0 0 2px rgba(78, 201, 176, 0.35);
}

.pattern-swatch-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  pointer-events: none;
  /* Hidden by default -- only the actual dwell-hold should show a ring,
     not a permanent faint halo around every swatch. */
  opacity: 0;
  transition: opacity 0.15s ease;
  background: conic-gradient(var(--ok, #4ec9b0) calc(var(--dwell-progress, 0) * 360deg), rgba(255, 255, 255, 0.15) 0deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 4px));
}

.pattern-swatch.dwelling .pattern-swatch-ring {
  opacity: 1;
}

/* Beauty toggles reuse .pattern-swatch's circular sizing/border/active/
   dwell-ring styling wholesale (same class) -- this just adds the bits a
   pattern swatch doesn't need: centering a text label instead of a
   background-image, since there's no thumbnail to show. */
.beauty-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: none !important;
}

/* Sized well below .pattern-swatch's own clamp() (a short word needs
   much more headroom than a single glyph did) so "Smooth" -- the longer
   of the two labels -- stays inside the circle at every size, including
   the smallest mobile swatch. Font/weight matches the app's other small
   UI labels (#brand, .btn-primary) rather than introducing a new style. */
.beauty-toggle-label {
  font-size: clamp(9px, min(2.4vw, 2.4vh), 14px);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

#help-button:hover {
  border-color: var(--ok);
  color: var(--ok);
}

.help-card {
  width: min(360px, 90vw);
}

.help-steps {
  list-style: none;
  margin: 0 0 0.85rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.85);
}

.help-steps strong {
  color: var(--ok);
}

.help-signature {
  margin: 0 0 1rem;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.4);
  text-align: center;
}

.status-pill.ok {
  color: var(--ok);
  border-color: var(--ok);
}

.status-pill.error {
  color: var(--warn);
  border-color: var(--warn);
}

/* Classic photobooth strip: a narrow cream paper column docked flush to
   the left, with a soft drop shadow like it's hanging in front of the
   video. Slot size and all margins/gaps are computed in JS
   (PhotoStrip.layout(), keyed off both window.innerHeight and
   window.innerWidth) and set as CSS custom properties here. On a
   wide/short window --strip-height comes out to exactly 100vh, so
   vertically centering it (top: 50% + translateY) looks identical to
   the old top:0/height:100vh -- it only visibly shrinks and centers
   itself once a narrow/tall viewport (phone portrait) caps the strip's
   width instead, so it never stretches edge to edge at an unreasonable
   size. */
#photo-strip {
  position: fixed;
  top: 50%;
  left: 0;
  height: var(--strip-height, 100vh);
  transform: translateY(-50%);
  z-index: 10;
  width: var(--strip-width, 132px);
  padding: var(--strip-top-margin, 16px) var(--strip-side-margin, 16px) var(--strip-bottom-margin, 48px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--strip-gap, 10px);
  /* --strip-pattern is set by updateOnScreenStripPattern() whenever the
     selected swatch changes; the gradient is just the pre-JS fallback.
     --strip-pattern-tile-size (from PhotoStrip.layout(), a *height*) sizes
     each repeat so the pattern shows real detail -- STRIP_PATTERN_TARGET_
     REPEATS controls how many times it repeats down the strip's height;
     width is auto so each pattern's own aspect ratio is preserved. */
  background: var(--strip-pattern, linear-gradient(180deg, #faf6ec, #efe8d6));
  background-repeat: repeat;
  background-size: auto var(--strip-pattern-tile-size, 200px);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5), 0 3px 8px rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
}

/* Subtle paper grain, via an inline SVG fractal-noise filter -- cheap,
   pure CSS, no per-frame cost. */
#photo-strip::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/></svg>");
}

.strip-slot {
  position: relative;
  width: var(--strip-slot-size, 112px);
  height: var(--strip-slot-size, 112px);
  flex: 0 0 auto;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid #d9d0ba;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  background: #6b6156; /* dimmed vintage-grey placeholder */
  display: flex;
  align-items: center;
  justify-content: center;
}

.strip-slot.empty {
  background: #55504a;
  border-style: dashed;
  border-color: rgba(120, 110, 90, 0.4);
}

.strip-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.slot-number {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.28);
}

/* Small save button overlaid on a filled slot's corner -- opens the
   custom-size picker for that one photo. */
.slot-save-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.85;
}

.slot-save-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.75);
}

/* Custom-size save modal. */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: min(320px, 90vw);
  /* Guards short viewports (phones in landscape) where a tall card --
     round-complete's strip preview especially -- could otherwise run off
     both edges of the screen with no way to reach its own buttons. */
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.modal-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.size-picker-preview {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: 6px;
  background: #111;
  margin-bottom: 0.75rem;
}

.size-picker-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

/* The `hidden` attribute's UA-stylesheet `display: none` otherwise loses
   to this class's own `display: flex` (same specificity, this rule comes
   later in the cascade) -- toggling `.hidden` on/off wouldn't work
   without this override. */
.size-picker-row[hidden] {
  display: none;
}

.size-picker-row label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.6);
  flex: 1;
}

.size-picker-row input[type="number"] {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #111;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.size-picker-x {
  padding-bottom: 0.5rem;
  opacity: 0.5;
}

.size-picker-lock {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 1rem;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.btn-secondary,
.btn-primary {
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
}

.btn-primary {
  background: var(--ok);
  color: #06251f;
  border-color: var(--ok);
  font-weight: 600;
}

.btn-primary:disabled {
  background: #3c3c3c;
  border-color: var(--border);
  color: rgba(255, 255, 255, 0.35);
  cursor: not-allowed;
}

/* Click-to-capture buttons (Quick Shot / Countdown Shot) -- visible on
   EVERY device, alongside the two-hand pinch gesture; the .mobile-capture
   body class (set by MobileDetect) no longer gates whether these show at
   all, only whether saving prefers the Web Share API (see
   saveCanvasesAsPng in script.js). They started mobile-only, since
   forming a precise two-hand frame is awkward on a phone/tablet, but a
   plain clickable button is just as welcome on desktop -- there was no
   reason to withhold it there. */
#mobile-capture-controls {
  display: flex;
  position: fixed;
  /* High enough to clear #style-label + #on-screen-signature's own
     bottom-anchored band (they're left-anchored/centered respectively,
     not wide, but a horizontally-CENTERED row can still overlap them on
     a narrow phone width where its bounding box spans past their x
     range) -- measured/verified via getBoundingClientRect at 375px
     width, not just eyeballed. */
  bottom: 3.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  gap: 0.75rem;
}

/* The `hidden` attribute's UA-stylesheet `display: none` would otherwise
   lose to the more specific `display: flex` just above (same pattern
   already hit elsewhere in this file, e.g. .size-picker-row[hidden]) --
   this is what MobileCaptureControls.update() actually toggles while a
   modal is open. */
#mobile-capture-controls[hidden] {
  display: none;
}

.mobile-capture-btn {
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  border-radius: 999px;
  white-space: nowrap;
}

.mobile-capture-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Only shown as a fallback when the Web Share API path (mobile) isn't
   available/didn't succeed -- see saveCanvasesAsPng in script.js. High
   z-index since a save is often triggered from inside a modal that's
   about to close, and the toast needs to stay visible through that. */
#save-toast {
  position: fixed;
  bottom: 7.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  backdrop-filter: blur(6px);
  pointer-events: none;
  max-width: min(320px, 80vw);
  text-align: center;
}

#save-toast[hidden] {
  display: none;
}

/* Photo preview + retake: full-screen, right after every capture. Reuses
   .modal-overlay's dark backdrop/centering, just stacked as a column
   instead of showing a card. */
.photo-preview-overlay {
  flex-direction: column;
  gap: 1.5rem;
}

.photo-preview-image {
  display: block;
  max-width: min(70vw, 640px);
  max-height: 65vh;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5), 0 3px 8px rgba(0, 0, 0, 0.35);
  object-fit: contain;
}

.photo-preview-actions {
  display: flex;
  gap: 1rem;
}

.photo-preview-btn {
  position: relative;
  overflow: hidden;
  padding: 0.6rem 1.8rem;
  font-size: 0.95rem;
}

/* Dwell-to-select progress: a thin bar filling left-to-right along the
   button's bottom edge, driven by --dwell-progress (set every frame while
   either hand's index fingertip hovers it -- see PhotoPreview.update()) --
   same underlying gesture as the strip-pattern swatches, just a bar
   instead of a ring since these buttons are rectangular, not circular. */
.photo-preview-btn::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: calc(var(--dwell-progress, 0) * 100%);
  background: var(--ok);
  transition: width 0.05s linear;
}

.photo-preview-btn.dwelling {
  box-shadow: 0 0 0 2px rgba(78, 201, 176, 0.4);
}

/* Round-complete save-choice modal. */
.round-complete-card {
  width: min(360px, 90vw);
}

/* The actual composed strip -- pattern, photos, and signature caption,
   exactly what "Save Strip" would produce -- scaled down to fit the
   modal instead of 4 separate thumbnails. */
.round-complete-strip-preview {
  display: block;
  max-width: 100%;
  max-height: 280px;
  margin: 0 auto 1rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.round-complete-section {
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}

.round-complete-section:first-of-type {
  border-top: none;
  padding-top: 0;
}

.round-complete-label {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.6);
}

.round-size-choice {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
}

.round-size-choice label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.round-complete-btn {
  width: 100%;
}

/* Custom size, set by hand gesture rather than typed -- a readout of the
   currently-drawn size plus a button to (re)draw it. */
.round-custom-gesture {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.75);
}

.round-custom-gesture[hidden] {
  display: none;
}

.round-custom-gesture .btn-secondary {
  flex: 0 0 auto;
  white-space: nowrap;
}

.size-gesture-cancel-btn {
  position: fixed;
  bottom: 2.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: rgba(20, 20, 20, 0.85);
  backdrop-filter: blur(6px);
}

.size-gesture-cancel-btn[hidden] {
  display: none;
}

/* --- Mobile / small-viewport adjustments ---------------------------------
   Everything else in this file already scales via CSS custom properties
   computed in JS (--strip-*, keyed off both innerWidth and innerHeight --
   see PhotoStrip.layout()) or clamp() (the pattern swatches). This block
   covers the couple of things that need an actual breakpoint: bumping
   small tap targets up to a comfortable touch size, and giving the
   full-screen photo preview more headroom on short (phone landscape)
   viewports so its Keep/Retake buttons can't get pushed off-screen. */
@media (max-width: 480px) {
  #help-button {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  .slot-save-btn {
    width: 26px;
    height: 26px;
    font-size: 13px;
  }
}

@media (max-height: 480px) {
  .photo-preview-image {
    max-height: 50vh;
  }

  .photo-preview-overlay {
    gap: 0.75rem;
  }
}
/* -------------------------------------------------------------------------- */
