:root {
  --bg: #15120f;
  --ink: #f6efe6;
  --muted: #b8ab9a;
  --gold: #d6a64b;
  --gold-soft: #e7c887;
  --line: rgba(246, 239, 230, 0.14);
  --panel: rgba(21, 18, 15, 0.72);
  --radius: 16px;
  --display: 'Fraunces', Georgia, serif;
  --sans: 'Inter Tight', system-ui, sans-serif;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must win over component `display` rules below
   (.panel/.card-guide use display:grid, which would otherwise override it). */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- Stage: camera + overlay, mirrored & zoomed together ---- */
.stage {
  position: fixed;
  inset: 0;
  transform-origin: center center;
  will-change: transform;
  background: #000;
  touch-action: none; /* claim drags for rotate/pinch instead of browser pan */
}
#cam, #overlay { touch-action: none; }
#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.scrim {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, transparent 55%, rgba(0, 0, 0, 0.5) 100%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.35), transparent 22%, transparent 62%, rgba(0, 0, 0, 0.55));
}
body[data-screen='landing'] .scrim,
body[data-screen='permission'] .scrim { background: rgba(10, 8, 6, 0.78); }

/* ---- Panels (landing / permission) ---- */
.panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 7vh 1.4rem;
  z-index: 5;
}
.landing__inner, .permission__inner { max-width: 30rem; text-align: center; }
.brand {
  font-family: var(--display);
  letter-spacing: 0.02em;
  color: var(--gold-soft);
  margin: 0 0 1.4rem;
  font-size: 1.05rem;
}
.brand__mark { color: var(--gold); }
.brand--sm { margin: 0; font-size: 0.95rem; }
.display {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.6rem, 1.6rem + 5vw, 5rem);
  line-height: 0.98;
  margin: 0 0 1rem;
}
.display em { color: var(--gold-soft); font-style: italic; }
.display--sm { font-size: clamp(1.7rem, 1.3rem + 2vw, 2.4rem); }
.lede { color: var(--muted); font-size: 1.02rem; line-height: 1.5; margin: 0 auto 1.8rem; max-width: 26rem; }
.privacy { color: var(--muted); font-size: 0.82rem; margin-top: 1.4rem; display: flex; gap: 0.5rem; align-items: center; justify-content: center; }
.privacy__dot { width: 8px; height: 8px; border-radius: 50%; background: #6fcf97; box-shadow: 0 0 10px #6fcf97; }
.error-text { color: #ff9b8a; font-size: 0.9rem; margin: 0.6rem 0; }

/* ---- Buttons ---- */
.btn {
  font-family: var(--sans);
  font-weight: 500;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.8rem 1.5rem;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 150ms cubic-bezier(0.16, 1, 0.3, 1), background 150ms, opacity 150ms;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--primary { background: linear-gradient(135deg, var(--gold-soft), var(--gold)); color: #2a1d08; }
.btn--primary:hover { background: var(--gold-soft); }
.btn--ghost { background: rgba(246, 239, 230, 0.06); color: var(--ink); border-color: var(--line); }
.btn--ghost:hover { background: rgba(246, 239, 230, 0.12); }
.btn--lg { padding: 1rem 2.2rem; font-size: 1.05rem; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 1.2rem;
  border: 3px solid rgba(214, 166, 75, 0.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Mirror UI ---- */
.mirror-ui { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.mirror-ui > * { pointer-events: auto; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(0.8rem, env(safe-area-inset-top)) 1rem 0.8rem;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  color: var(--ink); font-size: 1.3rem; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--gold); }
.coach {
  position: absolute; top: 4.4rem; left: 50%; transform: translateX(-50%);
  background: var(--panel); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 0.5rem 1.1rem; font-size: 0.85rem; color: var(--gold-soft);
  max-width: 86vw; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Pinned to the upper-right, clear of the coach pill above and the (variable
   height) tray below. At top:50% the tray covered the lower zoom buttons on
   short phone viewports, making them untappable. z-index wins over the tray. */
.zoom-rail {
  position: absolute; right: 0.9rem; top: 6.9rem; bottom: auto;
  display: flex; flex-direction: column; gap: 0.6rem; z-index: 6;
}

/* ---- Tray ---- */
.tray {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 1rem 1rem max(1rem, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(15, 12, 9, 0.92), rgba(15, 12, 9, 0.55) 70%, transparent);
  display: flex; flex-direction: column; gap: 0.7rem;
}
.tabs { display: flex; gap: 0.5rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(246, 239, 230, 0.05); color: var(--muted);
  padding: 0.45rem 1rem; font-size: 0.85rem; cursor: pointer; font-family: var(--sans);
}
.tab[aria-selected='true'] { color: #2a1d08; background: var(--gold-soft); border-color: transparent; }
.rack { display: flex; gap: 0.6rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 0.2rem; }
.rack::-webkit-scrollbar { display: none; }
.active-selections { display: flex; gap: 0.45rem; overflow-x: auto; scrollbar-width: none; min-height: 2.2rem; }
.active-selections::-webkit-scrollbar { display: none; }
.selection-chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 0.45rem;
  border-radius: 999px; border: 1px solid var(--line);
  background: rgba(246, 239, 230, 0.05); color: var(--ink);
  padding: 0.35rem 0.75rem; font-size: 0.78rem; cursor: pointer; font-family: var(--sans);
}
.selection-chip[aria-pressed='true'] { border-color: var(--gold); background: rgba(214, 166, 75, 0.14); }
.selection-chip__remove {
  width: 1.25rem; height: 1.25rem; border-radius: 50%; border: 0;
  background: rgba(246, 239, 230, 0.12); color: var(--ink); cursor: pointer; line-height: 1;
}
.card {
  flex: 0 0 auto; width: 8.2rem; text-align: left;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: rgba(246, 239, 230, 0.05); color: var(--ink);
  padding: 0.7rem 0.8rem; cursor: pointer;
  display: flex; flex-direction: column; gap: 0.25rem; font-family: var(--sans);
}
.card[aria-pressed='true'] { border-color: var(--gold); background: rgba(214, 166, 75, 0.14); }
.card__title { font-size: 0.85rem; font-weight: 500; line-height: 1.2; }
.card__price { font-size: 0.8rem; color: var(--gold-soft); }
.tray__row { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; }
.anchor-picker { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.78rem; color: var(--muted); }
.anchor-picker select {
  font-family: var(--sans); font-size: 0.9rem; color: var(--ink);
  background: rgba(246, 239, 230, 0.07); border: 1px solid var(--line);
  border-radius: 10px; padding: 0.5rem 0.7rem;
}
.actions { display: flex; gap: 0.5rem; }
.actions .btn { padding: 0.6rem 1.1rem; font-size: 0.88rem; }
.size-readout { margin: 0; font-size: 0.85rem; color: var(--gold-soft); min-height: 1.2em; }

/* Collapsible tray so the controls get out of the camera view. */
.tray__handle {
  align-self: center; margin: -0.3rem 0 0.1rem; padding: 0.28rem 1rem;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--gold-soft);
  font-family: var(--sans); font-weight: 600; font-size: 0.75rem;
  cursor: pointer; backdrop-filter: blur(8px);
}
.tray__handle:hover { border-color: var(--gold); }
.tray__body { display: flex; flex-direction: column; gap: 0.7rem; }
.tray--collapsed { background: linear-gradient(to top, rgba(15, 12, 9, 0.55), transparent 80%); }
.tray--collapsed .tray__body,
.tray--collapsed .active-selections { display: none; }

/* ---- Calibration guide ---- */
.card-guide {
  position: fixed; inset: 0; z-index: 8;
  display: grid; place-items: center; gap: 1rem;
  align-content: center;
  background: rgba(10, 8, 6, 0.82); backdrop-filter: blur(4px);
  padding: 1.4rem; text-align: center;
}
.card-guide__box {
  width: var(--card-w, 60vw); height: var(--card-h, 38vw);
  border: 2px dashed var(--gold-soft); border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(10, 8, 6, 0.55);
}
.card-guide__hint { color: var(--ink); max-width: 24rem; font-size: 0.92rem; line-height: 1.5; }
.card-guide__actions { display: flex; gap: 0.7rem; }

@media (min-width: 720px) {
  .tray { left: 50%; right: auto; transform: translateX(-50%); width: min(640px, 94vw); bottom: 1rem; border-radius: var(--radius); border: 1px solid var(--line); }
  .coach { white-space: normal; }
}

/* ── light theme (shared 'yj.theme' key; class on <html>) ── */
html.theme-light{ --bg:#f4eee2; --ink:#1c1813; --muted:#5d564a; --gold:#9c7c3f; --gold-soft:#7a5f2c; --line:rgba(40,32,16,.18); --panel:rgba(255,253,248,.86); }
.yj-theme-toggle{ position:fixed; top:14px; right:14px; z-index:30; width:38px; height:38px; border-radius:50%;
  border:1px solid var(--line); background:var(--panel); color:var(--ink); cursor:pointer; font-size:.95rem;
  display:inline-flex; align-items:center; justify-content:center; backdrop-filter:blur(8px); }
.vnav{ display:flex; gap:16px; margin-top:12px; justify-content:center; }
.vnav a{ font-size:.7rem; letter-spacing:.12em; text-transform:uppercase; color:var(--muted); text-decoration:none; transition:color .2s; }
.vnav a:hover{ color:var(--gold); }