:root {
  --jungle: #052E23;
  --navy: #232F3E;
  --orange: #FF9900;
  --gold: #E9B949;
  --leaf: #41B96C;
  --parchment: #FFF2D2;
  --ink: #17202b;
  --serif: "Cinzel", Palatino, "Palatino Linotype", serif;
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  font-family: var(--sans);
  color: var(--parchment);
  background:
    linear-gradient(180deg, rgba(5, 46, 35, 0.9), rgba(35, 47, 62, 0.92)),
    url("bg-canopy.png") center/cover;
  min-height: 100dvh;
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

button:disabled { cursor: not-allowed; }

img { border: 0; -webkit-user-drag: none; user-select: none; }

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

::selection { background: var(--orange); color: var(--navy); }

h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; }

p { margin: 0; }

.eyebrow, .kicker {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--orange);
  font-weight: 700;
}

.btn {
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  padding: 12px 18px;
  font-weight: 700;
}

.btn-orange { background: var(--orange); color: var(--navy); }

.btn-ghost {
  background: transparent;
  color: var(--parchment);
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.65);
}

.btn:hover { filter: brightness(1.05); }

#splash {
  position: fixed;
  inset: 0;
  z-index: 40;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(5, 46, 35, 0.2), rgba(5, 46, 35, 0.62)),
    url("bg-canopy.png") center/cover;
}

.vine-curtain {
  position: absolute;
  top: -8%;
  bottom: -8%;
  width: 48%;
  display: flex;
  z-index: 2;
  pointer-events: none;
}

.vine-curtain img {
  width: 50%;
  height: 100%;
  object-fit: contain;
}

.vine-curtain.left {
  left: 0;
  transform: translateX(26%);
  animation: partLeft 1.5s ease forwards;
}

.vine-curtain.right {
  right: 0;
  transform: translateX(-26%) scaleX(-1);
  animation: partRight 1.5s ease forwards;
}

@keyframes partLeft {
  from { transform: translateX(26%); }
  to { transform: translateX(-24%); }
}

@keyframes partRight {
  from { transform: translateX(-26%) scaleX(-1); }
  to { transform: translateX(24%) scaleX(-1); }
}

.splash-core {
  position: absolute;
  left: 50%;
  top: 24%;
  transform: translateX(-50%);
  z-index: 1;
  display: grid;
  place-items: center;
}

.splash-lamp {
  width: min(210px, 48vw);
  animation: gather 1.5s ease forwards;
  position: relative;
}

.splash-ring {
  position: absolute;
  width: min(250px, 58vw);
  height: 52px;
  border: 4px solid var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 18px rgba(233, 185, 73, 0.85);
  animation: ringIn 1.5s ease forwards;
  opacity: 0;
}

@keyframes gather {
  0% { opacity: 0.15; filter: brightness(0.2) drop-shadow(0 0 0 var(--orange)); transform: scale(0.82); }
  100% { opacity: 1; filter: brightness(1.15) drop-shadow(0 0 26px var(--orange)); transform: scale(1); }
}

@keyframes ringIn {
  0%, 35% { opacity: 0; }
  100% { opacity: 1; }
}

.splash-copy {
  position: absolute;
  left: 50%;
  bottom: 12%;
  z-index: 3;
  text-align: center;
  width: min(92vw, 640px);
  animation: titleIn 1.5s ease forwards;
  opacity: 0;
}

@keyframes titleIn {
  0%, 42% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.splash-copy h1 {
  font-size: clamp(2rem, 6vw, 3.5rem);
  color: var(--parchment);
  text-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}

.splash-copy p {
  margin-top: 8px;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

#onboarding {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    linear-gradient(180deg, rgba(5, 46, 35, 0.84), rgba(35, 47, 62, 0.9)),
    url("bg-canopy.png") center/cover;
}

.ob-top { text-align: center; padding: 16px 16px 0; }

.ob-top h1 { font-size: 1.4rem; margin-top: 4px; }

.dots { display: flex; gap: 7px; justify-content: center; margin-top: 8px; }

.dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 242, 210, 0.35);
}

.dots span.is-on { background: var(--orange); box-shadow: 0 0 8px var(--orange); }

.scene-frame { min-height: 0; overflow: auto; padding: 8px 12px 12px; }

.scene { text-align: center; padding-bottom: 8px; }

.scene h2 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin: 6px 0; }

.lead {
  max-width: 38rem;
  margin: 0 auto 8px;
  color: var(--parchment);
}

.vine-stage {
  position: relative;
  height: min(420px, 52vh);
  margin: 12px auto 0;
  max-width: 560px;
  touch-action: none;
  overflow: hidden;
  border-radius: 24px;
  background: rgba(35, 47, 62, 0.72);
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.4);
}

.vine-stage .door {
  position: absolute;
  top: -8%;
  height: 116%;
  width: 42%;
  object-fit: contain;
  pointer-events: none;
}

.vine-stage .door.left { left: 0; }

.vine-stage .door.left.b { left: 16%; }

.vine-stage .door.right { right: 0; transform: scaleX(-1); }

.vine-stage .door.right.b { right: 16%; }

.door-lamp {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 120px;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0 16px var(--orange));
  pointer-events: none;
}

.door-ring {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 180px;
  height: 42px;
  transform: translate(-50%, -50%);
  border: 3px solid var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 14px var(--gold);
  pointer-events: none;
  opacity: 0;
}

.lesson-lamp {
  width: min(230px, 68vw);
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  margin: 16px auto;
  display: grid;
  place-items: center;
  position: relative;
  touch-action: none;
  background: radial-gradient(circle, rgba(255, 153, 0, 0.22), var(--navy) 64%);
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.45), 0 12px 30px rgba(0, 0, 0, 0.28);
}

.lesson-lamp svg { position: absolute; inset: 0; width: 100%; height: 100%; }

.lesson-lamp img { width: 42%; position: relative; }

.ring-track { fill: none; stroke: rgba(233, 185, 73, 0.35); stroke-width: 6; }

.ring-value {
  fill: none;
  stroke: var(--orange);
  stroke-width: 6;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 60px 60px;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
}

.meter {
  width: 118px;
  height: 300px;
  margin: 16px auto;
  position: relative;
  border-radius: 60px;
  overflow: hidden;
  touch-action: none;
  background: linear-gradient(180deg, #1a2836, var(--navy));
  box-shadow: inset 0 0 0 3px var(--gold), 0 0 24px rgba(255, 153, 0, 0.18);
}

.meter-fill {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  height: 0;
  border-radius: 40px;
  background: linear-gradient(180deg, var(--parchment), var(--orange) 32%, var(--gold));
  box-shadow: 0 0 18px var(--orange);
}

.meter-band {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(233, 185, 73, 0.18);
  border-top: 3px solid var(--gold);
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 0 12px rgba(233, 185, 73, 0.45);
}

.meter-band.is-hot {
  background: rgba(255, 153, 0, 0.28);
  border-color: var(--orange);
  box-shadow: 0 0 16px var(--orange);
}

.meter img {
  position: absolute;
  width: 64px;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  pointer-events: none;
}

.ob-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: rgba(5, 46, 35, 0.92);
  border-top: 1px solid rgba(233, 185, 73, 0.28);
}

.legal-inline {
  width: 100%;
  text-align: center;
  color: var(--gold);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding-top: env(safe-area-inset-top);
}

.totems {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 10px 0;
}

.totem {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-height: 108px;
  padding: 30px 6px 12px;
  border: 0;
  color: var(--parchment);
  background:
    linear-gradient(180deg, rgba(255, 153, 0, 0.1), transparent 30%),
    linear-gradient(180deg, #314255, var(--navy) 46%, #0d1c18);
  border-radius: 18px 18px 12px 12px;
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.32), inset 0 -18px 24px rgba(0, 0, 0, 0.35);
}

.totem .flame {
  position: absolute;
  top: 4px;
  width: 30px;
  height: 30px;
  object-fit: contain;
  opacity: 0;
}

.totem.is-on .flame {
  opacity: 1;
  filter: drop-shadow(0 0 10px var(--orange));
  animation: lampBreath 1.6s ease-in-out infinite;
}

.totem.is-on {
  box-shadow: inset 0 0 0 2px var(--orange), 0 0 22px rgba(255, 153, 0, 0.35);
}

.totem .mark { width: 42px; height: 42px; object-fit: contain; }

.totem span {
  font-family: var(--serif);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

@keyframes lampBreath {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 6px var(--orange)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 16px var(--orange)); }
}

.column {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: relative;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 0;
}

.top h1 { font-size: clamp(1.25rem, 2.5vw, 1.8rem); }

#sound { min-height: 40px; padding: 8px 12px; }

.panels {
  min-height: 0;
  overflow: auto;
  padding-bottom: 8px;
}

.panel { padding: 12px 14px 22px; }

.panel-hold {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hold-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.hold-head h2 { font-size: 1.45rem; }

#hold-tempo { color: var(--gold); margin-top: 2px; }

.hold-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.hold-pills p {
  margin: 0;
  background: var(--navy);
  color: var(--gold);
  border-radius: 999px;
  padding: 6px 10px;
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.35);
  font-size: 0.85rem;
}

.halls {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(118px, 1fr);
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.hall {
  text-align: left;
  border: 0;
  border-radius: 14px;
  padding: 8px 10px;
  min-height: 54px;
  background: var(--navy);
  color: var(--parchment);
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.3);
}

.hall strong { display: block; font-family: var(--serif); font-size: 0.86rem; }

.hall span { display: block; margin-top: 2px; color: var(--leaf); font-size: 0.72rem; }

.hall.is-on { box-shadow: inset 0 0 0 2px var(--orange); }

.hall:disabled { opacity: 0.45; }

.stage {
  position: relative;
  flex: 1;
  min-height: 380px;
  border-radius: 24px;
  overflow: hidden;
  background: var(--jungle);
  box-shadow: inset 0 0 0 2px rgba(233, 185, 73, 0.45), 0 16px 40px rgba(0, 0, 0, 0.28);
  touch-action: none;
}

.stage-practice {
  flex: none;
  height: min(440px, 48vh);
  min-height: 280px;
  margin-top: 8px;
}

.stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.stage.is-spill { animation: spill 0.4s ease; }

.stage.is-hit { animation: hitglow 0.7s ease; }

@keyframes spill {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  55% { transform: translateX(5px); }
}

@keyframes hitglow {
  0% { box-shadow: inset 0 0 0 2px rgba(233, 185, 73, 0.45); }
  40% { box-shadow: inset 0 0 0 2px var(--orange), 0 0 28px rgba(255, 153, 0, 0.45); }
  100% { box-shadow: inset 0 0 0 2px rgba(233, 185, 73, 0.45); }
}

.stage-result {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  pointer-events: none;
  background: var(--parchment);
  color: var(--navy);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
}

.stage-result[data-rarity="leaf"] { box-shadow: inset 0 0 0 2px var(--leaf), 0 12px 30px rgba(0, 0, 0, 0.32); }

.stage-result[data-rarity="vine"] { box-shadow: inset 0 0 0 2px #7dcea0, 0 12px 30px rgba(0, 0, 0, 0.32); }

.stage-result[data-rarity="gold"] { box-shadow: inset 0 0 0 2px var(--gold), 0 12px 30px rgba(0, 0, 0, 0.32); }

.stage-result[data-rarity="mask"] { box-shadow: inset 0 0 0 2px var(--orange), 0 12px 30px rgba(0, 0, 0, 0.32); }

.result-title { font-family: var(--serif); font-size: 1.05rem; margin: 0 0 4px; color: var(--ink); }

.result-sub, .result-gain, .result-foot { margin: 0; color: var(--ink); }

.result-gain { font-weight: 700; margin-top: 4px; }

.result-foot {
  margin-top: 4px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hint { font-weight: 600; }

.hint-sub { color: rgba(255, 242, 210, 0.78); font-size: 0.88rem; }

.hero {
  position: relative;
  min-height: 190px;
  border-radius: 22px;
  overflow: hidden;
  display: grid;
  align-items: end;
  margin-bottom: 12px;
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.4);
}

.hero img:first-child {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-mask {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 84px;
  height: 84px;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
}

.hero-copy {
  position: relative;
  padding: 16px;
  background: linear-gradient(180deg, transparent, rgba(5, 46, 35, 0.94));
  display: grid;
  gap: 6px;
}

.hero-copy .legal-inline { text-align: left; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  background: var(--navy);
  border-radius: 16px;
  padding: 10px;
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.35);
}

.stat img { width: 28px; height: 28px; object-fit: contain; }

.stat b {
  display: block;
  margin-top: 4px;
  font-family: var(--serif);
  font-size: clamp(1.05rem, 3.5vw, 1.55rem);
  color: var(--gold);
}

.stat span {
  display: block;
  margin-top: 2px;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.card {
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(255, 242, 210, 0.06), transparent 46%),
    linear-gradient(180deg, #2a3a4c, var(--navy));
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.32);
  display: grid;
  gap: 8px;
}

.card h2 { font-size: 1.2rem; }

.xp-row, .rem-row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; }

.xp-track {
  height: 10px;
  border-radius: 999px;
  background: #15202b;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.28);
}

.xp-fill { height: 100%; background: linear-gradient(90deg, var(--gold), var(--orange)); }

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

.pips img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: grayscale(1) brightness(0.45);
}

.pips img.is-lit { filter: drop-shadow(0 0 8px var(--orange)) brightness(1.12); }

.ruin-halls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.log-item { padding-top: 4px; border-top: 1px solid rgba(233, 185, 73, 0.16); }

.log-item time { display: block; color: var(--gold); font-size: 0.75rem; }

.switch { display: flex; align-items: center; gap: 8px; }

input[type="time"] {
  background: #15202b;
  color: var(--parchment);
  border: 1px solid rgba(233, 185, 73, 0.5);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 44px;
}

.lede { color: rgba(255, 242, 210, 0.86); }

.relic-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.relic {
  background: rgba(21, 32, 43, 0.88);
  border-radius: 16px;
  padding: 8px;
  text-align: center;
  min-height: 156px;
  box-shadow: inset 0 0 0 1px rgba(233, 185, 73, 0.28);
}

.relic img { width: 72px; height: 72px; object-fit: contain; }

.relic h3 { font-size: 0.95rem; margin: 4px 0; }

.relic p { font-size: 0.78rem; color: rgba(255, 242, 210, 0.82); }

.tag {
  color: var(--gold);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.relic.is-locked img { filter: grayscale(1) brightness(0.45); }

.relic[data-rarity="leaf"] { box-shadow: inset 0 0 0 1px rgba(255, 242, 210, 0.45); }

.relic[data-rarity="vine"] { box-shadow: inset 0 0 0 1px var(--leaf); }

.relic[data-rarity="gold"] { box-shadow: inset 0 0 0 1px var(--gold); }

.relic[data-rarity="mask"] { box-shadow: inset 0 0 0 1px var(--orange); }

.page { border-top: 1px solid rgba(233, 185, 73, 0.16); padding-top: 6px; }

.page-toggle, .page-locked {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--parchment);
  font-family: var(--serif);
  font-size: 1rem;
  padding: 8px 0;
}

.page-locked { color: rgba(255, 242, 210, 0.48); }

.page-body { display: grid; gap: 8px; padding-bottom: 8px; }

textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  background: #15202b;
  color: var(--parchment);
  border: 1px solid rgba(233, 185, 73, 0.45);
  border-radius: 12px;
  padding: 10px;
  font-size: 16px;
}

.count { font-size: 0.75rem; color: var(--gold); }

.trail-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 7px 0;
  border-top: 1px solid rgba(233, 185, 73, 0.14);
  color: rgba(255, 242, 210, 0.72);
}

.trail-item.is-done { color: var(--parchment); }

.mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex: none;
  margin-top: 2px;
  box-shadow: inset 0 0 0 2px rgba(233, 185, 73, 0.65);
}

.trail-item.is-done .mark { background: var(--leaf); box-shadow: none; }

.legal {
  text-align: center;
  color: var(--parchment);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(5, 46, 35, 0.94);
  border-top: 1px solid rgba(233, 185, 73, 0.32);
}

.rite {
  position: absolute;
  z-index: 6;
  left: 12px;
  right: 12px;
  top: 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: center;
  background: var(--parchment);
  color: var(--navy);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.rite img { width: 52px; height: 52px; object-fit: contain; }

.rite .result-title, .rite p { color: var(--ink); }

.rite-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }

.rite .btn-ghost { color: var(--navy); box-shadow: inset 0 0 0 1px rgba(35, 47, 62, 0.45); }

.noscript { margin: 24px; }

.page-body, .log-item, .relic p, .lead { overflow-wrap: anywhere; }

@media (min-width: 720px) {
  .relic-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .ruin-halls { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 860px) {
  .shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    grid-template-columns: 136px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .totems {
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 10px;
  }

  .totem { flex: 1; min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .totem.is-on .flame { animation: none; }
  .stage.is-spill, .stage.is-hit { animation: none; }
}
