:root {
  --plum: #14060f;
  --plum-2: #24101c;
  --wine: #4a1834;
  --gold: #e6c36a;
  --gold-deep: #8d6424;
  --magenta: #e23b86;
  --cream: #f8e7c8;
  --dim: #cbb59a;
  --ink: #f3e6d4;
  --line: rgba(230, 195, 106, 0.45);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 480px at 50% -10%, rgba(226, 59, 134, 0.28), transparent 55%),
    var(--plum);
  color: var(--ink);
  font-family: "Khmer Sangam MN", "Kantumruy Pro", "Noto Sans Khmer", "Noto Sans", sans-serif;
  font-size: 16px;
  line-height: 1.7;
}

img, canvas, svg { max-width: 100%; }

button, input { font-family: inherit; }

button {
  touch-action: manipulation;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.shell {
  width: min(920px, 100%);
  margin: 0 auto;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

.lintel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.badge {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.04em;
  background:
    radial-gradient(circle at 50% 35%, #6d2468, #1a0816 72%);
  box-shadow:
    0 0 0 2px var(--gold),
    inset 0 0 0 3px rgba(230, 195, 106, 0.35),
    0 0 18px rgba(226, 59, 134, 0.55);
}

.badge span { font-size: 13px; }

.brand-copy { min-width: 0; }

.brand-copy h1 {
  margin: 0;
  font-size: clamp(20px, 5.4vw, 30px);
  line-height: 1.25;
  font-weight: 700;
}

.eyebrow, .kicker {
  margin: 0;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
  line-height: 1.4;
}

.mute {
  margin-left: auto;
  flex: none;
  border: 1px solid var(--line);
  background: rgba(20, 6, 15, 0.65);
  color: var(--cream);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 12px;
}

.mute[aria-pressed="true"] {
  color: var(--gold);
  box-shadow: 0 0 12px rgba(226, 59, 134, 0.45);
}

.tray-wrap { position: relative; }

.tray {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 12px 16px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.tray::-webkit-scrollbar { display: none; }

.tray-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 8px;
  width: 22px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--plum));
}

.gate {
  flex: 0 0 74px;
  width: 74px;
  scroll-snap-align: start;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--dim);
}

.roof {
  display: block;
  height: 62px;
  padding: 2px 2px 0;
  background: linear-gradient(#f3d78a, #8a5a1e);
  clip-path: polygon(50% 0, 100% 18%, 92% 100%, 8% 100%);
}

.roof-in {
  display: grid;
  place-items: end center;
  height: 100%;
  padding-bottom: 7px;
  background: #241018;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.2;
  clip-path: polygon(50% 4px, calc(100% - 2px) 20%, calc(100% - 5px) calc(100% - 2px), 5px calc(100% - 2px));
}

.gate.on { transform: translateY(-3px); }

.gate.on .roof {
  filter: drop-shadow(0 0 8px rgba(226, 59, 134, 0.75));
}

.gate.on .roof-in {
  color: var(--cream);
  background: radial-gradient(circle at 50% 80%, rgba(226, 59, 134, 0.95), #3a1024 70%);
}

.panel { display: none; }
.panel.on { display: block; }

.sheet {
  margin: 0 12px 12px;
  padding: 14px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(48, 20, 40, 0.96), rgba(18, 8, 16, 0.96)) padding-box,
    linear-gradient(150deg, #f0d48a, #6e4a16 42%, #e23b86 78%, #f0d48a) border-box;
  border: 1.5px solid transparent;
  box-shadow: var(--shadow);
  min-width: 0;
}

.sheet h2, .sheet h3 { margin: 0 0 6px; line-height: 1.35; }

.sheet h2 { font-size: clamp(22px, 6vw, 32px); }

.sheet h3 { font-size: clamp(18px, 4.8vw, 22px); }

.lead { margin: 0; color: var(--dim); }

.frame, .portrait {
  width: 100%;
  border-radius: 14px;
  object-fit: cover;
  display: block;
}

.frame { aspect-ratio: 16 / 10; margin-bottom: 12px; }

.portrait { aspect-ratio: 1 / 1; max-height: 320px; margin-bottom: 12px; }

.play { position: relative; }

.hud-top h2 { font-size: clamp(22px, 6vw, 30px); }

.meters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.meter {
  min-width: 0;
  padding: 6px 4px;
  border-radius: 12px;
  background: rgba(8, 2, 6, 0.45);
  border: 1px solid rgba(230, 195, 106, 0.2);
}

.meter span {
  display: block;
  color: var(--dim);
  font-size: 11px;
  line-height: 1.2;
}

.meter strong {
  display: block;
  color: var(--gold);
  font-size: clamp(13px, 3.6vw, 18px);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.pips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

.pip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.4;
}

.pip.on {
  color: #2a1208;
  background: var(--gold);
  border-color: var(--gold);
}

.picks {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}

.picks::-webkit-scrollbar { display: none; }

.seal-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--gold-deep);
  background: #1a0a14;
  color: var(--dim);
  font-size: 13px;
}

.seal-btn.on {
  color: #2a1208;
  background: radial-gradient(circle at 40% 35%, #fff1c9, var(--gold) 42%, #a8742a);
  box-shadow: 0 0 12px rgba(226, 59, 134, 0.65);
}

.seal-btn:disabled {
  opacity: 0.38;
}

.stage {
  width: min(100%, 460px, 46vh);
  margin: 0 auto;
}

#board {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 50%;
  touch-action: none;
  background: #10060c;
  box-shadow: 0 0 0 2px rgba(230, 195, 106, 0.7), 0 0 24px rgba(226, 59, 134, 0.35);
}

.note, .hint { margin: 8px 0 0; min-height: 1.4em; }

.note { color: var(--cream); }

.hint { color: var(--dim); font-size: 14px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 10px 0;
  padding: 0;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--dim);
  font-size: 13px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: block;
  flex: none;
  border: 1px solid var(--line);
}

.swatch.arch { background: #6d1d52; }
.swatch.seal { background: #4c2344; }
.swatch.drum { background: #5c3d18; }
.swatch.key { background: #e6c36a; }
.swatch.relic { background: #2f6a45; }
.swatch.lion { background: #e23b86; }

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  position: fixed;
  left: 50%;
  bottom: calc(8px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(896px, calc(100% - 24px));
  z-index: 4;
  margin: 0;
  padding: 8px;
  border-radius: 16px;
  background: rgba(16, 6, 12, 0.94);
  box-shadow: 0 0 0 1px rgba(230, 195, 106, 0.35);
}

#screen-trail.on { padding-bottom: 132px; }

.controls button, .solid, .veil button {
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #1b0c14;
  color: var(--cream);
  padding: 6px 4px;
}

.controls button b {
  display: block;
  color: var(--gold);
  font-size: 16px;
  line-height: 1.1;
}

.controls button span {
  display: block;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.controls button:active, .solid:active { transform: translateY(1px); }

.solid {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  padding: 0 16px;
  background: linear-gradient(#f0d48a, #c4963a);
  color: #2a1208;
  font-weight: 700;
  border-color: transparent;
  box-shadow: 0 0 16px rgba(226, 59, 134, 0.28);
}

.help {
  margin-top: 12px;
  color: var(--dim);
}

.help summary { color: var(--gold); cursor: pointer; }

.help ol { margin: 8px 0 0; padding-left: 18px; }

.veil {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  padding: 16px;
  border-radius: 18px;
  background: rgba(10, 3, 8, 0.9);
}

.veil[hidden] { display: none; }

.veil h2 { margin: 0; font-size: clamp(24px, 7vw, 34px); }

.stars { margin: 0; color: var(--gold); letter-spacing: 0.2em; font-size: 22px; }

.veil-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

.card-top {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.card-top img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 14px;
}

.status, .owned {
  margin: 0;
  color: var(--magenta);
  font-size: 13px;
}

.hall-card.is-open .status, .relic-card.is-held .owned { color: var(--gold); }

.hall-card button[disabled] { opacity: 0.45; }

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
}

.steps li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #2a1208;
  background: var(--gold);
  font-weight: 800;
}

.facts {
  display: grid;
  gap: 0;
}

.medallion {
  width: min(100%, 220px);
  aspect-ratio: 1;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--gold);
  background:
    radial-gradient(circle at 50% 45%, #6a2458, #1a0a14 68%);
  box-shadow: 0 0 0 3px var(--gold), inset 0 0 0 8px rgba(230, 195, 106, 0.25);
}

.medallion span { font-size: 28px; }

.record-meters { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.score-list, .run-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.score-list li, .run-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid rgba(230, 195, 106, 0.18);
}

.score-list span, .run-list span { min-width: 0; }

.score-list b, .run-list b {
  color: var(--gold);
  flex: none;
  font-variant-numeric: tabular-nums;
}

.empty { margin: 8px 0 0; color: var(--dim); }

.empty.off { display: none; }

.hero-card .frame { margin-bottom: 12px; }

@media (min-width: 560px) {
  .stage { width: min(100%, 480px, 52vh); }
  .facts { grid-template-columns: 1fr 1fr; }
  .facts .sheet:last-child { grid-column: 1 / -1; }
  .card-top { grid-template-columns: 120px minmax(0, 1fr); }
  .card-top img { width: 120px; height: 120px; }
}

@media (min-width: 720px) {
  .tray { justify-content: space-between; overflow: visible; }
  .gate { flex: 1 1 0; width: auto; }
  .tray-wrap::after { display: none; }
  .split {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    gap: 14px;
    align-items: center;
  }
  .split .frame, .split .portrait { margin: 0; height: 100%; max-height: 280px; }
  .facts { grid-template-columns: 1fr 1fr 1fr; }
  .facts .sheet:last-child { grid-column: auto; }
  .relic-card {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
  }
  .relic-card img, .relic-card .medallion { margin: 0; width: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
