:root {
  color-scheme: light;
  --paper: #e9e9e2;
  --ink: #141735;
  --blue: #172984;
  --sulfur: #fff17a;
  --white: #f7f6ec;
  --edge: clamp(12px, 2.85vw, 56px);
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font: 16px/1.5 system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-underline-offset: 0.22em; }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid #374fc9; outline-offset: 4px; }
#game :focus-visible { outline-color: #fff; outline-offset: 3px; }
#game:focus { outline: none; }

.masthead, main, .footer { width: min(100%, 1720px); margin-inline: auto; }
.masthead {
  display: flex;
  min-height: 84px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(var(--edge), env(safe-area-inset-right)) 10px max(var(--edge), env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: clamp(8px, 1.15vw, 18px); }
.brand img { display: block; width: clamp(32px, 3.5vw, 46px); height: auto; border-radius: 2px; }
.brand h1, .brand > span {
  margin: 0;
  font-size: clamp(1.47rem, 3.45vw, 3.45rem);
  line-height: 0.93;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: -0.07em;
}
.help { display: grid; min-height: 44px; align-items: center; flex: none; font-weight: 720; font-size: 0.94rem; }
main { padding-inline: max(var(--edge), env(safe-area-inset-left)) max(var(--edge), env(safe-area-inset-right)); }

#game {
  --flight-footer: 49px;
  color-scheme: dark;
  color: var(--white);
  position: relative;
  isolation: isolate;
  height: 83dvh;
  min-height: 260px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: #16246e linear-gradient(125deg, #121b4a, #273aa4);
  border: 1px solid #131f63;
  border-radius: 4px;
}
#game canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; visibility: hidden; }
#game canvas[data-ready] { visibility: visible; }
.cover { position: absolute; inset: 0; display: grid; align-items: center; pointer-events: none; }
.cover::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, #0d153af4, #10183bdf 21%, #111a3d8c 45%, transparent 66%); }
.cover-inner { position: relative; width: min(67%, 640px); padding: 18px 0 18px clamp(22px, 5.2vw, 86px); }
.panel-tag { color: var(--sulfur); font: 700 0.9rem/1.2 var(--mono); margin: 0 0 14px; }
.cover h2 {
  margin: 0;
  font-size: clamp(3rem, 8.3vw, 8.3rem);
  font-weight: 950;
  line-height: 0.84;
  letter-spacing: -0.064em;
  text-wrap: balance;
}
.summary { max-width: 29ch; min-height: 1.5em; margin: 17px 0 25px; color: #e8ebfb; font-weight: 550; font-size: clamp(1rem, 1.37vw, 1.24rem); }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
[data-mode=paused] .actions { margin-top: 16px; }
.actions button, .options button, .review button { pointer-events: auto; }
.primary, .secondary, .tool, .switch {
  border-radius: 3px;
  min-width: 44px;
  min-height: 44px;
  font-weight: 800;
}
.primary { position: relative; padding: 0.66em 1.26em; min-width: 132px; border: 1px solid var(--sulfur); color: #121530; background: var(--sulfur); font-size: 1.17rem; box-shadow: 0 3px 0 #b9a44e; }
.primary:hover { background: #fff7aa; border-color: #fff7aa; }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #b9a44e; }
.secondary, .tool, .switch { padding: 0 12px; color: var(--white); border: 1px solid #94a5f18e; background: #111a45; }
.secondary:hover, .tool:hover, .switch:hover { background: #283b8a; }
.tool { display: grid; place-items: center; width: 46px; height: 46px; padding: 0; }
.tool svg { width: 23px; height: 23px; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.sound[aria-pressed=false]::after { content: ""; position: absolute; height: 2px; width: 24px; transform: rotate(-45deg); background: #f9ed84; }
.options { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 21px; }
.switch { font-size: 0.9rem; }
.switch::before { content: ""; display: inline-block; vertical-align: 0.03em; margin-right: 7px; height: 8px; width: 8px; border: 1px solid #aeb8db; transform: rotate(45deg); }
.switch[aria-pressed=true]::before { border-color: var(--sulfur); background: var(--sulfur); }
.switch:disabled { color: #b7c1e9; cursor: default; }
.switch:disabled::before { background: transparent; border-color: #b7c1e9; }
.hud { position: absolute; top: clamp(10px, 2.2vw, 28px); left: clamp(10px, 2.3vw, 33px); right: clamp(10px, 2.3vw, 33px); display: flex; gap: clamp(8px, 1.5vw, 22px); align-items: start; pointer-events: none; }
.readout { min-width: 83px; background: #0e1947ed; padding: 5px 10px 6px; border: 1px solid #91a1e660; border-radius: 3px; font-family: var(--mono); line-height: 1.2; }
.readout span { display: block; margin-bottom: 3px; font-size: 0.76rem; color: #eff0ff; }
.readout strong { display: block; color: var(--sulfur); font-size: clamp(1.15rem, 2vw, 1.66rem); white-space: nowrap; }
.best-readout strong { color: #edf2ff; }
.readout small { font-size: 0.72em; }
.hud-actions { display: flex; gap: 6px; margin-left: auto; }
.hud-actions button { pointer-events: auto; }
#progress { appearance: none; position: absolute; left: 0; bottom: -7px; width: min(170px, 45%); height: 4px; border: 0; border-radius: 0; color: var(--sulfur); background: #111b53; }
#progress::-webkit-progress-bar { background: #111b53; }
#progress::-webkit-progress-value { background: var(--sulfur); }
#progress::-moz-progress-bar { background: var(--sulfur); }
#guide { position: absolute; inset: auto clamp(12px, 3vw, 36px) 18px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; }
.guide-keys { display: flex; gap: 9px; align-items: center; padding: 5px 12px; background: #0f1948ed; border: 1px solid #8a9ff1a6; border-radius: 3px; color: var(--white); font: 700 0.85rem/1.3 var(--mono); white-space: nowrap; }
.guide-arrow { color: var(--sulfur); font: 800 1.45rem/1 system-ui, sans-serif; }
#status { position: absolute; left: 50%; bottom: 17px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); pointer-events: none; text-align: center; }
#status-text:not(:empty) { display: block; padding: 4px 10px; border: 1px solid #9aabed; border-radius: 3px; background: #111a43; color: var(--white); font: 650 0.84rem/1.35 var(--mono); }
.review { position: absolute; inset: 0; pointer-events: none; padding: clamp(9px, 2.5vw, 25px); display: flex; flex-direction: column; justify-content: space-between; }
.review-title, .review-timeline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.review-title h2 { margin: 0; font-size: clamp(1.05rem, 3vw, 1.55rem); background: #101943; padding: 6px 10px; border: 1px solid #7084d8; }
.review-timeline { align-self: center; width: min(100%, 520px); padding: 7px; background: #0e163df5; border: 1px solid #7084d8; pointer-events: auto; }
.scrub { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 4px; flex: 1; min-width: 0; font: 0.82rem/1.15 var(--mono); }
.scrub input { grid-column: 1 / -1; margin: 0; min-height: 44px; min-width: 0; width: 100%; accent-color: var(--sulfur); }
.review button:disabled { opacity: 0.50; cursor: default; }

.story { width: min(100%, 1010px); margin-inline: auto; padding: clamp(45px, 7vw, 108px) 0 58px; }
#back-to-run { display: inline-flex; min-height: 44px; align-items: center; padding-inline: 12px; margin-bottom: 12px; background: var(--ink); color: var(--white); border-radius: 3px; font-weight: 750; }
.story h2, .legal h1 { font-weight: 920; line-height: 0.99; letter-spacing: -0.055em; font-size: clamp(2.15rem, 4.7vw, 4.8rem); margin: 0 0 0.45em; text-wrap: balance; }
.story-grid h2, .questions h2, .legal h2 { font-weight: 850; line-height: 1.12; letter-spacing: -0.036em; font-size: clamp(1.33rem, 2.7vw, 2.3rem); margin: 0 0 0.57em; }
.story p, .legal p { max-width: 69ch; margin: 0 0 1.03em; color: #292b46; }
.story .intro { font-size: clamp(1.10rem, 2vw, 1.42rem); color: var(--ink); }
.story-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 26px clamp(26px, 6vw, 90px); margin-top: 38px; }
.story-grid > section { border-top: 2px solid #242d66; padding-top: 16px; }
.story-grid > section:last-child { grid-column: 1 / -1; }
.story h2 { overflow-wrap: anywhere; }
.questions { padding-top: 38px; }
.questions details { border-top: 1px solid #9a9daf; }
.questions details:last-child { border-bottom: 1px solid #9a9daf; }
.questions summary { font-weight: 770; padding: 11px 1px; min-height: 44px; cursor: pointer; }
.questions details p { padding-left: 15px; }
.independent { margin-top: 26px !important; font-size: 0.9rem; }
.footer { display: flex; justify-content: space-between; flex-wrap: wrap; align-items: center; gap: 0 20px; padding: 15px max(var(--edge), env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(var(--edge), env(safe-area-inset-left)); border-top: 1px solid #9a9daf; font-size: 0.95rem; }
.footer > span { font-weight: 850; }
.footer nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0 clamp(12px, 3vw, 32px); }
.footer a { display: grid; min-height: 44px; align-items: center; }
.footer .english-pages { width: 100%; font-size: 0.85rem; }
.footer .languages { width: 100%; }
.languages [aria-current=page] { font-weight: 850; text-decoration: none; }
.legal { width: min(100%, 850px); min-height: 64dvh; margin-inline: auto; padding-block: 36px 68px; }
.legal h2 { margin-top: 1.15em; }
.legal .lead { font-size: 1.1rem; }

@media (max-width: 819px) {
  .masthead { min-height: 64px; }
  #game { height: 84dvh; }
  .cover { align-items: end; }
  .cover::before { background: linear-gradient(0deg, #0d153af7, #10183bea 28%, #10183b40 59%, transparent 76%); }
  .cover-inner { width: 100%; padding: 12px clamp(17px, 5.2vw, 40px) clamp(22px, 6.7vh, 60px); }
  .cover h2 { font-size: clamp(3.2rem, 11vw, 5.8rem); }
  .panel-tag { margin-bottom: 10px; }
  .summary { margin: 12px 0 17px; }
  .options { margin-top: 16px; }
}

@media (max-width: 540px) {
  .brand h1, .brand > span { font-size: clamp(1.5rem, 7.5vw, 2.5rem); }
  .brand h1 { font-size: clamp(1.22rem, 6.1vw, 2.1rem); }
  .brand img { flex: none; }
  .help { font-size: 0.82rem; }
  .story-grid { grid-template-columns: 1fr; }
  .cover-inner .primary { min-width: 115px; }
  .options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 360px; }
  .actions button, .options button { max-width: 100%; overflow-wrap: anywhere; }
  html:not([lang=en]) [data-mode]:not([data-mode=menu]) .cover h2 {
    font-size: clamp(2.4rem, 10.1vw, 4.65rem);
    overflow-wrap: anywhere;
  }
  #game { --flight-footer: 77px; }
  #status { bottom: 57px; }
}

@media (max-width: 350px) {
  .brand { gap: 6px; }
  .brand h1, .brand > span { font-size: 1.4rem; }
  .brand img { width: 28px; }
  .actions { gap: 6px; }
  .primary, .secondary { padding-inline: 9px; }
}

@media (max-height: 510px) and (orientation: landscape) {
  .masthead { min-height: 50px; padding-block: 3px; }
  .brand img { width: 32px; }
  .brand h1, .brand > span { font-size: 1.85rem; }
  #game { height: 82dvh; min-height: 205px; }
  .cover { align-items: center; }
  .cover::before { background: linear-gradient(90deg, #0d153af4, #10183bd6 35%, transparent 74%); }
  .cover-inner { width: min(76%, 540px); padding: 10px 0 10px 22px; }
  .cover h2 { font-size: clamp(2.45rem, 13vh, 4.4rem); }
  .panel-tag { margin-bottom: 7px; }
  .summary { margin: 8px 0 11px; }
  .primary { padding-block: 5px; }
  .options { margin-top: 10px; gap: 5px; }
  #guide { bottom: 9px; }
  #status { bottom: 10px; }
  #game { --flight-footer: 42px; }
}

@media (max-width: 520px) and (max-height: 510px) and (orientation: landscape) {
  #game { --flight-footer: 67px; }
  #status { bottom: 46px; }
}

@media (max-height: 320px) and (orientation: landscape) {
  [data-mode=paused] .cover-inner {
    display: grid;
    align-items: center;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 12px;
    width: 100%;
    padding: 10px clamp(12px, 3vw, 24px);
  }
  [data-mode=paused] .cover h2 { font-size: clamp(1.75rem, 6vw, 2.4rem); }
  [data-mode=paused] .actions { grid-column: 2; grid-row: 1 / 3; margin-top: 0; }
  [data-mode=paused] .options {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(100%, 560px);
    max-width: none;
  }
}
