* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f7f7f7; color: #535353; font: 15px/1.6 system-ui, sans-serif; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }
#offline { position: fixed; left: 20%; top: 32%; width: min(480px, 76vw); pointer-events: none; transform-origin: left bottom; }
#offline h1 { margin: 0 0 14px; font-size: 24px; font-weight: 500; color: #202124; }
#offline p { margin: 2px 0; }
#offline .code { margin-top: 22px; color: #777; font: 11px ui-monospace, monospace; letter-spacing: .04em; }
#bar { position: fixed; top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); display: flex; gap: 6px; z-index: 12; }
#bar button { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid #8884; border-radius: 8px; color: #666; background: #ffffff18; font: 20px system-ui, sans-serif; text-decoration: none; cursor: pointer; }
html[data-spatial="true"] #bar button { color: #e8eeff; background: #080b2080; }
#bar #bank { width: auto; padding: 0 10px; font-size: 12px; }
#bar #bank:disabled { opacity: .38; cursor: default; }
#bar button.off { opacity: .5; text-decoration: line-through; }
button:focus-visible, a:focus-visible { outline: 2px solid #2bb9c9; outline-offset: 3px; }
#chapter { position: fixed; left: 20px; bottom: max(22px, env(safe-area-inset-bottom)); color: #c6d5ec; pointer-events: none; font: 10px ui-monospace, monospace; letter-spacing: .24em; }
@media (max-width: 600px) { #offline { left: 10%; top: 34%; width: 82%; } #offline h1 { font-size: 22px; } #offline p { font-size: 13px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; } }

html[data-scene="dream"] #bar button, html[data-scene="desktop"] #bar button, html[data-scene="stampede"] #bar button { color: #243040; background: #ffffff60; }
html[data-scene="dream"] #chapter, html[data-scene="desktop"] #chapter, html[data-scene="stampede"] #chapter { color: #33445e; }
/* Standalone end card (score, best, play again, share). */
#end { position: fixed; z-index: 20; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); width: min(680px, calc(100% - 24px)); transform: translateX(-50%); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border: 1px solid #d9dfe2; border-radius: 8px; background: #fffffff5; color: #39414a; box-shadow: 0 4px 25px #0001; font: 13px/1.4 system-ui, sans-serif; }
#end[hidden] { display: none; }
#end .end-info { display: flex; flex-direction: column; gap: 2px; }
#end .end-title { color: #67717a; font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
#end .end-scores { font-size: 12px; color: #59616a; }
#end .end-scores strong { font-size: 16px; color: #202a34; }
#end .end-new { color: #9a5b12; font-weight: 600; }
#end .end-actions { display: flex; gap: 6px; align-items: center; }
#end button { padding: 8px 11px; border: 0; border-radius: 4px; color: #384b52; background: #e8efee; font: 12px system-ui, sans-serif; cursor: pointer; }
#end .end-again { color: #fff; background: #355d62; }
#end .end-close { padding: 4px 9px; border: 1px solid #bbc5ca; background: transparent; color: #56626b; font-size: 16px; }
@media (max-width: 600px) { #end { flex-direction: column; align-items: stretch; gap: 10px; } #end .end-actions { justify-content: flex-end; } }

/* A steady, high-contrast recovery cue, separate from the timing corridor. */
#health { position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 44px); left: max(12px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 9px; padding: 2px 8px; border: 1px solid #8884; border-radius: 6px; background: #fffffff0; color: #75424a; pointer-events: none; }
#health .hearts { font: 22px/1.3 system-ui, sans-serif; letter-spacing: 3px; }
#health .health-cue { font: 9px ui-monospace, monospace; letter-spacing: .04em; }
#health[data-recovering="true"] { border-color: #a76135; color: #85451e; background: #fff1db; }
html[data-scene="desktop"] #health { top: calc(max(12px, env(safe-area-inset-top)) + 80px); }

/* Art-medium contrast is independent of camera/spatial state and lap variants. */
html:is([data-medium="ink-comic"], [data-medium="cel-cartoon"], [data-medium="ai-gouache"], [data-medium="gouache-fallback"], [data-medium="pixel-16"]) #bar button { color: #302b3a; background: #fff8e8e8; border-color: #302b3a55; }
html:is([data-medium="ink-comic"], [data-medium="cel-cartoon"], [data-medium="ai-gouache"], [data-medium="gouache-fallback"], [data-medium="pixel-8"]) #chapter { color: #302b3a; background: #fff8e8d9; padding: 2px 5px; border-radius: 2px; }
html[data-medium="pixel-16"] #chapter { color: #fff3d0; background: #253d72; padding: 2px 5px; }

/* Medium changes tint the existing controls, never duplicate their text. */
#bar button, #chapter, #health { transition: color .55s ease, background-color .55s ease, border-color .55s ease; }
#health { transition: top .55s ease, color .55s ease, background-color .55s ease, border-color .55s ease, opacity .6s ease, visibility 0s; }
#bar { transition: opacity .6s ease; }
#chapter { transition: color .55s ease, background-color .55s ease, opacity .6s ease, visibility 0s; }
@media (prefers-reduced-motion: reduce) {
  #bar button, #chapter, #health, #bar { transition-duration: .2s; }
}

/* Chrome's offline opening. Layout adapted from Chromium net_error.css and
   interstitial_common.css; runner box from Chromium's offline runner CSS.
   See THIRD_PARTY_NOTICES.md. The page's own runner is the first phase. */
#chrome-opening { color-scheme: light dark; position: fixed; inset: 0; z-index: 10; overflow: auto; pointer-events: none; background: #fff; color: #5f6368; font: 15px/1.55 "sans", Arial, sans-serif; -webkit-text-size-adjust: 100%; }
#chrome-opening[hidden] { display: none; }
#chrome-opening .chrome-body { margin: 8px; }
#chrome-opening .chrome-wrapper { position: relative; box-sizing: border-box; width: 100%; max-width: 600px; margin: 0 auto; padding-top: 100px; }
#chrome-opening .chrome-icon { position: relative; display: inline-block; width: 72px; height: 72px; margin: 0 0 40px; visibility: hidden; }
#chrome-opening h1 { color: #202124; font-size: 1.6em; font-weight: normal; line-height: 1.25em; margin: 0 0 16px; overflow-wrap: break-word; }
#chrome-opening h1 span { font-weight: 500; }
#chrome-opening p { margin: 1em 0 0; }
#chrome-opening ul { margin: 0 0 1em; padding-left: 40px; }
#chrome-opening .chrome-code { font-size: .8em; margin-top: 12px; text-transform: uppercase; }
#chrome-opening .chrome-runner { position: absolute; top: 35px; width: 44px; height: 150px; max-width: 600px; overflow: hidden; direction: ltr; }
#chrome-opening .chrome-dino { position: absolute; top: 0; left: 0; width: 44px; height: 150px; image-rendering: pixelated; }
#chrome-opening .chrome-runner canvas { position: absolute; top: 0; left: 0; height: 150px; }
#chrome-opening .chrome-runner [hidden] { display: none; }
/* Until lap one's transformation is underway, only the page exists. */
html[data-phase="opening"] #game { opacity: 0; }
html[data-phase="handoff"] #chrome-opening { background: transparent; }
html:not([data-revealed="true"]) #offline { visibility: hidden; }
/* Hearts and chapter fade in with the controls; hidden from assistive tech until then. */
html:not([data-revealed="true"]) :is(#health, #chapter) { opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility 0s linear .2s; }
html:not([data-revealed="true"]) #bar { opacity: 0; pointer-events: none; }
html:not([data-revealed="true"]) #bar:focus-within { opacity: 1; pointer-events: auto; }
@media (max-width: 640px), (max-height: 640px) { #chrome-opening h1 { margin-bottom: 15px; } }
@media (max-width: 700px) { #chrome-opening .chrome-wrapper { padding-left: 10%; padding-right: 10%; } }
@media (max-width: 420px) { #chrome-opening .chrome-wrapper { padding-left: 5%; padding-right: 5%; } }
@media (max-width: 420px) and (orientation: portrait), (max-height: 560px) {
  #chrome-opening .chrome-body { margin: 0 auto; }
  #chrome-opening .chrome-wrapper { padding-left: 24px; padding-right: 24px; }
  #chrome-opening h1 { font-size: 1.5em; margin-bottom: 15px; }
  #chrome-opening .chrome-icon { margin-bottom: 5.69vh; }
  #chrome-opening p { font-size: .95em; line-height: 1.61em; margin-top: 8px; }
}
@media (max-width: 360px) and (max-height: 480px) {
  #chrome-opening .chrome-wrapper { padding-top: 60px; }
  #chrome-opening .chrome-runner { top: 8px; }
}
@media (min-height: 240px) and (orientation: landscape) { #chrome-opening .chrome-icon { margin-bottom: 20px; } }
@media (max-height: 320px) and (orientation: landscape) {
  #chrome-opening .chrome-icon { margin-bottom: 0; }
  #chrome-opening .chrome-runner { top: 10px; }
}
@media (prefers-color-scheme: dark) {
  #chrome-opening { background: #202124; color: #9aa0a6; }
  #chrome-opening h1 { color: #9aa0a6; }
  #chrome-opening :is(.chrome-dino, .chrome-runner canvas) { filter: invert(1); }
  #chrome-opening .chrome-body { background: transparent; }
}

/* Chromium retains this empty fixed navigation strip and its background shadow. */
@media (min-width: 240px) and (max-width: 420px) and (min-height: 401px),
       (min-width: 421px) and (min-height: 240px) and (max-height: 560px) {
  #chrome-opening .chrome-footer { position: fixed; bottom: 0; left: 0; right: 0; z-index: 2; margin: 0 auto; width: 100%; max-width: 736px; height: 16px; background: #fff; box-shadow: 0 -12px 24px #fff; }
}
@media (prefers-color-scheme: dark) { #chrome-opening .chrome-footer { background: #202124; box-shadow: 0 -12px 24px #202124; } }
