@font-face {
  font-family: "Pixelify Sans";
  src: url('/fonts/pixelify-sans.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}
:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #f9e8d6;
  background: #160f18;
  --cream: #fff0d6;
  --muted: #c8afb1;
  --edge: #76565c;
  --panel: #201924;
  --accent: #ffc27d;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
button, a, select { touch-action: manipulation; }
button, select {
  color: var(--cream); background: #302535; border: 1px solid var(--edge);
  border-radius: 4px; min-height: 39px; padding: .42rem .7rem; cursor: pointer;
}
button:hover:not(:disabled) { background: #46334a; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid #93eee5; outline-offset: 3px; }
a { color: inherit; }
h1, h2, p, ol { margin: 0; }
#game { position: relative; isolation: isolate; display: grid; min-height: 100dvh; height: 100dvh; overflow: hidden; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -3; image-rendering: pixelated; }
@media (min-width: 900px) and (pointer: fine) {
  #game:is([data-phase="question"], [data-phase="charge"], [data-phase="recap"], [data-phase="finale"])::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: linear-gradient(90deg, #080714df, #0b091977 14%, transparent 31% 69%, #0b091977 86%, #080714df);
  }
}
#game::before { content: ''; position: absolute; inset: 0; z-index: -2; pointer-events: none; background:
  linear-gradient(#130e19c9, transparent 19%, transparent 67%, #130d17da),
  linear-gradient(90deg, #130d19bd, transparent 27%, transparent 73%, #130d19bd); }
.hud {
  position: absolute; top: 0; inset-inline: 0; z-index: 3;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: .65rem; width: min(100%, 1360px); margin: auto; padding: 16px 24px;
}
.back { justify-self: start; font-weight: 650; font-size: .85rem; text-decoration: none; }
.back:hover { text-decoration: underline; }
.region { display: grid; justify-items: center; text-align: center; }
#biome { font-weight: 800; }
#round { color: var(--muted); font-size: .78rem; }
.hud-right { justify-self: end; display: flex; align-items: center; gap: .75rem; }
#distance { font: 800 1rem ui-monospace, Consolas, monospace; white-space: nowrap; }
#sound { min-height: 35px; font-size: .76rem; padding-inline: .5rem; white-space: nowrap; }
.controls {
  display: flex; justify-content: center; align-items: end; min-height: 0;
  padding: 4.2rem 1rem clamp(53px, 7vh, 88px); pointer-events: none;
}
.controls:has(.intro:not([hidden])), .controls:has(.results:not([hidden])) { align-items: center; }
.panel {
  pointer-events: auto; width: min(100%, 510px); color: var(--cream);
  background: linear-gradient(155deg, #261d2a, var(--panel) 62%);
  border: 1px solid var(--edge); border-top: 2px solid var(--accent); border-radius: 5px;
  padding: clamp(1rem, 3vw, 1.7rem); box-shadow: 0 7px #100c16, 0 12px 48px #0b0815a0;
  max-height: 100%; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin;
}
.intro { text-align: left; margin-bottom: 12vh; padding: clamp(1.3rem, 5vw, 2.4rem); align-self: center; }
.kicker, .banner { font: 750 .77rem ui-monospace, Consolas, monospace; text-transform: uppercase; letter-spacing: .15em; color: var(--accent); }
h1 { font: 950 clamp(1.95rem, 10vw, 4.15rem)/.94 system-ui, sans-serif; letter-spacing: -.073em; margin: .55rem 0 1rem; text-shadow: 3px 3px 0 #914d47; }
h2 { font-size: clamp(1.16rem, 3.5vw, 1.64rem); line-height: 1.18; letter-spacing: -.023em; margin: .45rem 0 .65rem; }
.intro > p:not(.kicker), #rules, #loot, #final-biome, #map-label, #feedback, #start-status, #replay-status { color: var(--muted); }
.intro button, .results > button { margin-top: 1rem; min-width: 136px; }
.primary {
  min-height: 44px; background: #ffc485; color: #2b1b26; font-weight: 850;
  border-color: #ffe0aa; box-shadow: inset 0 -3px #c8815e;
}
.primary:hover:not(:disabled) { background: #ffdc9f; }
.reward, .banner {
  position: absolute; inset-inline: 0; margin-inline: auto; width: max-content; max-width: calc(100% - 2rem);
  text-align: center; border: 1px solid #a67865; background: #201825ed; box-shadow: 0 4px #100b14;
  padding: .6rem .9rem; border-radius: 3px; pointer-events: none; z-index: 2;
}
.reward { top: clamp(74px, 14vh, 135px); color: var(--cream); font-weight: 850; }
.banner { top: clamp(124px, 23vh, 220px); color: #affbf3; border-color: #528783; }
.banner:not([hidden]) { animation: discover 230ms ease-out both; }
.banner.biome-reveal {
  font-family: "Pixelify Sans", monospace;
  font-size: clamp(1.04rem, 3vw, 1.65rem);
  letter-spacing: .045em;
  color: #ddffff;
  background: #15283be8;
  border: 2px solid #74dce8;
  box-shadow: 0 4px #100b19, 0 0 30px #56d4e859;
}
.banner.biome-reveal:not([hidden]) { animation: breach-title 310ms cubic-bezier(.16,.85,.25,1) both; }
@keyframes breach-title {
  from { opacity: 0; transform: translateY(-12px) scale(.86); }
  60% { opacity: 1; transform: translateY(2px) scale(1.04); }
  to { opacity: 1; transform: none; }
}
@keyframes discover {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}
.reward[data-tone="rarest"], .reward[data-tone="deep"] { color: #ffe0a3; border-color: #ffd486; }
.results #total { font-size: clamp(2rem, 7vw, 3.6rem); }
#journey { list-style: none; padding: 0; margin: .85rem 0; display: grid; gap: .3rem; }
#journey li { position: relative; isolation: isolate; display: grid; grid-template-columns: 2rem 1fr auto; gap: .4rem; align-items: center; padding: .42rem; font-size: .82rem; }
#journey progress { position: absolute; z-index: -1; inset: 0; width: 100%; height: 100%; appearance: none; opacity: .55; }
progress::-webkit-progress-bar { background: #31283c; border-radius: 4px; }
progress::-webkit-progress-value { background: #70536b; border-radius: 4px; }
#loot { font-size: .88rem; }
.lab { position: absolute; bottom: 10px; left: 12px; width: min(340px, calc(100% - 24px)); z-index: 5; }
.lab summary { width: max-content; border: 1px solid #685965; border-radius: 4px; background: #211a28; padding: .4rem .65rem; font-size: .76rem; color: var(--muted); cursor: pointer; }
.lab-body { background: var(--panel); border: 1px solid var(--edge); padding: .55rem; margin-top: .3rem; border-radius: 3px; }
.lab-actions, .lab-settings { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.lab-actions { margin-bottom: .45rem; }
.lab button, .lab select { min-height: 31px; font-size: .74rem; padding: .26rem .42rem; }
.lab label { font-size: .75rem; color: var(--muted); }
.lab-settings label { display: flex; gap: .22rem; align-items: center; }
.lab input[type="range"] { max-width: 68px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
@media (max-width: 540px) {
  .hud { padding: 10px 8px; gap: .25rem; }
  .hud-right { gap: .28rem; }
  .back, #biome { font-size: .75rem; }
  #distance { font-size: .77rem; }
  .controls { padding-inline: 10px; }
  .intro { margin-bottom: 16vh; }
  #sound { font-size: .68rem; padding-inline: .28rem; }
}
@media (max-height: 540px) {
  .controls { padding-block: 48px 34px; }
  .intro { margin-bottom: 0; }
  .lab { bottom: 2px; }
}

#trivia { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
#game[data-phase="question"] :is(.region, .hud #distance) { visibility: hidden; }
#game[data-keyboard] .lab { visibility: hidden; }
#game[data-blind-test] :is(.hud, .reward, .banner, .lab) { visibility: hidden; }

/* Keep the ceiling and floor vignette while leaving the side caverns readable. */
#game::before {
  background: linear-gradient(#130e19b0, transparent 16%, transparent 72%, #130d17b0);
}
#fullscreen { min-height: 35px; min-width: 35px; padding: 0 5px; font-size: 1rem; }
#game[data-phase="recap"] :is(.region, #distance) { visibility: hidden; }
.realm-reveal {
  --realm-light: #9be7ff;
  --realm-ink: #171225;
  position: absolute;
  z-index: 6;
  inset: 50% auto auto 50%;
  width: min(92vw, 740px);
  box-sizing: border-box;
  translate: -50% -50%;
  text-align: center;
  pointer-events: none;
  padding: 20px 12px 23px;
  color: #fff6df;
  background: radial-gradient(ellipse at center, var(--realm-ink) 7%, color-mix(in srgb, var(--realm-ink), transparent 13%) 48%, transparent 73%);
  animation: realm-card 1.46s both;
}
.realm-reveal::before, .realm-reveal::after {
  content: '';
  display: block;
  width: min(85%, 410px);
  height: 2px;
  margin: 7px auto;
  background: linear-gradient(90deg, transparent, var(--realm-light) 22%, #fff5d9 50%, var(--realm-light) 78%, transparent);
  box-shadow: 0 0 15px color-mix(in srgb, var(--realm-light), transparent 55%);
}
#realm-crest {
  display: block;
  width: clamp(80px, 14vw, 135px);
  height: auto;
  margin: -12px auto -5px;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 14px var(--realm-light));
}
.realm-kicker {
  margin: 4px 0;
  color: var(--realm-light);
  font: 700 clamp(.68rem, 1.3vw, .88rem)/1.2 ui-monospace, monospace;
  letter-spacing: .2em;
  text-transform: uppercase;
}
#realm-name {
  margin: .12em 0 .14em;
  font: 700 clamp(2rem, 7vw, 4.6rem)/.94 "Pixelify Sans", monospace;
  text-transform: uppercase;
  text-wrap: balance;
  text-shadow: 3px 4px #0c0a16, 0 0 20px color-mix(in srgb, var(--realm-light), transparent 48%);
}
#realm-chain { font: 650 .75rem/1.4 ui-monospace, monospace; color: #f1d8dc; text-wrap: balance; }
@keyframes realm-card {
  0% { opacity: 0; transform: translateY(16px) scale(.88); }
  16%, 82% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-11px); }
}
@media (max-width: 460px) {
  #fullscreen { min-width: 28px; }
  .realm-reveal { padding-inline: 7px; width: 97vw; }
  #realm-chain { font-size: .62rem; }
}
@media (prefers-reduced-motion: reduce) {
  .realm-reveal { animation: realm-fade 1.1s both; }
  @keyframes realm-fade { 0%, 100% { opacity: 0; } 12%, 86% { opacity: 1; } }
}
