/* VIBEROLL — main.css : layout & components
 * Full-screen 3D first; HTML is a quiet typographic layer on top.
 */
:root {
  --black: #0B0B0B;
  --steel: #202020;
  --gunmetal: #353535;
  --chrome: #A5A19A;
  --amber: #FFB347;
  --orange: #F47A24;
  --red: #B83227;
  --ivory: #F1E8D8;
  --ivory-dim: rgba(241, 232, 216, 0.62);
  --line: rgba(241, 232, 216, 0.22);
  --safe-t: max(18px, env(safe-area-inset-top));
  --safe-b: max(18px, env(safe-area-inset-bottom));
  --safe-l: max(22px, env(safe-area-inset-left));
  --safe-r: max(22px, env(safe-area-inset-right));
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-io: cubic-bezier(.65, 0, .35, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--black); color: var(--ivory); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
body.can-roll { cursor: pointer; }
body.rec.cursor-idle, body.rec.cursor-idle * { cursor: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

#gl { position: fixed; inset: 0; z-index: 0; }
#gl canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; outline: none; }

#ui { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
#ui button, #result, #notice { pointer-events: auto; }

/* ── brand watermark & meta ─────────────────────────────────────────── */
.brandmark {
  position: absolute; top: var(--safe-t); left: var(--safe-l);
  display: flex; align-items: baseline; gap: 14px;
  opacity: 0; transform: translateY(-6px);
  transition: opacity 1.2s var(--ease-out), transform 1.2s var(--ease-out);
}
.brandmark.show { opacity: 0.92; transform: none; }
.brandmark b { font-family: var(--f-brand); font-weight: 400; font-size: 22px; letter-spacing: 0.2em; color: var(--ivory); }
.brandmark span { font-family: var(--f-mono); font-size: 9.5px; letter-spacing: 0.38em; color: var(--amber); opacity: 0.85; }

.meta {
  position: absolute; top: calc(var(--safe-t) + 6px); right: var(--safe-r);
  display: flex; align-items: center; gap: 12px;
  font-family: var(--f-mono); font-size: 9.5px; letter-spacing: 0.32em; color: var(--ivory-dim);
  opacity: 0; transition: opacity 1s var(--ease-out);
}
.meta.show { opacity: 0.8; }
.meta i { width: 22px; height: 1px; background: var(--line); display: block; }

/* ── intro ──────────────────────────────────────────────────────────── */
.intro {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; pointer-events: none;
}
.intro::before {
  content: ''; position: absolute; left: 50%; top: 50%; width: min(78vw, 1100px); height: min(34vw, 420px);
  transform: translate(-50%, -50%); pointer-events: none;
  background: radial-gradient(closest-side, rgba(6, 5, 4, 0.62), rgba(6, 5, 4, 0.28) 55%, rgba(6, 5, 4, 0));
  opacity: 0; transition: opacity 2s ease .3s;
}
.intro.show::before { opacity: 1; }
.intro.out::before { opacity: 0; transition-delay: 0s; transition-duration: .8s; }
.intro-title {
  margin: 0; font-family: var(--f-brand); font-weight: 400; line-height: 0.9;
  font-size: clamp(64px, 12.5vw, 196px); letter-spacing: 0.14em; padding-left: 0.14em;
  color: var(--ivory);
  text-shadow: 0 0 40px rgba(255, 220, 180, 0.18);
  mix-blend-mode: screen;
}
.intro-sub {
  margin: 1.4em 0 0; font-family: var(--f-mono); font-size: clamp(10px, 0.95vw, 13px);
  letter-spacing: 0.62em; padding-left: 0.62em; color: var(--amber);
}
.intro-cta {
  position: absolute; bottom: calc(var(--safe-b) + 7vh); left: 0; right: 0; margin: 0;
  display: flex; align-items: center; justify-content: center; gap: 18px;
  font-family: var(--f-mono); font-size: 10.5px; letter-spacing: 0.5em; color: var(--ivory-dim);
}
.intro-cta span { padding-left: 0.5em; }
.intro-cta i { display: block; width: 44px; height: 1px; background: linear-gradient(90deg, transparent, rgba(241,232,216,.5), transparent); }

/* ── hint ───────────────────────────────────────────────────────────── */
.hint {
  position: absolute; left: var(--hx, 70%); top: var(--hy, 30%);
  display: flex; flex-direction: column; align-items: flex-start; gap: 9px;
  opacity: 0; transform: translate(34px, -40%);
  transition: opacity .9s var(--ease-out), transform .9s var(--ease-out);
}
.hint.show { opacity: 1; transform: translate(26px, -40%); }
.hint-text::after { display: none !important; }
.hint .hint-text::before { margin-left: 0; width: 34px; }
.hint-sub { padding-left: 52px; }
.hint-text {
  font-family: var(--f-cond); font-weight: 500; font-size: 15px; letter-spacing: 0.5em; padding-left: 0.5em; color: var(--ivory);
}
.hint-text::before, .hint-text::after { content: ''; display: inline-block; vertical-align: middle; width: 28px; height: 1px; background: var(--amber); margin: 0 18px 2px; opacity: .8; }
.hint-sub { font-family: var(--f-mono); font-size: 9px; letter-spacing: 0.42em; color: var(--ivory-dim); }

/* ── result (final challenge) ───────────────────────────────────────── */
.result {
  position: absolute; left: 51vw; top: 50%; width: min(42vw, 700px);
  transform: translateY(-50%);
  opacity: 0; visibility: hidden;
  transition: opacity .6s var(--ease-out), visibility 0s linear .6s;
  -webkit-user-select: text; user-select: text;
}
.result.show { opacity: 1; visibility: visible; transition: opacity .3s var(--ease-out), visibility 0s; }
.result::before {
  content: ''; position: absolute; inset: -18% -30% -18% -14%; z-index: -1; pointer-events: none;
  background: radial-gradient(closest-side, rgba(8, 6, 5, 0.72), rgba(8, 6, 5, 0.38) 55%, rgba(8, 6, 5, 0) 100%);
}
.r-head { display: flex; align-items: center; gap: 16px; font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.34em; color: var(--amber); }
.r-rule { flex: 0 0 48px; height: 1px; background: rgba(255, 179, 71, 0.55); }
.r-tag { color: var(--ivory-dim); }
.r-zh {
  margin: 0.55em 0 0; font-family: var(--f-zh); font-weight: 700;
  font-size: clamp(30px, 3.35vw, 64px); line-height: 1.22; letter-spacing: 0.04em; color: var(--ivory);
}
.r-part { display: inline-block; white-space: nowrap; }
.r-part + .r-part { margin-left: 0.32em; }
.r-x { display: inline-block; color: var(--amber); font-family: var(--f-ui); font-weight: 300; margin-right: 0.32em; transform: translateY(-0.04em); }
.r-en {
  margin: 0.7em 0 0; font-family: var(--f-cond); font-weight: 500;
  font-size: clamp(15px, 1.68vw, 32px); letter-spacing: 0.12em; line-height: 1.3; color: #d9cfbf;
}
.r-x2 { color: var(--amber); }
.r-desc { margin-top: 1.6em; padding-top: 1.25em; position: relative; }
.r-desc::before { content: ''; position: absolute; top: 0; left: 0; width: 56px; height: 1px; background: var(--amber); }
.r-desc-zh { margin: 0; font-family: var(--f-zh); font-weight: 400; font-size: clamp(15px, 1.25vw, 22px); line-height: 1.6; color: var(--ivory); letter-spacing: 0.04em; }
.r-desc-en { margin: 0.45em 0 0; font-family: var(--f-ui); font-weight: 400; font-size: clamp(12px, 0.86vw, 15px); line-height: 1.55; color: var(--ivory-dim); letter-spacing: 0.01em; }
.r-actions { display: flex; gap: 12px; margin-top: 2.2em; flex-wrap: wrap; }
.r-actions button {
  font-family: var(--f-mono); font-size: 10.5px; letter-spacing: 0.3em; color: var(--ivory);
  padding: 12px 18px 12px 20px; border: 1px solid rgba(241, 232, 216, 0.26);
  transition: border-color .3s, color .3s, background-color .3s;
}
.r-actions button:hover, .r-actions button:focus-visible { border-color: var(--amber); color: var(--amber); outline: none; }
.r-actions button kbd { border-color: rgba(241, 232, 216, 0.2); }

/* ── controls ───────────────────────────────────────────────────────── */
.controls {
  position: absolute; left: var(--safe-l); bottom: var(--safe-b);
  display: flex; gap: 22px; align-items: center;
  opacity: 0; transform: translateY(6px); visibility: hidden;
  transition: opacity .8s var(--ease-out), transform .8s var(--ease-out), visibility 0s linear .8s;
}
.controls.show { opacity: 1; transform: none; visibility: visible; transition: opacity .8s var(--ease-out), transform .8s var(--ease-out), visibility 0s; }
.controls button {
  font-family: var(--f-mono); font-size: 9.5px; letter-spacing: 0.28em; color: var(--ivory-dim);
  padding: 8px 0; transition: color .25s;
}
.controls button b { font-weight: 500; color: var(--amber); }
.controls button:hover, .controls button:focus-visible { color: var(--ivory); outline: none; }
.controls kbd { font-size: 8.5px; }

/* ── toast / notice ─────────────────────────────────────────────────── */
.toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 2vh); transform: translate(-50%, 8px);
  font-family: var(--f-mono); font-size: 10px; letter-spacing: 0.34em; color: var(--ivory);
  padding: 10px 18px; background: rgba(11, 11, 11, 0.72); border-top: 1px solid rgba(255, 179, 71, 0.5);
  opacity: 0; transition: opacity .4s, transform .4s var(--ease-out); white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.notice {
  position: absolute; left: 50%; top: 18vh; transform: translateX(-50%);
  font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.22em; color: var(--ivory); text-align: center;
  padding: 16px 22px; background: rgba(11, 11, 11, 0.88); border: 1px solid var(--line);
  opacity: 0; visibility: hidden; transition: opacity .4s;
}
.notice.show { opacity: 1; visibility: visible; }
.notice button { margin-left: 14px; color: var(--amber); text-decoration: underline; text-underline-offset: 4px; letter-spacing: 0.22em; }

/* ── loader ─────────────────────────────────────────────────────────── */
.loader {
  position: fixed; inset: 0; z-index: 10; background: var(--black);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  transition: opacity 1.2s var(--ease-io), visibility 0s linear 1.2s;
}
.loader.done { opacity: 0; visibility: hidden; }
.loader-mark { font-family: var(--f-brand); font-size: 26px; letter-spacing: 0.42em; padding-left: 0.42em; color: var(--ivory); opacity: 0.9; }
.loader-bar { width: 168px; height: 1px; background: rgba(241, 232, 216, 0.12); overflow: hidden; }
.loader-bar i { display: block; height: 100%; background: var(--amber); transform-origin: 0 50%; transform: scaleX(0); transition: transform .5s var(--ease-out); }
.loader-text { font-family: var(--f-mono); font-size: 9px; letter-spacing: 0.42em; color: var(--ivory-dim); }
.loader-tag { position: absolute; bottom: calc(var(--safe-b) + 5vh); font-family: var(--f-ui); font-size: 11px; letter-spacing: 0.12em; color: rgba(241,232,216,.38); }
.noscript { padding: 40px; font-family: var(--f-mono); }

/* ── recording mode: keep brand, machine & result only ─────────────── */
body.rec .controls, body.rec .hint, body.rec .meta, body.rec .r-actions, body.rec .intro-cta { opacity: 0 !important; visibility: hidden !important; }

/* ── portrait / 9:16 (Instagram Reels, TikTok, Shorts) ─────────────── */
@media (max-aspect-ratio: 19/20) {
  .brandmark { top: calc(var(--safe-t) + 2vh); left: 50%; transform: translate(-50%, -6px); flex-direction: column; align-items: center; gap: 4px; }
  .brandmark.show { transform: translate(-50%, 0); }
  .brandmark b { font-size: 19px; }
  .meta { display: none; }
  .intro-title { font-size: clamp(52px, 17vw, 120px); }
  .intro-sub { font-size: 10px; }
  .intro-cta { bottom: 24vh; }
  .hint { left: 0; right: 0; top: auto; bottom: 27vh; align-items: center; transform: translateY(8px); }
  .hint.show { transform: none; }
  .hint-text::after { display: inline-block !important; }
  .hint .hint-text::before { margin: 0 18px 2px; width: 28px; }
  .hint-sub { padding-left: 0; }
  .result {
    left: 7vw; right: 14vw; width: auto; top: 50vh; transform: none; text-align: center;
  }
  .result::before {
    inset: -16% -30% -60% -30%;
    background: linear-gradient(180deg, rgba(8, 6, 5, 0) 0%, rgba(8, 6, 5, 0.8) 20%, rgba(8, 6, 5, 0.9) 60%, rgba(8, 6, 5, 0.94) 100%);
  }
  html[data-state="spinning"] .brandmark, html[data-state="style_revealed"] .brandmark,
  html[data-state="theme_revealed"] .brandmark, html[data-state="result"] .brandmark,
  html[data-state="resetting"] .brandmark { opacity: 0; }
  html[data-state="result"] .controls { opacity: 0; visibility: hidden; }
  .r-head { justify-content: center; font-size: 9.5px; gap: 10px; }
  .r-rule { flex-basis: 22px; }
  .r-zh { font-size: clamp(22px, 7vw, 40px); margin-top: 0.45em; }
  .r-part + .r-part { margin-left: 0; }
  .r-part { display: block; }
  .r-en { font-size: clamp(11px, 3.5vw, 20px); margin-top: 0.55em; letter-spacing: 0.08em; }
  .r-desc { margin-top: 1.1em; padding-top: 0.95em; }
  .r-desc::before { left: 50%; transform: translateX(-50%); width: 40px; }
  .r-desc-zh { font-size: clamp(13px, 3.7vw, 18px); }
  .r-desc-en { font-size: clamp(10.5px, 2.9vw, 13px); }
  .r-actions { justify-content: center; margin-top: 1.4em; }
  .r-actions button { padding: 10px 12px 10px 14px; font-size: 9.5px; letter-spacing: 0.22em; }
  .r-actions kbd { display: none; }
  .controls { left: 50%; transform: translate(-50%, 6px); bottom: calc(var(--safe-b) + 1vh); gap: 16px; white-space: nowrap; }
  .controls.show { transform: translate(-50%, 0); }
  .controls button { font-size: 8.5px; letter-spacing: 0.2em; }
  .controls kbd { display: none; }
}
@media (max-aspect-ratio: 19/20) {
  #fallback { justify-content: center; align-items: flex-start; padding: 9vh 5vw 0; }
  .fb-machine { width: 100%; padding: 18px; }
  .fb-sign b { font-size: 40px; }
}
@media (max-aspect-ratio: 19/20) and (max-height: 700px) {
  .r-desc-en { display: none; }
}

/* ── 2D fallback ────────────────────────────────────────────────────── */
#fallback { position: fixed; inset: 0; z-index: 1; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, #3a1c10 0%, #120b08 45%, #0b0b0b 80%); }
#fallback[hidden] { display: none; }
#fallback { justify-content: flex-start; padding-left: 6vw; }
.fb-machine { width: min(44vw, 600px); padding: 28px; border: 1px solid rgba(165, 161, 154, 0.5); border-radius: 18px;
  background: linear-gradient(180deg, #2a2724, #161412); box-shadow: inset 0 0 0 6px #0f0e0d, 0 40px 80px rgba(0,0,0,.6); text-align: center; }
.fb-sign { padding: 14px; border-radius: 8px; background: radial-gradient(ellipse, #F47A24, #B83227 60%, #5a120a); box-shadow: 0 0 40px rgba(244,122,36,.35); }
.fb-sign b { display: block; font-family: var(--f-brand); font-weight: 400; font-size: 56px; letter-spacing: .16em; color: #fff4de; }
.fb-sign span { font-family: var(--f-mono); font-size: 11px; letter-spacing: .5em; color: #ffe1b5; }
.fb-reels { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 22px; }
.fb-label { font-family: var(--f-zh); font-size: 14px; color: var(--amber); margin-bottom: 8px; }
.fb-label small { font-family: var(--f-mono); font-size: 9px; letter-spacing: .25em; color: var(--ivory-dim); margin-left: 6px; }
.fb-window { height: 84px; overflow: hidden; border-radius: 6px; border: 3px solid #a5a19a; background: #efe5d2; position: relative; }
.fb-window::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,.45), transparent 30%, transparent 70%, rgba(0,0,0,.45)); pointer-events: none; }
.fb-strip { will-change: transform; }
.fb-item { height: 84px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #17110c; }
.fb-item b { font-family: var(--f-zh); font-size: 24px; font-weight: 700; }
.fb-item small { font-family: var(--f-cond); font-size: 12px; letter-spacing: .12em; color: var(--red); }
.fb-roll { margin-top: 22px; padding: 14px 40px; font-family: var(--f-cond); font-size: 16px; letter-spacing: .4em; color: #fff; background: var(--red); border-radius: 40px; box-shadow: 0 6px 0 #6e1a12; }
.fb-roll:active { transform: translateY(3px); box-shadow: 0 3px 0 #6e1a12; }
.fb-note { margin: 18px 0 0; font-family: var(--f-mono); font-size: 9px; letter-spacing: .2em; color: var(--ivory-dim); line-height: 1.6; }
