:root {
  --ink: #12070a;
  --velvet: #2a1016;
  --crimson: #e10600;
  --crimson-deep: #8d1020;
  --gold: #f3d48a;
  --gold-deep: #a9782f;
  --ivory: #fff6ea;
  --muted: #e7d2c2;
  --felt: #114237;
  --felt-deep: #0b2c26;
  --line: rgba(243, 212, 138, 0.45);
  --display: "Tiro Devanagari Hindi", "Noto Serif Devanagari", serif;
  --ui: "Hind", "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  --latin: "Cinzel", "Palatino Linotype", serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: #070305;
  color: var(--ivory);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.45;
}

button, input { font-family: inherit; }

button { cursor: pointer; }

img { max-width: 100%; display: block; }

[hidden] { display: none !important; }

.app-shell {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% -20%, rgba(225, 6, 0, 0.38), transparent 52%),
    radial-gradient(70% 40% at 110% 110%, rgba(169, 120, 47, 0.22), transparent 46%),
    repeating-linear-gradient(135deg, rgba(243, 212, 138, 0.035) 0 2px, transparent 2px 14px),
    var(--ink);
}

.stage-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.screen { display: none; }

.screen.is-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

#screen-play.is-active { overflow: hidden; }

.page {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 14px 14px 22px;
}

.lamps {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 12px;
}

.lamps i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6d2, #e2b34a 42%, #7a4a12 78%);
  box-shadow: 0 0 8px rgba(243, 212, 138, 0.85);
  animation: blink 1.5s ease-in-out infinite;
}

.lamps i:nth-child(3n) { animation-delay: 0.35s; }
.lamps i:nth-child(3n + 1) { animation-delay: 0.7s; }

@keyframes blink {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.wordmark {
  margin: 0;
  text-align: center;
  font-family: var(--latin);
  letter-spacing: 0.28em;
  font-size: 12px;
  color: var(--gold);
}

.display-title {
  margin: 4px 0 0;
  text-align: center;
  font-family: var(--display);
  font-size: clamp(2rem, 9vw, 3.4rem);
  font-weight: 400;
  line-height: 1.05;
}

.kicker {
  margin: 4px 0 0;
  text-align: center;
  color: var(--gold);
  letter-spacing: 0.08em;
  font-size: 0.95rem;
}

.arch {
  margin: 14px auto 0;
  width: min(100%, 520px);
  aspect-ratio: 16 / 10;
  border-radius: 180px 180px 16px 16px;
  overflow: hidden;
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 6px rgba(141, 16, 32, 0.65), 0 16px 30px rgba(0, 0, 0, 0.35);
  position: relative;
}

.arch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.arch::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(180deg, transparent 45%, rgba(18, 7, 10, 0.55));
  pointer-events: none;
}

.medallion-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.medallion {
  min-height: 74px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 0%, rgba(243, 212, 138, 0.2), transparent 55%),
    rgba(42, 16, 22, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 4px;
  box-shadow: inset 0 0 0 3px rgba(88, 16, 24, 0.65);
}

.medallion strong {
  font-family: var(--latin);
  color: var(--gold);
  font-size: 1.25rem;
}

.medallion span {
  color: var(--muted);
  font-size: 0.78rem;
}

.lead, .story, .rule p, .hero-card p, .chamber-card p {
  color: var(--muted);
}

.lead {
  font-size: 1.02rem;
  text-align: center;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.plaque, .text-link {
  border: 0;
  color: #2a1208;
  background: linear-gradient(180deg, #ffe7ad, #e2b34a 45%, #a9782f);
  border-radius: 999px;
  min-height: 48px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 8px 0 #6d4314, 0 12px 18px rgba(0, 0, 0, 0.28);
}

.plaque.secondary {
  color: var(--ivory);
  background: linear-gradient(180deg, #ff3b45, var(--crimson) 40%, #8d1020);
  box-shadow: 0 8px 0 #4d0a12, 0 12px 18px rgba(0, 0, 0, 0.28);
}

.plaque.ghost, .text-link.ghost {
  color: var(--gold);
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line);
}

.plaque:active, .text-link:active { transform: translateY(2px); }

.section-title {
  font-family: var(--display);
  font-size: clamp(1.6rem, 6vw, 2.3rem);
  margin: 18px 0 8px;
  text-align: center;
}

.teaser-list, .stack { display: flex; flex-direction: column; gap: 10px; }

.hero-card, .rule, .chamber-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(28, 10, 14, 0.82);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 3px rgba(88, 16, 24, 0.45);
}

.hero-card { grid-template-columns: 76px minmax(0, 1fr); align-items: center; }

.hero-card img, .party-btn img, .token.hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portrait, .party-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--gold);
  background: #5c1020;
  padding: 0;
}

.party-btn { width: 46px; height: 46px; position: relative; }

.hero-card h3, .rule h3, .chamber-card h3 { margin: 0; font-size: 1.05rem; }

.hero-card p, .rule p, .chamber-card p { margin: 4px 0 0; }

.ability {
  display: inline-block;
  margin-top: 6px;
  color: #2a1208;
  background: var(--gold);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 700;
}

.ability.meera { background: #7ddecb; }
.ability.kabir { background: #f0c36a; }

.relic-mark {
  width: min(180px, 48%);
  margin: 16px auto 0;
  border-radius: 24px;
  border: 1px solid var(--line);
}

.banner {
  margin-top: 8px;
  border-radius: 22px 22px 16px 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 16 / 8;
}

.banner img { width: 100%; height: 100%; object-fit: cover; }

.rule { grid-template-columns: 1fr; }

.mini {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.m {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid rgba(243, 212, 138, 0.35);
}

.m-floor { background: var(--felt); }
.m-wall { background: #3a1218; }
.m-gap { background: #07090d; box-shadow: inset 0 0 0 2px #c4923a; }
.m-block { background: linear-gradient(145deg, #d7b07a, #6d4a28); }
.m-rune { background: radial-gradient(circle, #fff1c2 0 30%, #114237 32%); }
.m-door { background: repeating-linear-gradient(90deg, #f3d48a 0 3px, #6d1020 3px 8px); }
.m-aarav { background: #e10600; border-radius: 50%; }
.m-meera { background: #1aa58f; border-radius: 50%; }
.m-kabir { background: #e6b15a; border-radius: 50%; }
.m-exit { background: radial-gradient(circle, #fff1c2, #a9782f); }

.chamber-list { display: flex; flex-direction: column; gap: 8px; }

.chamber-card {
  grid-template-columns: auto minmax(0, 1fr);
  width: 100%;
  text-align: left;
  color: inherit;
}

.chamber-card.is-locked { opacity: 0.48; }

.chamber-index {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--latin);
  color: #2a1208;
  background: linear-gradient(180deg, #ffe7ad, #c4923a);
  font-weight: 700;
}

.stars { display: flex; gap: 3px; margin-top: 6px; }

.star {
  width: 14px;
  height: 14px;
  background: #4a342c;
  clip-path: polygon(50% 0, 62% 35%, 100% 38%, 70% 60%, 78% 100%, 50% 78%, 22% 100%, 30% 60%, 0 38%, 38% 35%);
}

.star.is-on { background: linear-gradient(#fff1c2, #e2b34a); }

.summary {
  text-align: center;
  color: var(--gold);
  margin-top: 0;
}

#screen-play {
  background:
    linear-gradient(180deg, rgba(12, 4, 6, 0.55), rgba(12, 4, 6, 0.88)),
    url("chamber.jpg") center / cover no-repeat;
}

.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 0;
}

.hud-copy { min-width: 0; flex: 1; }

.hud-kicker, .objective, .coach {
  margin: 0;
  color: var(--gold);
  font-size: 0.78rem;
}

.hud-title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.15rem, 5vw, 1.7rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-stats {
  display: flex;
  gap: 6px;
  align-items: center;
}

.stat, .icon-btn {
  min-width: 42px;
  min-height: 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(18, 7, 10, 0.72);
  color: var(--ivory);
  display: grid;
  place-items: center;
  padding: 0 8px;
  font-weight: 700;
}

.objective, .coach { padding: 4px 12px 0; }

.coach { color: var(--ivory); }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  touch-action: none;
}

.board {
  display: grid;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 5px rgba(88, 12, 20, 0.8), 0 12px 24px rgba(0, 0, 0, 0.35);
  background: var(--felt-deep);
}

.cell, .token { min-width: 0; min-height: 0; }

.cell.floor {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 40%),
    var(--felt);
  box-shadow: inset 0 0 0 1px rgba(243, 212, 138, 0.18);
}

.cell.wall {
  background:
    repeating-linear-gradient(135deg, rgba(243, 212, 138, 0.18) 0 2px, transparent 2px 8px),
    #3a1218;
}

.cell.chasm, .cell.bridge {
  background: radial-gradient(circle at 50% 40%, #1a2430, #05070a 70%);
  box-shadow: inset 0 0 0 2px rgba(196, 146, 58, 0.45);
}

.cell.bridge.up {
  background: linear-gradient(180deg, #f0d7a0, #a9782f);
  box-shadow: inset 0 0 0 2px rgba(255, 244, 214, 0.4);
}

.cell.door {
  background: repeating-linear-gradient(90deg, #f3d48a 0 3px, #6d1020 3px 9px);
}

.cell.door.open { background: var(--felt); box-shadow: inset 0 0 0 2px rgba(243, 212, 138, 0.55); }

.cell.exit {
  background: radial-gradient(circle, #fff4c9 0 28%, #e2b34a 45%, #8d5a16 80%);
}

.cell.filled { box-shadow: inset 0 0 0 3px rgba(215, 176, 122, 0.8); }

.token { z-index: 2; align-self: center; justify-self: center; }

.token.block {
  width: 74%;
  height: 74%;
  border-radius: 6px;
  background: linear-gradient(145deg, #f0d2a4, #8a5a30 55%, #4e3018);
  box-shadow: inset 0 0 0 2px rgba(255, 236, 196, 0.45);
}

.token.gem {
  width: 62%;
  height: 62%;
  border-radius: 50%;
  background: url("relic.png") center / cover no-repeat;
  box-shadow: 0 0 8px rgba(243, 212, 138, 0.8);
}

.token.rune {
  width: 70%;
  height: 70%;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: rgba(8, 20, 18, 0.35);
}

.token.rune.is-on {
  background: radial-gradient(circle, #fff6d0, #e2b34a 60%, transparent 62%);
  box-shadow: 0 0 10px rgba(243, 212, 138, 0.9);
}

.token.seal {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  border: 2px dashed currentColor;
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * 0.28);
  font-weight: 700;
  background: rgba(0, 0, 0, 0.25);
}

.token.seal.aarav { color: #ff8d96; }
.token.seal.meera { color: #8ef0e0; }
.token.seal.kabir { color: #ffd98a; }
.token.seal.is-met { background: rgba(243, 212, 138, 0.28); }

.token.hero {
  width: 84%;
  height: 84%;
  min-width: 0;
  min-height: 0;
  border-radius: 50%;
  overflow: hidden;
  padding: 0;
  border: 2px solid #fff6ea;
  z-index: 4;
  background: #5c1020;
}

.token.hero.aarav { border-color: #ffb3b8; }
.token.hero.meera { border-color: #9cf3e6; }
.token.hero.kabir { border-color: #ffe1a3; }

.token.hero.is-selected {
  box-shadow: 0 0 0 2px #fff6d4, 0 0 0 4px var(--crimson);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 8px 8px;
}

.party { display: flex; flex-direction: column; gap: 6px; }

.party-btn.is-selected { box-shadow: 0 0 0 2px #fff6d4; }
.party-btn:disabled { opacity: 0.35; }

.pad {
  display: grid;
  grid-template-columns: repeat(3, clamp(40px, 12vw, 52px));
  grid-template-rows: repeat(3, clamp(36px, 10vw, 46px));
  gap: 4px;
}

.pad button, .side-actions button {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(18, 7, 10, 0.82);
  color: var(--ivory);
  font-weight: 700;
}

.pad-up { grid-column: 2; grid-row: 1; }
.pad-left { grid-column: 1; grid-row: 2; }
.pad-right { grid-column: 3; grid-row: 2; }
.pad-down { grid-column: 2; grid-row: 3; }

#btn-activate {
  grid-column: 2;
  grid-row: 2;
  background: radial-gradient(circle at 50% 30%, #ff5a62, #9d1224);
  color: white;
  border-color: var(--gold);
  font-size: 11px;
  line-height: 1.1;
  padding: 0;
}

#btn-activate:disabled { opacity: 0.4; }

.side-actions { display: flex; flex-direction: column; gap: 4px; }

.side-actions button {
  min-width: 64px;
  min-height: 32px;
  padding: 0 8px;
}

.plinth {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: end;
  gap: 2px;
  padding: 18px 4px calc(6px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(225, 6, 0, 0.18), #14080b 38%);
  border-top: 1px solid var(--line);
}

.plinth::before {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 8px;
  height: 8px;
  background: radial-gradient(circle, #ffe7a8 0 3px, transparent 4px) 0 0 / 16px 8px repeat-x;
  animation: march 1.1s linear infinite;
  opacity: 0.85;
}

@keyframes march { to { background-position: 16px 0; } }

.nav-btn {
  min-width: 0;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  padding: 2px;
}

.nav-ico { width: 22px; height: 22px; display: grid; place-items: center; }
.nav-ico svg { width: 22px; height: 22px; }
.nav-label {
  font-size: 11px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-btn.is-active { color: var(--gold); }

.crest {
  width: 66px;
  height: 66px;
  margin: -8px auto 2px;
  border-radius: 50%;
  justify-self: center;
  background: radial-gradient(circle at 50% 32%, #ff5460, #a10f22 70%);
  color: white;
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 4px #4c0d16, 0 8px 16px rgba(0, 0, 0, 0.4);
}

.crest .nav-label { font-size: 14px; font-weight: 700; color: white; }

.crest.is-active { box-shadow: 0 0 0 4px #f3d48a, 0 8px 16px rgba(0, 0, 0, 0.4); }

.result {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(7, 3, 5, 0.78);
}

.result-card {
  width: min(100%, 380px);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 16px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background:
    radial-gradient(80% 50% at 50% 0%, rgba(225, 6, 0, 0.35), transparent 60%),
    #1c0b10;
  text-align: center;
}

.result-card img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  margin: 0 auto 8px;
  border-radius: 28px;
}

.result-card h2 { font-family: var(--display); margin: 0; }

.result-stars { display: flex; justify-content: center; gap: 6px; margin: 8px 0; }
.result-stars .star { width: 22px; height: 22px; }

.toast {
  position: fixed;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  max-width: calc(100% - 28px);
  padding: 10px 14px;
  border-radius: 999px;
  background: #1c0b10;
  border: 1px solid var(--gold);
  color: var(--ivory);
  opacity: 0;
  pointer-events: none;
}

.toast.is-on { opacity: 1; }

.stage.shake { animation: shake 0.18s linear; }

@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@media (min-width: 380px) {
  .page { padding: 18px 18px 28px; }
  .hero-card { grid-template-columns: 92px minmax(0, 1fr); }
  .portrait { width: 92px; height: 92px; }
}

@media (max-width: 340px) {
  .crest { width: 58px; height: 58px; }
  .nav-label { font-size: 10px; }
  .party-btn { width: 40px; height: 40px; }
  .side-actions button { min-width: 56px; font-size: 0.78rem; }
}

@media (max-height: 520px) {
  .plinth { padding-top: 10px; }
  .plinth::before { display: none; }
  .crest { width: 52px; height: 52px; margin-top: 0; }
  .pad { grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 28px); }
  .hud { padding-top: 4px; }
  #screen-play.is-active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
  }
  #screen-play .hud { grid-column: 1 / -1; grid-row: 1; }
  #screen-play .objective,
  #screen-play .coach { display: none; }
  #screen-play .stage { grid-column: 1; grid-row: 2; min-height: 0; }
  #screen-play .controls {
    grid-column: 2;
    grid-row: 2;
    flex-direction: column;
    justify-content: center;
    padding: 4px 6px 4px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lamps i, .plinth::before, .stage.shake { animation: none; }
}
