:root {
  /* Layout: one full-bleed night-sky canvas; HTML panels float in the sky and never cover the family at the bottom */
  --night: #0b0a1c;
  --panel: rgba(17, 12, 38, 0.74);
  --panel-line: rgba(255, 207, 90, 0.26);
  --ink: #f8efdc;
  --muted: #cbbfa8;
  --gold: #ffcf5a;
  --gold-deep: #e39b17;
  --heal: #3fd6c4;
  --display: "Yatra One", Georgia, "Times New Roman", serif;
  --body: "Mukta", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }

body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
  cursor: crosshair;
}

/* ---------- Title ---------- */
.title {
  position: fixed;
  inset: 0 0 auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding-top: max(6vh, calc(env(safe-area-inset-top, 0px) + 20px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  pointer-events: none;
}
.title button { pointer-events: auto; }

.eyebrow {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.title h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.6rem, min(12vw, 13vh), 7.5rem);
  line-height: 1;
  background: linear-gradient(180deg, #fff6d2 0%, #ffd56a 38%, #f0a823 70%, #b8680c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 180, 60, 0.45));
  text-wrap: balance;
  animation: glow 3.2s ease-in-out infinite;
}
@keyframes glow {
  50% { filter: drop-shadow(0 0 34px rgba(255, 190, 70, 0.7)); }
}

.tagline {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.3rem, 4vw, 2rem);
  color: var(--ink);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

.lede {
  margin: 4px 0 6px;
  max-width: 34rem;
  color: var(--muted);
  font-size: clamp(1.05rem, 2.8vw, 1.2rem);
  text-wrap: pretty;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
}

.btn-gold {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: 700 1.2rem/1 var(--body);
  color: #2a1503;
  padding: 15px 28px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe08a, #f2ac2b);
  box-shadow: 0 0 0 1px rgba(255, 230, 160, 0.6) inset, 0 8px 30px rgba(255, 170, 40, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-gold:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(255, 230, 160, 0.8) inset, 0 10px 38px rgba(255, 170, 40, 0.55);
}

.btn-ghost {
  appearance: none;
  cursor: pointer;
  font: 600 1rem/1 var(--body);
  color: var(--ink);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 14px 22px;
}
.btn-ghost:hover { border-color: var(--gold); }

.btn-gold:focus-visible,
.btn-ghost:focus-visible,
.sound:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.ladder-legend {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 56rem;
}
.ladder-legend li {
  font-size: 0.95rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--muted);
}
.ladder-legend b { color: var(--gold); margin-right: 5px; }
.ladder-legend li:last-child {
  background: rgba(255, 207, 90, 0.2);
  border-color: var(--gold);
  color: var(--ink);
}

.legend-note {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 300px);
  gap: 8px 16px;
  align-items: start;
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  pointer-events: none;
}

.hud-level,
.hud-gold {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 10px 14px;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.hud-level {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 32rem;
}
.lvl-text { min-width: 0; }

.lvl-code {
  flex: none;
  font-family: var(--display);
  font-size: 1.8rem;
  line-height: 1;
  color: #2a1503;
  background: linear-gradient(180deg, #ffe08a, #f2ac2b);
  border-radius: 10px;
  padding: 9px 10px 6px;
  min-width: 3ch;
  text-align: center;
}
.lvl-name {
  font-family: var(--display);
  font-size: 1.5rem;
  line-height: 1.1;
  color: var(--gold);
}
.lvl-goal { margin: 3px 0 0; font-size: 1.05rem; }
.lvl-progress {
  margin: 4px 0 0;
  font-size: 0.95rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.gold-head {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.gold-track {
  margin-top: 6px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.gold-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #c9cfdc, #ffd56a 60%, #ffb21f);
  box-shadow: 0 0 12px rgba(255, 190, 60, 0.7);
}

.ladder {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  font-size: 0.85rem;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ladder li { padding: 2px 0; border-radius: 6px; }
.ladder li.done { color: var(--gold); }
.ladder li.now { background: rgba(255, 207, 90, 0.22); color: var(--ink); font-weight: 700; }

.skills {
  grid-column: 1 / -1;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.skills li {
  font-size: 0.92rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px dashed rgba(255, 255, 255, 0.28);
  color: var(--muted);
  background: rgba(10, 8, 24, 0.6);
}
.skills li b { margin-right: 5px; }
.skills li.learned {
  border-style: solid;
  border-color: var(--heal);
  color: var(--ink);
  background: rgba(63, 214, 196, 0.16);
}
.skills li.learned b { color: var(--heal); }

/* ---------- Banner and toasts ---------- */
.banner {
  position: fixed;
  left: 50%;
  top: var(--sky-mid, 34%);
  transform: translate(-50%, -50%);
  width: min(calc(100vw - 32px), 34rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  pointer-events: none;
  background: rgba(20, 14, 40, 0.88);
  border: 1px solid rgba(255, 207, 90, 0.45);
  border-radius: 20px;
  padding: 16px 20px 18px;
  box-shadow: 0 0 50px rgba(255, 180, 60, 0.22);
}
.banner.play { animation: bannerIn 3.2s ease forwards; }
.banner-code {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
}
.banner-name {
  font-family: var(--display);
  font-size: clamp(2rem, 7vw, 3.4rem);
  line-height: 1.05;
  color: #fff1c9;
  text-shadow: 0 0 24px rgba(255, 180, 60, 0.6);
}
.banner-line {
  font-size: 1.2rem;
  text-wrap: balance;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -42%) scale(0.96); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.toasts {
  position: fixed;
  left: 50%;
  top: calc(var(--hud-h, 0px) + 10px);
  transform: translateX(-50%);
  width: min(92vw, 30rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  font-size: 1.02rem;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  text-align: center;
  animation: toastIn 0.25s ease;
  transition: opacity 0.4s;
}
.toast.heal { border-color: var(--heal); color: #d8fffa; }
.toast.learn { border-color: var(--gold); color: #fff3cf; background: rgba(60, 40, 8, 0.88); }
.toast.out { opacity: 0; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-6px); }
}

/* ---------- Next level ---------- */
.next {
  position: fixed;
  left: 50%;
  top: var(--sky-mid, 34%);
  transform: translate(-50%, -50%);
  width: min(calc(100vw - 32px), 28rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  background: rgba(20, 14, 40, 0.9);
  border: 1px solid rgba(255, 207, 90, 0.45);
  border-radius: 20px;
  padding: 22px 20px;
  box-shadow: 0 0 50px rgba(255, 180, 60, 0.22);
}
.next h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  line-height: 1.1;
  color: var(--gold);
  text-wrap: balance;
}
.next p:not(.eyebrow) { margin: 0; color: var(--ink); text-wrap: pretty; }

/* ---------- Win ---------- */
.win {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding-block: 24px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: radial-gradient(ellipse at center, rgba(11, 10, 28, 0.6), rgba(11, 10, 28, 0.15));
}
.win-card {
  width: min(100%, 30rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  background: rgba(20, 14, 40, 0.88);
  border: 1px solid rgba(255, 207, 90, 0.45);
  border-radius: 20px;
  padding: 26px 22px;
  box-shadow: 0 0 60px rgba(255, 180, 60, 0.25);
}
.win-card h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2rem, 7vw, 2.8rem);
  line-height: 1.05;
  color: var(--gold);
}
.win-card p { margin: 0; color: var(--muted); }

.stats {
  margin: 4px 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.stats div { background: rgba(255, 255, 255, 0.05); border-radius: 12px; padding: 8px; }
.stats dt { font-size: 0.9rem; color: var(--muted); }
.stats dd {
  margin: 0;
  font-family: var(--display);
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
}
.win-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ---------- Sound ---------- */
.sound {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  appearance: none;
  cursor: pointer;
  font: 600 0.88rem/1 var(--body);
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  padding: 7px 12px;
}

@media (max-width: 640px) {
  .hud { grid-template-columns: minmax(0, 1fr); }
  .hud-level { max-width: none; padding: 8px 12px; }
  .hud-gold { padding: 8px 12px; }
  .lvl-code { font-size: 1.4rem; }
  .lvl-goal { font-size: 0.98rem; }
  .legend-note { display: none; }
}

@media (max-height: 880px) {
  .title { gap: 6px; padding-top: max(3vh, calc(env(safe-area-inset-top, 0px) + 12px)); }
  .lede { display: none; }
  .legend-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .title h1, .banner.play, .toast { animation: none; }
  .banner.play { opacity: 1; }
}
