/* Fright Face - a backstage makeup mirror. The camera is the star; controls
   sit on smoky glass. The look picker is styled like a greasepaint palette:
   round pans in a gold-rimmed tray. */

:root {
  --plum: #1d1219;        /* backstage dark */
  --glass: rgba(29, 18, 25, 0.58);
  --bone: #efe6d2;        /* text */
  --bone-dim: #b9ad9b;
  --candle: #f2a541;      /* active, shutter */
  --blood: #7a1c22;       /* secondary accent */
  --brass: #b98b3e;       /* tray rims */
  --display: 'Pirata One', 'Georgia', serif;
  --body: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--plum);
  color: var(--bone);
  font: 400 16px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--candle); outline-offset: 3px; }

/* ---- Stage ---- */
.camera-feed { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0.01; pointer-events: none; }
#stage { position: fixed; inset: 0; }
.stage-canvas { display: block; }
.stage-canvas.mirrored { transform: scaleX(-1); }

/* ---- Live controls (hidden until running) ---- */
.topbar, .tray { opacity: 0; pointer-events: none; transition: opacity 0.4s; }
body.running .topbar, body.running .tray { opacity: 1; pointer-events: auto; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: linear-gradient(var(--glass), transparent);
}

.wordmark {
  margin: 0;
  font: 400 26px/1 var(--display);
  letter-spacing: 0.01em;
  color: var(--bone);
}
.wordmark.big { font-size: clamp(44px, min(16vw, 14vh), 92px); line-height: 0.9; }

.now-wearing {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
}
#look-title { font: 400 22px/1.05 var(--display); }
#look-tagline { font-size: 13px; color: var(--bone-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }


/* ---- Tray: palette + shutter ---- */
.tray {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 0 calc(16px + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: linear-gradient(transparent, var(--glass) 35%);
}

.palette {
  display: flex;
  gap: 10px;
  max-width: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 10px 16px;
  scrollbar-width: none;
}
.palette::-webkit-scrollbar { display: none; }

.look {
  flex: 0 0 auto;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 76px;
  padding: 0;
  border: 0;
  background: none;
}
.look-thumb {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  /* the brass rim of a paint pan */
  box-shadow: 0 0 0 3px var(--brass), 0 0 0 4px rgba(0, 0, 0, 0.5), inset 0 2px 6px rgba(0, 0, 0, 0.6);
  transition: transform 0.18s, box-shadow 0.18s;
}
.look-name { font-size: 12px; font-weight: 600; color: var(--bone-dim); white-space: nowrap; }
.look[aria-pressed='true'] .look-thumb {
  transform: scale(1.12);
  box-shadow: 0 0 0 3px var(--candle), 0 0 18px 2px rgba(242, 165, 65, 0.55);
}
.look[aria-pressed='true'] .look-name { color: var(--bone); }

.shutter {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 4px solid var(--bone);
  background: radial-gradient(circle, var(--candle) 0 52%, transparent 54%);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  transition: transform 0.1s;
}
.shutter:active { transform: scale(0.92); }
.shutter {
  position: relative;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
/* Recording: red centre, ring fills up to the time limit */
.shutter.recording,
.shutter.recording:active {
  transform: scale(1.15);
  border-color: rgba(239, 230, 210, 0.35);
  background: radial-gradient(circle, #d8232c 0 30%, transparent 32%);
}
.shutter.recording::before {
  content: '';
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  background: conic-gradient(#e2323a calc(var(--rec, 0) * 1turn), rgba(239, 230, 210, 0.18) 0);
  -webkit-mask: radial-gradient(circle, transparent 61%, #000 63%);
  mask: radial-gradient(circle, transparent 61%, #000 63%);
}
.rec-badge {
  position: fixed;
  top: calc(64px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 12px 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font: 600 14px/1.4 var(--body);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 7px;
  z-index: 5;
}
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #e2323a; animation: rec-blink 1s steps(2) infinite; }
@keyframes rec-blink { 50% { opacity: 0.25; } }

/* One-time tips */
.tip {
  position: fixed;
  top: calc(66px + var(--safe-t));
  left: 50%;
  width: max-content;
  max-width: min(320px, calc(100% - 32px));
  margin: 0;
  padding: 9px 14px;
  border-radius: 14px;
  background: rgba(29, 18, 25, 0.88);
  border: 1px solid rgba(242, 165, 65, 0.65);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  font-size: 15px;
  text-align: center;
  z-index: 6;
  cursor: pointer;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.35s, transform 0.35s;
}
.tip.show { opacity: 1; transform: translate(-50%, 0); }

/* Shutter in the middle, "transform again" button to its left */
.shutter-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  width: 100%;
}
.shutter-row .shutter { grid-column: 2; }
.replay {
  grid-column: 1;
  justify-self: end;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(239, 230, 210, 0.35);
  background: var(--glass);
  color: var(--bone);
  display: grid;
  place-items: center;
}

.haunted-toggle {
  grid-column: 3;
  justify-self: start;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(239, 230, 210, 0.35);
  background: var(--glass);
  color: var(--bone);
  display: grid;
  place-items: center;
  transition: color 0.3s, box-shadow 0.3s, border-color 0.3s;
}
.haunted-toggle[aria-pressed="true"] {
  color: #cfe3ff;
  border-color: rgba(190, 215, 255, 0.7);
  box-shadow: 0 0 14px rgba(150, 190, 255, 0.55), inset 0 0 8px rgba(150, 190, 255, 0.35);
}
/* Haunted Mirror: the controls go cold and dim with the room */
body.haunted .topbar { background: linear-gradient(rgba(6, 6, 10, 0.7), transparent); }
body.haunted .wordmark { color: #cfd6e2; text-shadow: 0 0 10px rgba(150, 190, 255, 0.45); }

/* ---- Paint it for real ---- */
.paint-real {
  grid-column: 3;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(242, 165, 65, 0.6);
  background: var(--glass);
  color: var(--bone);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.paint-real svg { color: var(--candle); }
body.tutorial .paint-real { visibility: hidden; }
body.tutorial #filters, body.tutorial #looks, body.tutorial #replay { display: none; }

.tutorial {
  position: relative;
  width: min(100% - 32px, 460px);
  padding: 12px 14px 10px;
  border-radius: 18px;
  background: rgba(29, 18, 25, 0.86);
  border: 1px solid rgba(185, 139, 62, 0.55);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}
.tutorial-close {
  position: absolute;
  top: 6px; right: 8px;
  width: 36px; height: 36px;
  border: 0;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--bone-dim);
}
.tutorial-fold {
  position: absolute;
  top: 6px; right: 44px;
  width: 36px; height: 36px;
  border: 0;
  background: none;
  color: var(--bone-dim);
  display: grid;
  place-items: center;
  transition: transform 0.2s;
}
.tutorial.folded .tutorial-fold { transform: rotate(180deg); }
.tutorial.folded .tutorial-how,
.tutorial.folded .tutorial-supplies,
.tutorial.folded .tutorial-hint { display: none; }
.tutorial-count {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--candle);
}
.tutorial-title { margin: 2px 80px 4px 0; font: 400 24px/1.1 var(--display); }
.tutorial-how { margin: 0 0 6px; font-size: 15px; line-height: 1.35; }
.tutorial-supplies { margin: 0 0 10px; padding: 0; list-style: none; font-size: 13px; color: var(--bone-dim); }
.tutorial-supplies li + li { margin-top: 2px; }
.tutorial-supplies b { color: var(--bone); font-weight: 600; }
.tutorial-nav { display: flex; gap: 10px; }
.tutorial-nav button {
  flex: 1;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 15px;
}
.tutorial-back { border: 1px solid rgba(239, 230, 210, 0.35); background: none; }
.tutorial-back:disabled { opacity: 0.35; }
.tutorial-next { border: 0; background: var(--candle); color: #2a1608; }
.tutorial-hint { margin: 6px 0 0; font-size: 12px; color: var(--bone-dim); text-align: center; transition: color 0.2s; }
.tutorial-hint.primed { color: var(--candle); font-weight: 700; }

/* Category chips above the palette */
.filters {
  display: flex;
  gap: 6px;
  max-width: 100%;
  overflow-x: auto;
  padding: 0 16px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid rgba(239, 230, 210, 0.3);
  background: var(--glass);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--bone-dim);
}
.chip[aria-pressed='true'] { color: #2a1608; background: var(--candle); border-color: var(--candle); }
.palette[data-empty='true']::after {
  content: 'No looks match';
  color: var(--bone-dim);
  font-size: 14px;
  padding: 24px 0;
}
span.look-thumb { display: block; background: #2a1d24; }

/* ---- Messages ---- */
.hint, .status {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-weight: 600;
  text-align: center;
  max-width: calc(100% - 32px);
}
.status { top: auto; bottom: 30%; z-index: 30; }

/* ---- Start screen ---- */
.start {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto; /* short screens (phone on its side): scroll to the buttons */
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(242, 165, 65, 0.18), transparent 60%),
    var(--plum);
}
.mirror {
  width: min(440px, 100%);
  padding: 72px 28px 28px;
  border-radius: 200px 200px 24px 24px;   /* an arched dressing-room mirror */
  border: 2px solid var(--brass);
  background: linear-gradient(180deg, rgba(239, 230, 210, 0.06), rgba(239, 230, 210, 0.02));
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.lede { margin: 0 0 8px; font-size: 18px; max-width: 30ch; color: var(--bone); }
.fine { margin: 6px 0 0; font-size: 13px; color: var(--bone-dim); max-width: 42ch; }
.error { margin: 0; min-height: 1em; color: #ff9a8a; font-weight: 600; }

.primary {
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  background: var(--candle);
  color: #2a1608;
  font-weight: 700;
  font-size: 17px;
  min-width: 220px;
}
.quiet {
  border: 0;
  background: none;
  color: var(--bone-dim);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 8px;
  font-size: 15px;
}
.start.busy .primary, .start.busy .quiet { opacity: 0.5; pointer-events: none; }


/* ---- Photo preview ---- */
.capture {
  position: fixed;
  inset: 0;
  z-index: 26;
  background: var(--plum);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px 16px calc(16px + var(--safe-b));
}
.capture video,
.capture img {
  max-width: 100%;
  max-height: 72vh;
  border-radius: 14px;
  border: 2px solid var(--brass);
}
.capture-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }
.capture-actions .primary { min-width: 140px; }

/* ---- Debug ---- */
.debug {
  position: fixed;
  top: calc(60px + var(--safe-t));
  left: 8px;
  z-index: 40;
  padding: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  font: 12px/1.35 ui-monospace, monospace;
  white-space: pre;
}
.debug-row { display: flex; gap: 4px; margin: 6px 0; }
.debug-row button { font-size: 11px; padding: 3px 6px; background: #333; border: 0; border-radius: 4px; }
.debug canvas { display: block; border-radius: 50%; }

@media (max-width: 420px) {
  .topbar { grid-template-columns: 1fr auto; }
  .paint-real { grid-column: 2; }
  .paint-real span { display: none; }
  .paint-real { padding: 8px; }
  .topbar .wordmark { display: none; }
  .now-wearing { align-items: flex-start; text-align: left; }
}

/* Phones on their side: the tray becomes a rail down the right edge
   (looks scroll vertically, shutter column beside them) so it doesn't
   cover your face; the tutorial card sits bottom-left. */
@media (orientation: landscape) and (max-height: 500px) {
  .tray {
    left: auto;
    top: calc(54px + var(--safe-t)); /* below the top bar and its buttons */
    display: grid;
    grid-template-columns: 80px 62px;
    align-items: center;
    gap: 6px;
    padding: 4px calc(10px + env(safe-area-inset-right, 0px)) calc(8px + var(--safe-b)) 8px;
    background: linear-gradient(to right, transparent, var(--glass) 30%);
  }
  .filters { display: none; }
  .palette {
    grid-column: 1;
    grid-row: 1;
    align-self: stretch;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-snap-type: y mandatory;
    padding: 8px 0;
    gap: 8px;
  }
  .look { width: 72px; gap: 3px; }
  .look-thumb { width: 50px; height: 50px; }
  .look-name { font-size: 11px; }
  .shutter-row {
    grid-column: 2;
    grid-row: 1;
    grid-template-columns: auto;
    justify-items: center;
    gap: 14px;
    width: auto;
  }
  .shutter-row > * { grid-column: auto !important; justify-self: center !important; }
  .shutter { width: 60px; height: 60px; }
  .mirror { padding: 28px 24px 18px; gap: 8px; border-radius: 120px 120px 20px 20px; }
  .lede { font-size: 15px; margin-bottom: 2px; }
  .fine { font-size: 12px; }
  .tutorial {
    position: fixed;
    left: calc(12px + env(safe-area-inset-left, 0px));
    bottom: calc(10px + var(--safe-b));
    width: min(320px, 40vw);
    max-height: calc(100% - 70px);
    overflow-y: auto;
  }
  .tutorial-title { font-size: 20px; }
  .tutorial-how { font-size: 13px; }
  .tutorial-supplies, .tutorial-hint { font-size: 11px; }
  .tutorial-nav button { padding: 7px 10px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
.debug label.debug-row { align-items: center; white-space: normal; }

/* ---- On-screen error report ---- */
.errors {
  position: fixed;
  left: 8px; right: 8px;
  bottom: calc(8px + var(--safe-b));
  z-index: 50;
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(122, 28, 34, 0.92);
  color: #fff;
  font: 12px/1.4 ui-monospace, monospace;
  white-space: pre-wrap;
  max-height: 30vh;
  overflow: auto;
}

/* ---- Prop fitter (?fit=name) ---- */
.fitter {
  position: fixed;
  top: calc(60px + var(--safe-t));
  right: 8px;
  z-index: 40;
  width: min(300px, calc(100% - 16px));
  max-height: 60vh;
  overflow: auto;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 13px;
}
.fitter h2 { margin: 0 0 6px; font-size: 15px; }
.fitter label { display: grid; grid-template-columns: 1fr; gap: 2px; margin: 6px 0; }
.fitter label:has(input[type='range']) { grid-template-columns: 1fr auto; }
.fitter label input[type='range'] { grid-column: 1 / -1; grid-row: 2; width: 100%; }
.fitter button { margin-top: 6px; padding: 6px 12px; border: 0; border-radius: 6px; background: var(--candle); color: #2a1608; font-weight: 700; }
.fitter pre { white-space: pre-wrap; font-size: 11px; }
.fitter label:has(input[type='checkbox']) { display: flex; align-items: center; gap: 6px; }
