:root {
  --void: #07060b;
  --ink: #100e16;
  --gold: #d4af37;
  --gold-soft: #e8d5a3;
  --gold-deep: #8a5a12;
  --cyan: #7df9ff;
  --champagne: #fff4c8;
  --paper: #f4ead4;
  --dim: rgba(244, 234, 212, 0.58);
  --line: rgba(212, 175, 55, 0.38);
  --serif: "Noto Serif Thai", "Cinzel", serif;
  --sans: "IBM Plex Sans Thai", system-ui, sans-serif;
  --display: "Cinzel", "Noto Serif Thai", serif;
  --mono: "Orbitron", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--void); color: var(--paper); }
body { font-family: var(--sans); -webkit-font-smoothing: antialiased; user-select: none; touch-action: none; }

canvas, video { display: block; }
button { font-family: inherit; cursor: pointer; }

#grain, #vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 40;
}
#grain {
  opacity: 0.09;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='.85'/></svg>");
  animation: grain 0.7s steps(2) infinite;
}
#vignette {
  background: radial-gradient(ellipse at center, transparent 42%, rgba(0,0,0,.62) 100%);
  z-index: 39;
}
@keyframes grain {
  0% { transform: translate(0,0); }
  100% { transform: translate(-2%, 1%); }
}

/* ---------- boot ---------- */
#boot {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  background: radial-gradient(ellipse at 50% 40%, #161225 0%, #07060b 70%);
  transition: opacity 0.9s ease, visibility 0.9s;
}
#boot.done { opacity: 0; visibility: hidden; }
.boot-crest { width: 110px; height: 110px; animation: spinSlow 18s linear infinite; }
.boot-crest svg { width: 100%; height: 100%; filter: drop-shadow(0 0 18px rgba(212,175,55,.35)); }
.boot-kicker {
  font-family: var(--mono);
  letter-spacing: 0.46em;
  font-size: 11px;
  color: var(--gold);
  padding-left: 0.46em;
}
.boot-msg { font-weight: 300; color: var(--dim); font-size: 14px; }
.boot-bar {
  width: 180px;
  height: 1px;
  background: rgba(212,175,55,.18);
  overflow: hidden;
}
.boot-bar i {
  display: block;
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  animation: load 1.4s ease-in-out infinite;
}
@keyframes load {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
@keyframes spinSlow { to { transform: rotate(360deg); } }

/* ---------- landing ---------- */
#landing {
  position: fixed;
  inset: 0;
  z-index: 10;
}
#landing.leave { pointer-events: none; }
#landing.leave .landing-ui { opacity: 0; transform: translateY(-18px) scale(0.98); }
#landing.leave .landing-veil { opacity: 1; background: #000; }
#landing-canvas { width: 100%; height: 100%; }
.landing-veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(7,6,11,.15) 0%, rgba(7,6,11,.08) 40%, rgba(7,6,11,.72) 100%);
  pointer-events: none;
  transition: opacity 1.1s ease, background 1.1s ease;
}
.landing-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 24px 7vh;
  text-align: center;
  transition: opacity 0.8s ease, transform 0.8s ease;
}
.crest-wrap { margin-bottom: 10px; }
.crest {
  width: 92px;
  height: 92px;
  filter: drop-shadow(0 0 16px rgba(125,249,255,.18)) drop-shadow(0 0 22px rgba(212,175,55,.28));
  animation: pulseCrest 4.4s ease-in-out infinite;
}
@keyframes pulseCrest {
  0%, 100% { transform: scale(1); opacity: 0.92; }
  50% { transform: scale(1.04); opacity: 1; }
}
.kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.42em;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 14px;
  padding-left: 0.42em;
}
.landing-ui h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(36px, 6.4vw, 86px);
  line-height: 1.18;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fff8dc 0%, #e0b84a 48%, #9a6a1c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 10px 28px rgba(0,0,0,.45));
}
.rule {
  width: min(420px, 70vw);
  height: 10px;
  margin: 16px 0 18px;
  position: relative;
}
.rule span, .rule::before, .rule::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.rule span {
  width: 7px; height: 7px; left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--gold);
  box-shadow: 0 0 12px var(--gold);
}
.lede {
  max-width: 640px;
  color: var(--dim);
  font-weight: 300;
  font-size: clamp(13px, 1.5vw, 16px);
  line-height: 1.85;
  margin-bottom: 28px;
}
#enter-btn {
  position: relative;
  isolation: isolate;
  border: 1px solid rgba(212,175,55,.65);
  background: linear-gradient(180deg, rgba(212,175,55,.16), rgba(12,10,18,.55));
  color: var(--champagne);
  padding: 16px 36px;
  font-size: 16px;
  letter-spacing: 0.08em;
  border-radius: 2px;
  overflow: hidden;
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s;
  box-shadow: 0 0 0 1px rgba(255,244,200,.05), 0 10px 40px rgba(0,0,0,.35);
}
#enter-btn:hover {
  transform: translateY(-2px);
  border-color: var(--gold-soft);
  box-shadow: 0 0 28px rgba(212,175,55,.28), 0 14px 40px rgba(0,0,0,.4);
}
#enter-btn:active { transform: translateY(0); }
.btn-glow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(circle, rgba(212,175,55,.28), transparent 55%);
  opacity: 0.55;
  animation: glowDrift 5s ease-in-out infinite;
  z-index: -1;
}
@keyframes glowDrift {
  0%, 100% { transform: translate(-8%, -4%); }
  50% { transform: translate(10%, 8%); }
}
.btn-label { font-family: var(--serif); font-weight: 500; }
.hint {
  margin-top: 16px;
  font-size: 12px;
  color: rgba(244,234,212,.42);
  font-weight: 300;
}

/* ---------- ceremony ---------- */
#ceremony {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #05040a;
}
#ceremony[hidden] { display: none; }
#cam, #world, #hands-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#cam {
  object-fit: cover;
  transform: scaleX(-1);
  filter: saturate(0.78) contrast(1.08) brightness(0.72);
  z-index: 0;
}
#world { z-index: 1; }
#hands-overlay { z-index: 2; pointer-events: none; }

.hud {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 22px max(16px, env(safe-area-inset-bottom));
}
.hud-top, .hud-bot, .hud button { pointer-events: auto; }
.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.hud-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  background: linear-gradient(180deg, rgba(10,8,16,.55), rgba(10,8,16,.2));
  border: 1px solid var(--line);
  padding: 10px 14px;
  backdrop-filter: blur(10px);
}
.hud-brand .orb {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
  animation: pulseCrest 2.2s ease-in-out infinite;
}
.hud-brand small {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.28em;
  color: var(--gold);
}
.hud-brand strong {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 16px;
}
.hud-meter {
  position: relative;
  width: 74px; height: 74px;
}
.ring { width: 74px; height: 74px; transform: rotate(-90deg); }
.ring circle {
  fill: none;
  stroke: rgba(212,175,55,.18);
  stroke-width: 3;
}
#ring-fill {
  stroke: var(--gold);
  stroke-dasharray: 163.4;
  stroke-dashoffset: 163.4;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--gold));
  transition: stroke-dashoffset 0.5s ease;
}
.meter-txt {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.meter-txt b { font-size: 18px; color: var(--champagne); }
.meter-txt span { font-size: 10px; color: var(--gold); margin-left: 2px; }

.hud-guide {
  align-self: center;
  max-width: 640px;
  text-align: center;
  font-weight: 300;
  font-size: 14px;
  color: var(--paper);
  padding: 10px 16px;
  background: rgba(7,6,11,.42);
  border: 1px solid rgba(212,175,55,.2);
  backdrop-filter: blur(8px);
  margin-top: 8px;
}

.mix-list {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  list-style: none;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  max-width: 92vw;
  overflow-x: auto;
  pointer-events: none;
  z-index: 10;
  padding: 4px 10px;
  background: rgba(8, 7, 14, 0.65);
  border: 1px solid var(--line);
  border-radius: 24px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.mix-list li {
  font-size: 12px;
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 14px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  color: var(--gold-soft);
  background: rgba(16, 14, 22, 0.6);
  white-space: nowrap;
  transition: all 0.3s ease;
}
.mix-list li.on {
  border-color: var(--cyan);
  color: #ffffff;
  background: rgba(125, 249, 255, 0.25);
  box-shadow: 0 0 12px rgba(125, 249, 255, 0.5);
  transform: scale(1.06);
}

.hud-bot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.ghost, .hud-bot button, #btn-again, #btn-skip-cam {
  pointer-events: auto;
  background: rgba(8,7,12,.45);
  color: var(--gold-soft);
  border: 1px solid var(--line);
  padding: 8px 14px;
  font-size: 12px;
  letter-spacing: 0.06em;
  backdrop-filter: blur(8px);
}
.ghost:hover { border-color: var(--gold); color: var(--champagne); }
#track-status {
  margin-left: auto;
  font-size: 11px;
  color: var(--dim);
  font-family: var(--mono);
  letter-spacing: 0.08em;
}

#cam-gate {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: rgba(5,4,10,.62);
  backdrop-filter: blur(8px);
}
#cam-gate[hidden] { display: none; }
.gate-card {
  width: min(440px, 90vw);
  padding: 36px 28px;
  text-align: center;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20,16,30,.92), rgba(8,7,12,.94));
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.gate-card h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  margin-bottom: 12px;
  color: var(--champagne);
}
.gate-card p {
  color: var(--dim);
  font-weight: 300;
  line-height: 1.7;
  margin-bottom: 22px;
}
#btn-allow-cam, #btn-again {
  background: linear-gradient(180deg, rgba(212,175,55,.22), rgba(12,10,18,.5));
  border: 1px solid var(--gold);
  color: var(--champagne);
  padding: 12px 22px;
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.06em;
}
#btn-skip-cam { margin-top: 10px; display: inline-block; }

/* ---------- finale ---------- */
#finale {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(28,18,8,.28), rgba(5,4,10,.78) 70%);
}
#finale[hidden] { display: none; }
#finale.show .finale-inner { animation: rise 1.4s ease both; }
#finale.show .finale-flash { animation: flash 1.1s ease both; }
.finale-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, #fff6d0 0%, #ffd56a 18%, transparent 62%);
  opacity: 0;
  pointer-events: none;
}
@keyframes flash {
  0% { opacity: 1; }
  40% { opacity: 0.55; }
  100% { opacity: 0; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(28px) scale(0.96); filter: blur(8px); }
  to { opacity: 1; transform: none; filter: none; }
}
.finale-inner { text-align: center; padding: 24px; position: relative; z-index: 1; }
.finale-kicker {
  font-family: var(--mono);
  letter-spacing: 0.5em;
  font-size: 11px;
  color: var(--gold);
  margin-bottom: 18px;
  padding-left: 0.5em;
}
.finale-inner h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(26px, 4.4vw, 52px);
  line-height: 1.45;
  background: linear-gradient(180deg, #fffce8, #e0b84a 70%, #b8860b);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 8px 24px rgba(212,175,55,.25));
}
.finale-rule {
  width: 160px;
  height: 1px;
  margin: 22px auto;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.finale-sub {
  color: var(--dim);
  font-weight: 300;
  margin-bottom: 26px;
}
#btn-again { pointer-events: auto; }

@media (max-width: 720px) {
  .landing-ui { padding-bottom: 5vh; }
  .lede br { display: none; }
  .mix-list { max-width: 100%; }
  .hud-guide { font-size: 12px; }
  .hud-brand strong { font-size: 14px; }
}
