:root {
  color-scheme: dark;
  font: 16px/1.5 system-ui, sans-serif;
  color: #e4edeb;
  background: #101f29;
  --page: #101f29;
  --ink: #173344;
  --paper: #f9f4e3;
  --yellow: #ffda57;
  --rule: #54717c;
  --edge: clamp(12px, 4vw, 62px);
  --ridge: polygon(0 26%, 4% 72%, 9% 48%, 14% 94%, 23% 44%, 30% 54%, 36% 12%, 41% 44%, 48% 24%, 53% 73%, 59% 43%, 67% 91%, 75% 36%, 80% 47%, 86% 13%, 93% 63%, 100% 20%, 100% 100%, 0 100%);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; }
a { color: #cde2df; text-underline-offset: .23em; }
a:hover { color: var(--yellow); }
a:focus-visible, button:focus-visible, #game:focus-visible { outline: 3px solid #ffb242; outline-offset: 3px; }
#game:focus-visible { outline-offset: -3px; }

.top {
  min-height: calc(64px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--edge), env(safe-area-inset-right)) 0 max(var(--edge), env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(58px, 1fr) minmax(0, 3fr) minmax(58px, 1fr);
  align-items: center;
  gap: clamp(8px, 3vw, 34px);
  border-bottom: 2px solid #688792;
}
.top h1, .top .home {
  margin: 0; color: var(--paper); text-align: center;
  font-size: clamp(1.23rem, 3.4vw, 2rem); font-weight: 900; line-height: 1.03; letter-spacing: -.06em;
  text-wrap: balance; overflow-wrap: anywhere;
}
.top a { display: flex; align-items: center; min-height: 44px; font-size: .9rem; font-weight: 750; line-height: 1.15; overflow-wrap: anywhere; }
.top > :first-child { justify-self: start; }
.top > :last-child { justify-self: end; text-align: right; }
.top .home { justify-content: center; text-decoration: none; }
.top .home:hover { color: var(--yellow); }

#game {
  position: relative; width: 100%; height: min(84vh, 862px); height: min(84dvh, 862px); min-height: 290px;
  overflow: hidden; isolation: isolate; background: #a9ccdb;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  --game-top: 0px;
}
#game::after {
  content: ''; position: absolute; inset: auto 0 -1px; height: 17px;
  background: var(--page); clip-path: var(--ridge); pointer-events: none; z-index: 1;
}
canvas { width: 100%; height: 100%; display: block; }
#game:is(:fullscreen, .is-fullscreen-fallback) {
  margin: 0; width: 100%; height: 100%; height: 100dvh;
  min-height: 0; max-width: none; max-height: none;
  --game-top: env(safe-area-inset-top);
}
#game:is(:fullscreen, .is-fullscreen-fallback)::after { display: none; }
#game.is-fullscreen-fallback { position: fixed; inset: 0; z-index: 10; }
html.has-game-fullscreen, html.has-game-fullscreen body { overflow: hidden; overscroll-behavior: none; }
html.has-game-fullscreen body { position: fixed; top: var(--page-offset); inset-inline: 0; }
html.has-game-fullscreen :is(.top, .field-edge, .copy, .foot) { visibility: hidden; }

.hud, .overlay, .controller, .hint, .keyboard-guide { position: absolute; }
.hud {
  inset: calc(var(--game-top) + 12px) max(12px, env(safe-area-inset-right)) auto max(12px, env(safe-area-inset-left));
  display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; z-index: 4; pointer-events: none;
}
.hud button { pointer-events: auto; }
.readout, .tools { display: flex; align-items: center; gap: 5px; }
.tools { margin-inline-start: auto; }
.readout {
  min-height: 44px; gap: 13px; padding: 5px 12px; background: var(--ink); color: var(--paper);
  border: 1px solid #658694; border-radius: 4px; font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 0 #143b4957; font-size: .92rem;
}
#sector { font-weight: 800; }
#timer, #score { white-space: nowrap; }
#timer { font-family: ui-monospace, 'Courier New', monospace; font-weight: 800; }
#score { color: var(--yellow); font-weight: 750; }

button {
  font: inherit; min-height: 44px; min-width: 44px; border: 1px solid transparent; border-radius: 4px;
  padding: 7px 13px; color: var(--paper); background: var(--ink); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:hover { filter: brightness(1.12); }
button:active { transform: translateY(1px); }
.icon-button { padding: 9px; border-color: #638491; box-shadow: 0 2px 0 #143b4957; }
.icon-button svg {
  display: block; width: 24px; height: 24px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.icon-button .mute, .icon-button[aria-pressed=false] .waves,
.icon-button .contract, .icon-button[aria-pressed=true] .expand { display: none; }
.icon-button[aria-pressed=false] .mute, .icon-button[aria-pressed=true] .contract { display: block; }

.overlay {
  inset: 0; display: grid; place-items: center;
  padding: calc(var(--game-top) + 66px) max(14px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  pointer-events: none; z-index: 2;
}
.board { position: relative; pointer-events: auto; max-width: 100%; min-width: 0; }
.board h2 { margin: 0; font-size: clamp(1.9rem, 4.1vw, 3.6rem); font-weight: 900; line-height: 1; letter-spacing: -.055em; }
.board p { margin: 8px 0 14px; }
.board .best { color: #b7ddd9; font-size: .9rem; font-weight: 700; }
.primary {
  min-height: 50px; min-width: 108px; padding: 7px 20px; background: var(--yellow); color: #142a37;
  font-weight: 850; border-color: #ffe77a; box-shadow: 0 3px 0 #af7c2d;
}
.primary:active { box-shadow: 0 1px 0 #af7c2d; transform: translateY(2px); }
.secondary { background: #2b5060; border-color: #7d999d; font-weight: 750; }
.run-actions, .actions, .preferences { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

#menu { align-items: start; padding-top: max(calc(var(--game-top) + 65px), 20dvh); }
.welcome {
  color: #142f3e; display: grid; justify-items: center; text-align: center;
  padding-inline: 4px;
}
.welcome h2 {
  font: 950 clamp(3.35rem, 12.5vw, 9.5rem)/.84 system-ui, sans-serif;
  letter-spacing: -.095em; padding-inline-end: .09em;
  text-shadow: 0 2px #e6f4eb9c;
}
.welcome h2 span { color: #254f60; }
.welcome p { font-weight: 800; margin: 12px 0 16px; }
.welcome .run-actions { justify-content: center; }
.welcome .best { color: #142f3e; margin-bottom: 0; }
.welcome .primary { min-width: clamp(126px, 15vw, 196px); }

.pause-board, .result-board, .layout-board {
  width: min(100%, 740px); padding: clamp(17px, 2.5vw, 30px);
  background: #112a38; color: var(--paper);
  border-top: 4px solid var(--yellow); border-bottom: 2px solid #658694;
  box-shadow: 0 8px 0 #0d233393;
}
.pause-board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 24px; }
.pause-main .actions { margin-top: 14px; }
.preferences { align-content: center; padding-inline-start: 18px; border-left: 1px solid var(--rule); }
.preferences button { padding: 5px 9px; border-color: #64828b; font-size: .9rem; }
.preferences button[aria-pressed=true] { color: #1a3641; background: #c1e0d9; font-weight: 750; }
.touch-option { display: none; }
@media (pointer: coarse) { .touch-option { display: inline-block; } }
.layout-board { width: min(100%, 420px); }
.layout-board p { margin-top: 0; }
#control-layout { padding-bottom: max(115px, env(safe-area-inset-bottom)); }

.result-board {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 13px 22px;
}
.result-board:has(#result-timing[hidden]) { width: min(100%, 460px); grid-template-columns: 1fr; }
.result-summary { align-self: center; }
.result-board > .run-actions { grid-column: 1 / -1; }
.result-board p { font-variant-numeric: tabular-nums; }
.result-board #result-detail { margin: 9px 0 0; }
.result-board #result-best { margin: 5px 0 0; }
.result-board #result-splits-label { margin: 0 0 4px; color: #b7ddd9; font-size: .88rem; font-weight: 700; }
#result-splits { margin: 0; padding: 0; list-style: none; font-size: .88rem; font-variant-numeric: tabular-nums; }
#result-splits li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(58px, auto);
  gap: 7px; padding-block: 4px; border-top: 1px solid #6d8789;
}
#result-splits li span:last-child { color: #e5eee7; text-align: right; }
#result-splits .faster span:last-child { color: var(--yellow); }

.controller {
  inset: auto max(12px, env(safe-area-inset-right)) max(15px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex; justify-content: space-between; pointer-events: none; z-index: 3;
}
.control-bank {
  position: relative; display: flex; gap: 5px;
  transform: translate(var(--move-x, 0px), var(--move-y, 0px));
}
.controller.mirrored { flex-direction: row-reverse; }
.controller.large { --control-size: clamp(44px, calc((100vw - 54px - env(safe-area-inset-left) - env(safe-area-inset-right)) / 4), 64px); }
.control-bank button {
  pointer-events: auto; display: grid; place-items: center; width: var(--control-size, 52px); height: var(--control-size, 52px);
  padding: 0; font-size: 1.65rem; font-weight: 900; line-height: 1; background: #122a39; color: #fdf6df;
  border: 1px solid #7899a4; box-shadow: 0 3px 0 #10232e;
}
.techniques button { color: var(--yellow); border-color: #b7a56c; }
.control-bank button.active { background: var(--yellow); color: var(--ink); border-color: var(--yellow); }
.controller.editing [data-control] { pointer-events: none; opacity: .8; }
.control-bank .move-handle {
  position: absolute; inset: 0; width: 100%; height: 100%; font-size: 1.35rem; background: #122a39ad;
  color: var(--yellow); border: 2px dashed var(--yellow); cursor: grab; transform: none;
}
.control-bank .move-handle:active { cursor: grabbing; }

.hint {
  left: 50%; top: calc(var(--game-top) + 69px); transform: translateX(-50%); width: max-content;
  max-width: min(calc(100% - 24px), 660px); padding: 6px 11px; border-left: 4px solid var(--yellow);
  background: var(--ink); color: var(--paper); pointer-events: none; text-align: center; z-index: 2;
  font-size: .92rem;
}
.keyboard-guide {
  inset: auto auto max(15px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  color: #e7f2ef; font-size: .875rem; display: flex; flex-wrap: wrap; gap: 6px 12px; max-width: calc(100% - 24px);
  pointer-events: none; padding: 5px 8px; background: #193444; border-radius: 3px; z-index: 2;
}
.keyboard-guide kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 19px; margin-right: 3px;
  background: #152e3b; border: 1px solid #70929b; border-radius: 3px; color: #fff3cc; font: inherit;
}

.field-edge {
  display: flex; justify-content: flex-end; align-items: center; min-height: 44px;
  margin-inline: max(var(--edge), env(safe-area-inset-left)) max(var(--edge), env(safe-area-inset-right));
  border-bottom: 1px solid var(--rule);
}
.field-edge::before {
  content: ''; flex: 1; margin-right: 12px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--rule));
}
.language-nav { display: flex; justify-content: space-between; }
.language-nav a {
  display: grid; place-items: center; min-width: 44px; min-height: 44px;
  font: 750 .875rem ui-monospace, monospace; text-decoration: none;
}
.language-nav a[aria-current="page"] { color: var(--yellow); box-shadow: inset 0 -3px var(--yellow); font-weight: 900; }

.copy { width: min(calc(100% - 2 * var(--edge)), 850px); margin: clamp(34px, 7vw, 92px) auto; line-height: 1.7; }
.copy h2 { margin: 0 0 .45em; font-size: clamp(1.55rem, 5vw, 2.6rem); line-height: 1.08; letter-spacing: -.055em; }
.copy h3 { font-size: 1.1rem; margin-bottom: .28em; }
.copy p { margin: .55em 0 1em; }
.copy .lead { font-size: clamp(1.13rem, 3.1vw, 1.48rem); font-weight: 700; color: var(--paper); }
.copy ul { padding-inline-start: 1.4em; }
.copy ul li { margin-bottom: .65em; }
.copy dt { font-weight: 800; margin-top: 13px; }
.copy dd { margin: 3px 0 0; }
.guide-chapters { padding: 0; margin: 2.1rem 0 0; list-style: none; }
.guide-chapter {
  position: relative; border-top: 1px solid var(--rule);
  padding: clamp(20px, 4vw, 34px) 0 clamp(22px, 4vw, 42px) clamp(47px, 10vw, 105px);
}
.guide-chapter::before {
  content: ''; position: absolute; top: clamp(20px, 4vw, 34px); left: 0;
  width: clamp(28px, 6vw, 58px); aspect-ratio: 1; background: var(--yellow);
  clip-path: polygon(4% 74%, 52% 25%, 28% 25%, 28% 7%, 86% 7%, 86% 65%, 68% 65%, 68% 42%, 19% 91%);
}
.guide-chapter:nth-child(2)::before { clip-path: polygon(1% 70%, 33% 24%, 55% 52%, 71% 21%, 99% 70%, 79% 70%, 70% 50%, 55% 78%, 32% 51%, 20% 70%); }
.guide-chapter:nth-child(3)::before { clip-path: polygon(1% 12%, 98% 12%, 83% 30%, 64% 30%, 64% 65%, 83% 65%, 98% 84%, 1% 84%, 15% 65%, 37% 65%, 37% 30%, 15% 30%); }
.guide-chapter:nth-child(4)::before { clip-path: polygon(50% 2%, 94% 48%, 50% 94%, 6% 48%, 50% 2%, 50% 26%, 30% 48%, 50% 70%, 70% 48%, 50% 26%); }
.guide-chapter:nth-child(5)::before { clip-path: polygon(5% 21%, 50% 3%, 95% 21%, 95% 77%, 50% 95%, 5% 77%, 5% 21%, 27% 32%, 27% 65%, 50% 74%, 73% 65%, 73% 32%, 50% 23%, 27% 32%); }

.foot {
  position: relative; border-top: 1px solid var(--rule);
  padding: 10px max(var(--edge), env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(var(--edge), env(safe-area-inset-left));
  background: #142936;
}
.foot-name {
  font-size: min(20.3vw, 28rem); font-weight: 950; line-height: .96; letter-spacing: -.085em;
  color: var(--paper); text-align: center; white-space: nowrap; padding-inline-end: .085em;
}
.foot nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 2px 22px; margin-top: 10px; }
.foot a { display: flex; align-items: center; min-height: 44px; font-weight: 700; font-size: .94rem; }
.foot a span { margin-inline-start: .35em; font-weight: 400; }

.legal .copy {
  border-top: 4px solid var(--yellow); padding-top: clamp(19px, 4vw, 42px);
}
.legal .copy h1 { margin: 0 0 .4em; font-size: clamp(2.6rem, 8vw, 5.8rem); line-height: .93; letter-spacing: -.065em; }
.legal .guide-chapter { padding-inline-start: clamp(43px, 8vw, 80px); }
.legal .guide-chapter::before { width: clamp(26px, 5vw, 46px); }
.legal .guide-chapter p:last-child { margin-bottom: 0; }
.board button, #result-splits li span { overflow-wrap: anywhere; }

@media (max-width: 650px) {
  .top { min-height: calc(58px + env(safe-area-inset-top)); }
  #game { height: min(82vh, 830px); height: min(82dvh, 830px); }
  #menu { padding-top: max(calc(var(--game-top) + 68px), 17dvh); }
  .welcome h2 { font-size: clamp(2.8rem, 14vw, 5.65rem); }
  .pause-board, .result-board { width: min(100%, 460px); grid-template-columns: 1fr; gap: 13px; }
  .preferences { padding: 12px 0 0; border: 0; border-top: 1px solid var(--rule); }
}
@media (max-width: 450px) {
  .top {
    gap: 7px;
    grid-template-columns: minmax(clamp(58px, 19.5vw, 72px), 1fr) minmax(0, 3fr) minmax(clamp(58px, 19.5vw, 72px), 1fr);
  }
  .hud { inset-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); }
  .readout { display: grid; grid-template-columns: auto auto; column-gap: 8px; row-gap: 0; padding: 3px 7px; line-height: 1.25; }
  #sector { grid-column: span 2; }
  .controller { inset-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); }
}
@media (orientation: landscape) and (max-height: 540px) {
  .top { min-height: calc(47px + env(safe-area-inset-top)); }
  #game { height: calc(100vh - 57px - env(safe-area-inset-top)); height: calc(100dvh - 57px - env(safe-area-inset-top)); min-height: 218px; }
  #menu { padding-top: max(calc(var(--game-top) + 58px), 8dvh); }
  .welcome p { margin: 6px 0 9px; }
  .welcome .primary, .board .primary { min-height: 44px; }
  .overlay { padding-block-start: calc(var(--game-top) + 55px); padding-block-end: max(15px, env(safe-area-inset-bottom)); }
  .board { padding-block: 11px; }
  .board h2 { font-size: clamp(1.65rem, 4.5vw, 2.5rem); }
  .welcome h2 { font-size: clamp(2.6rem, 13dvh, 4.35rem); }
  .hint { top: calc(var(--game-top) + 59px); }
  #result-splits li { padding-block: 2px; }
}
