:root {
  color-scheme: light;
  --rex-sky: #bdcfba;
  --rex-paper: #fff8e9;
  --rex-ink: #29273e;
  --rex-muted: #625969;
  --rex-sage: #376d57;
  --rex-clay: #a13e32;
  --rex-sand: #e5c774;
  --rex-coral: #f08e78;
  --rex-cream: #f4edd9;
  --rex-scene-shadow: 0 1px 2px #29273ee6;
  --rex-font-sans: "Nines Geist", Arial, sans-serif;
  --rex-font-mono: "Nines Plex Mono", monospace;
  font-family: var(--rex-font-sans);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; background: var(--rex-sky); }
body { color: var(--rex-ink); }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: wait; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--rex-sage); outline-offset: 5px; }
button[hidden], [hidden], .hidden { display: none !important; }
#three-canvas { position: fixed; z-index: 0; inset: 0; display: block !important; width: 100% !important; height: 100% !important; outline: none; touch-action: pan-y pinch-zoom; }
/* Reserve field gestures for a run; menus allow scrolling the containing page. */
body:has(.rex-interface:is([data-phase="starting"], [data-phase="playing"], [data-phase="crashing"])) #three-canvas { touch-action: none; }
#score-counter, .rex-runtime-only, #ai-feedback, #language-selector { display: none !important; }

.rex-interface { position: fixed; z-index: 10; inset: 0; isolation: isolate; outline: none; pointer-events: none; font-variant-numeric: tabular-nums; }
.rex-header { position: absolute; z-index: 5; inset: 0 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 20px; padding: max(26px, env(safe-area-inset-top)) max(36px, env(safe-area-inset-right)) 0 max(36px, env(safe-area-inset-left)); }
.rex-header::before { content: ""; position: absolute; z-index: -1; inset: 0 0 -28px; background: linear-gradient(#29273e55, #29273e00); pointer-events: none; }
.rex-settings { grid-column: 3; display: flex; justify-content: flex-end; align-items: center; gap: 9px; }
.rex-tool { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 13px; border: 1px solid #29273e55; border-radius: 8px; background: #fff8e9c2; color: var(--rex-ink); font-family: var(--rex-font-mono); font-size: 11px; font-weight: 500; white-space: nowrap; pointer-events: auto; transition: background-color 140ms ease, border-color 140ms ease; }
.rex-tool:hover { background: var(--rex-paper); border-color: var(--rex-ink); }
.rex-sound-icon { display: flex; align-items: center; gap: 2px; width: 12px; height: 15px; }
.rex-sound-icon i { display: block; width: 2px; height: 3px; border-radius: 2px; background: currentColor; }
.rex-sound[aria-pressed="true"] .rex-sound-icon i:first-child { height: 9px; }
.rex-sound[aria-pressed="true"] .rex-sound-icon i:nth-child(2) { height: 15px; }
.rex-sound[aria-pressed="true"] .rex-sound-icon i:last-child { height: 11px; }
.rex-pause-icon { display: block; width: 10px; height: 12px; border-inline: 3px solid currentColor; }
.rex-hud { grid-column: 2; display: flex; justify-content: center; align-items: flex-start; gap: clamp(28px, 3.5vw, 46px); margin: 0; text-align: center; }
.rex-hud > div { min-width: 68px; }
.rex-hud dt { color: var(--rex-paper); font-family: var(--rex-font-mono); font-size: 10px; font-weight: 500; letter-spacing: .035em; text-shadow: var(--rex-scene-shadow); }
.rex-hud dd { margin: 5px 0 0; color: var(--rex-paper); font-size: clamp(30px, 2.8vw, 38px); font-weight: 850; line-height: 1; letter-spacing: -.035em; text-shadow: var(--rex-scene-shadow); }
.rex-hud .rex-best-score dd { margin-top: 8px; color: var(--rex-paper); font-size: clamp(23px, 2.1vw, 28px); font-weight: 750; letter-spacing: -.02em; }
.rex-hud[data-milestone="true"] .rex-current-score dd { color: var(--rex-coral); }

.rex-intro { position: absolute; z-index: 2; inset: 0; display: flex; flex-direction: column; align-items: center; padding: max(92px, calc(env(safe-area-inset-top) + 76px)) max(18px, env(safe-area-inset-right)) max(94px, calc(env(safe-area-inset-bottom) + 76px)) max(18px, env(safe-area-inset-left)); text-align: center; }
.rex-intro > * { flex-shrink: 0; }
.rex-intro > .rex-eyebrow { margin-bottom: 10px; }
.rex-intro > .rex-primary { margin-top: auto; }
.rex-eyebrow { margin: 0 0 14px; color: var(--rex-muted); font-family: var(--rex-font-mono); font-size: 10px; font-weight: 500; letter-spacing: .15em; text-transform: uppercase; }
.rex-intro h1 { margin: 0; color: var(--rex-coral); font-size: clamp(48px, 7vw, 68px); font-weight: 900; font-style: italic; line-height: .96; letter-spacing: -.06em; -webkit-text-stroke: 1.5px var(--rex-ink); paint-order: stroke fill; text-shadow: 0 3px 0 var(--rex-ink), 0 6px 12px #29273e66; }
.rex-intro h1 > span { color: var(--rex-sand); }
.rex-tagline { margin: 16px 0 22px; color: var(--rex-paper); font-size: 17px; font-weight: 600; line-height: 1.4; letter-spacing: -.015em; }
.rex-run-note { margin: -10px 0 20px; color: var(--rex-cream); font-family: var(--rex-font-mono); font-size: 11px; letter-spacing: .04em; }
.rex-intro > .rex-eyebrow { color: var(--rex-sand); }
.rex-intro > .rex-eyebrow, .rex-tagline, .rex-run-note, .rex-ready-best { text-shadow: 0 1px 2px var(--rex-ink), 0 2px 6px #29273ecc; }
.rex-hud .rex-demo-clock dd { color: var(--rex-paper); }
.rex-primary { display: inline-flex; align-items: center; justify-content: center; gap: 28px; min-width: 184px; min-height: 54px; padding: 14px 25px; border: 2px solid var(--rex-ink); border-radius: 9px; background: var(--rex-coral); color: var(--rex-ink); box-shadow: 0 4px 0 var(--rex-ink); font-size: 16px; font-weight: 750; line-height: 1.4; letter-spacing: -.015em; pointer-events: auto; transition: background-color 140ms ease, box-shadow 140ms ease; }
.rex-primary > span { font-size: 23px; line-height: 1; font-weight: 450; }
.rex-primary:hover { background: #f6a38f; }
.rex-primary:active { box-shadow: 0 1px 0 var(--rex-ink); }
.rex-primary:disabled { opacity: .55; }
.rex-ready-best { max-width: 100%; margin: 12px 0 0; color: var(--rex-paper); font-family: var(--rex-font-mono); font-size: 11px; overflow-wrap: anywhere; }
.rex-ready-best strong { margin-left: 7px; color: var(--rex-paper); font-family: var(--rex-font-sans); font-weight: 750; }
.rex-loading { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 9px 12px; width: 210px; margin: auto auto 0; color: var(--rex-paper); font-family: var(--rex-font-mono); font-size: 11px; line-height: 1.5; text-shadow: var(--rex-scene-shadow); }
.rex-loading > span:first-child { width: 100%; }
.rex-loading-bar { width: 160px; height: 3px; overflow: hidden; border-radius: 2px; background: #29273e29; }
.rex-loading-bar > span { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--rex-sage); transform: scaleX(var(--rex-progress, 0)); transform-origin: left; transition: transform 180ms linear; }

.rex-result, .rex-pause-layer { position: absolute; z-index: 6; inset: 0; display: flex; align-items: center; justify-content: center; overflow-y: auto; padding: 90px 20px 60px; background: rgb(41 39 62 / 12%); pointer-events: auto; }
.rex-result-panel, .rex-pause-panel { width: min(100%, 410px); margin-block: auto; padding: 32px 34px 28px; border: 2px solid var(--rex-ink); border-radius: 18px; background: var(--rex-paper); box-shadow: 4px 5px var(--rex-ink); text-align: center; }
.rex-result:not([hidden]) .rex-result-panel { animation: rex-result-enter 200ms ease-out both; }
@keyframes rex-result-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.rex-result-panel .rex-eyebrow { margin-bottom: 12px; color: var(--rex-clay); }
.rex-result h2, .rex-pause-panel h2 { margin: 0; color: var(--rex-ink); font-size: 38px; font-weight: 900; font-style: italic; line-height: 1.08; letter-spacing: -.065em; }
.rex-final-score { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 6px 9px; margin: 22px 0 0; }
.rex-final-score > strong { --rex-score-size: clamp(64px, 8vw, 94px); max-width: 100%; color: var(--rex-ink); font-size: max(20px, calc(var(--rex-score-size) * var(--rex-number-scale, 1))); font-weight: 900; line-height: 1; letter-spacing: -.07em; overflow-wrap: anywhere; }
.rex-final-score > span { color: var(--rex-muted); font-family: var(--rex-font-mono); font-size: 12px; }
.rex-result-best { margin: 14px 0 28px; color: var(--rex-muted); font-family: var(--rex-font-mono); font-size: 12px; overflow-wrap: anywhere; }
.rex-result-best > strong { margin-left: 7px; color: var(--rex-sage); font-family: var(--rex-font-sans); font-weight: 750; }
.rex-result .rex-primary { width: 100%; }
.rex-retry-hint { margin: 16px 0 0; color: var(--rex-muted); font-family: var(--rex-font-mono); font-size: 10px; }
.rex-pause-panel { padding-block: 36px; }
.rex-pause-panel .rex-primary { margin-top: 28px; }
.rex-pause-panel > p:not(.rex-eyebrow) { margin: 16px 0 0; color: var(--rex-muted); font-size: 14px; line-height: 1.6; }
.rex-guidance { position: absolute; z-index: 3; right: 30px; bottom: max(23px, env(safe-area-inset-bottom)); left: 30px; color: var(--rex-paper); text-align: center; pointer-events: none; text-shadow: var(--rex-scene-shadow); }
.rex-guidance p { margin: 0; font-family: var(--rex-font-mono); font-size: 11px; line-height: 1.6; }
.rex-guidance kbd { display: inline-block; min-width: 22px; margin-inline: 2px; padding: 2px 6px; border: 1px solid #29273e55; border-radius: 5px; background: var(--rex-paper); color: var(--rex-ink); text-shadow: none; font: inherit; font-size: 10px; }
.rex-guidance p > span { padding-inline: 7px; opacity: .5; }
.rex-touch-help { display: none; }
.rex-source { position: absolute; right: 0; bottom: 3px; min-height: 24px; padding-block: 5px; color: var(--rex-paper); font-family: var(--rex-font-mono); font-size: 9px; text-decoration-color: #fff8e999; text-underline-offset: 3px; pointer-events: auto; }
.rex-touch-controls { position: absolute; z-index: 3; right: max(22px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); left: max(22px, env(safe-area-inset-left)); display: none; justify-content: space-between; pointer-events: none; }
.rex-touch-button { display: inline-flex; align-items: center; justify-content: center; gap: 16px; min-width: 110px; min-height: 56px; padding: 13px 20px; border: 2px solid var(--rex-ink); border-radius: 9px; background: #fff8e9eb; color: var(--rex-ink); box-shadow: 0 3px 0 var(--rex-ink); font-size: 15px; font-weight: 750; touch-action: none; -webkit-user-select: none; user-select: none; pointer-events: auto; }
.rex-touch-button > span { font-size: 23px; font-weight: 500; line-height: 1; }
.rex-touch-button[aria-pressed="true"] { border-color: var(--rex-ink); background: var(--rex-coral); color: var(--rex-ink); box-shadow: 0 1px 0 var(--rex-ink); }
.rex-sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; white-space: nowrap; }
.rex-interface[data-phase="starting"] .rex-intro, .rex-interface[data-phase="playing"] .rex-intro, .rex-interface[data-phase="crashing"] .rex-intro, .rex-interface[data-phase="paused"] .rex-intro, .rex-interface[data-phase="over"] .rex-intro, .rex-interface[data-phase="error"] .rex-intro { display: none; }
.rex-interface[data-phase="crashing"] .rex-settings, .rex-interface[data-phase="crashing"] .rex-guidance, .rex-interface[data-phase="over"] .rex-guidance p, .rex-interface[data-phase="paused"] .rex-guidance p, .rex-interface[data-phase="error"] .rex-guidance p { visibility: hidden; }

@media (max-width: 680px) {
  .rex-header { gap: 12px; padding: max(20px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) 0 max(22px, env(safe-area-inset-left)); }
  .rex-hud { gap: 26px; margin-top: 2px; }
  .rex-hud > div { min-width: 64px; }
  .rex-hud dd { font-size: 32px; }
  .rex-hud .rex-best-score dd { font-size: 24px; }
  .rex-settings { gap: 6px; }
  .rex-tool { padding-inline: 11px; font-size: 10px; }
  .rex-pause { width: 44px; padding-inline: 0; }
  .rex-pause > span:last-child { display: none; }
  .rex-intro { padding-top: max(90px, calc(env(safe-area-inset-top) + 76px)); }
  .rex-intro h1 { font-size: 56px; }
  .rex-tagline { margin-block: 12px 20px; font-size: 16px; }
  .rex-source { position: static; display: inline-block; margin-top: 10px; }
  .rex-guidance { bottom: max(16px, env(safe-area-inset-bottom)); }
  .rex-result-panel { padding: 30px 28px 24px; border-radius: 18px; }
}

@media (max-width: 480px) {
  .rex-header { grid-template-columns: 1fr 1fr; padding-inline: max(18px, env(safe-area-inset-left)) max(18px, env(safe-area-inset-right)); }
  .rex-settings { grid-column: 2; }
  .rex-hud { position: absolute; grid-column: 1 / -1; top: max(85px, calc(env(safe-area-inset-top) + 66px)); left: 50%; width: max-content; gap: 34px; transform: translateX(-50%); }
  .rex-hud dd { font-size: 32px; }
  .rex-hud dt { font-size: 9px; }
  .rex-intro { padding-top: max(84px, calc(env(safe-area-inset-top) + 72px)); }
  .rex-intro h1 { font-size: clamp(48px, 14vw, 58px); }
  .rex-eyebrow { font-size: 9px; letter-spacing: .12em; }
  .rex-tagline { font-size: 15px; }
  .rex-primary { min-height: 53px; min-width: 176px; font-size: 15px; }
  .rex-result, .rex-pause-layer { padding: 90px 18px 52px; }
  .rex-result-panel, .rex-pause-panel { padding-inline: 24px; }
  .rex-result h2, .rex-pause-panel h2 { font-size: 34px; }
  .rex-final-score > strong { --rex-score-size: 80px; }
}

@media (pointer: coarse) {
  .rex-desktop-help { display: none; }
  .rex-touch-help { display: block; }
  .rex-touch-controls:not([hidden]) { display: flex; }
  .rex-interface[data-phase="playing"] .rex-guidance { bottom: max(96px, calc(env(safe-area-inset-bottom) + 74px)); }
  .rex-interface[data-phase="playing"] .rex-source { display: none; }
}

@media (max-height: 650px) {
  .rex-intro { padding-top: max(82px, calc(env(safe-area-inset-top) + 72px)); }
  .rex-intro h1 { font-size: 54px; }
  .rex-eyebrow { margin-bottom: 10px; }
  .rex-tagline { margin-block: 12px 20px; font-size: 15px; }
  .rex-result-panel, .rex-pause-panel { padding-block: 24px; }
  .rex-final-score { margin-top: 15px; }
  .rex-final-score > strong { --rex-score-size: 66px; }
  .rex-result-best { margin-block: 11px 21px; }
  .rex-retry-hint { margin-top: 12px; }
}

@media (max-height: 450px) {
  .rex-header { padding-top: max(12px, env(safe-area-inset-top)); }
  .rex-intro { padding-top: max(72px, calc(env(safe-area-inset-top) + 60px)); }
  .rex-eyebrow { margin-bottom: 8px; font-size: 8px; }
  .rex-intro h1 { font-size: 47px; }
  .rex-tagline { margin-block: 10px 15px; font-size: 13px; }
  .rex-primary { min-height: 46px; padding-block: 11px; font-size: 14px; }
  .rex-ready-best { margin-top: 12px; }
  .rex-hud { top: 65px; }
  .rex-hud dd { font-size: 30px; }
  .rex-result, .rex-pause-layer { padding-block: 64px 20px; }
  .rex-result-panel, .rex-pause-panel { width: min(100%, 390px); padding: 18px 24px; }
  .rex-result h2, .rex-pause-panel h2 { font-size: 28px; }
  .rex-final-score { margin-top: 10px; }
  .rex-final-score > strong { --rex-score-size: 47px; }
  .rex-result-best { margin-block: 8px 14px; }
  .rex-retry-hint { display: none; }
  .rex-guidance { bottom: max(10px, env(safe-area-inset-bottom)); }
  .rex-touch-button { min-height: 52px; min-width: 108px; }
  .rex-touch-controls { bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .rex-tool, .rex-primary, .rex-loading-bar > span { transition: none; }
  .rex-result:not([hidden]) .rex-result-panel { animation: none; }
}

/* Keep the title in the sky and the action below Rex on short phones. */
@media (max-width: 480px) and (min-height: 451px) and (max-height: 650px) {
  .rex-intro h1 { font-size: 48px; }
  .rex-intro > .rex-eyebrow { margin-bottom: 8px; }
  .rex-tagline { margin-block: 10px 14px; }
}

/* The landscape skyline fills the top half. Place the menu in the open
   foreground opposite Rex instead of across the cliffs and river arch. */
@media (min-aspect-ratio: 5 / 4) {
  .rex-intro { inset: auto max(40px, 5vw) max(88px, calc(env(safe-area-inset-bottom) + 66px)) auto; width: clamp(260px, 27vw, 350px); padding: 0; align-items: flex-start; text-align: left; }
  .rex-intro h1 { font-size: clamp(44px, 4.8vw, 68px); }
  .rex-intro > .rex-eyebrow { margin-bottom: 10px; }
  .rex-intro .rex-tagline { margin-block: 14px 22px; }
  .rex-intro > .rex-primary { margin-top: 0; }
  .rex-intro .rex-loading { margin: 0; justify-content: flex-start; }
}

@media (min-aspect-ratio: 5 / 4) and (max-height: 450px) {
  .rex-intro { right: max(28px, env(safe-area-inset-right)); bottom: max(60px, calc(env(safe-area-inset-bottom) + 42px)); width: clamp(244px, 32vw, 300px); }
  .rex-intro h1 { font-size: 42px; }
  .rex-intro > .rex-eyebrow { margin-bottom: 7px; }
  .rex-intro .rex-tagline { margin-block: 10px 15px; }
  .rex-intro .rex-ready-best { margin-top: 10px; }
}
