:root {
  color-scheme: dark;
  --night: #0b111f;
  --surface: #151d2e;
  --surface-shy: #111a2b;
  --line: #35415a;
  --paper: #fff0d7;
  --quiet: #b9c0cf;
  --amber: #ffcf88;
  --ember: #eca863;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  --display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 0; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: clip;
  color: var(--paper);
  background: radial-gradient(ellipse at 68% 6%, #17223b, transparent 55%), var(--night);
  font: 1rem/1.5 system-ui, sans-serif;
}

a { color: inherit; }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 4px; }

.shell { width: min(1120px, calc(100% - 80px)); margin-inline: auto; }
.masthead {
  min-height: 71px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding-block: 12px;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 600 1.24rem/1.25 var(--display);
}

.brand-star { color: var(--amber); font: 1.1rem/1 system-ui, sans-serif; }
.event-link { color: var(--quiet); font-size: .82rem; text-decoration-color: #717d95; text-underline-offset: 4px; }
.event-link:hover { color: var(--paper); }
.event-link span { padding-left: 3px; }
.opening { padding-block: clamp(26px, 4vw, 45px) 26px; }
.chapter {
  margin: 0 0 8px;
  color: var(--amber);
  font-size: .75rem;
  font-weight: 650;
  letter-spacing: .135em;
  text-transform: uppercase;
}

h1, h2, p { margin-block-start: 0; }
h1 {
  margin-bottom: 9px;
  font: 500 clamp(3.0rem, 7.2vw, 5.65rem)/.97 var(--display);
  letter-spacing: -.063em;
}

h1 em { color: var(--amber); font-weight: inherit; }
.objective { margin-bottom: 0; color: var(--quiet); font-size: clamp(.94rem, 1.5vw, 1.07rem); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(270px, 300px);
  align-items: start;
  gap: 22px;
}

.board-frame, .run-panel { border: 1px solid var(--line); background: var(--surface-shy); min-width: 0; }
.board-frame { box-shadow: 0 18px 50px #04071154; }
.scene { position: relative; aspect-ratio: 320 / 204; background: #11192f; isolation: isolate; }
.scene::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  box-shadow: inset 0 0 24px #080c1c47;
}

canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.tiles { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.tile {
  position: absolute;
  width: 11.25%;
  height: 8.824%;
  transform: translate(-50%, -50%);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  border: 0;
  padding: 0;
  background: transparent;
  pointer-events: auto;
  touch-action: manipulation;
}

.tile:hover, .tile:focus-visible { background: #ffe0a444; outline: none; }
.tile:focus-visible::after {
  position: absolute;
  inset: 28% 36%;
  content: "";
  background: var(--paper);
}

.board-help {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 8px 15px;
  border-top: 1px solid var(--line);
}

.board-help p { margin: 0; color: var(--quiet); font-size: .82rem; }
.tile-key { display: inline-block; width: 8px; height: 8px; margin-right: 8px; background: var(--amber); transform: rotate(45deg); }
.directions { display: flex; gap: 5px; flex-wrap: wrap; }
.directions button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #58647a;
  background: #1f2940;
  color: var(--paper);
  font-size: 1.12rem;
  line-height: 1;
}

.directions button:not(:disabled):hover { color: var(--amber); background: #2b3449; border-color: var(--amber); }
.directions button:disabled { color: #8e98ac; border-color: #364058; background: transparent; }
.run-panel { padding: 22px; background: linear-gradient(150deg, #1a2335, var(--surface) 70%); }
.trial-heading { display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
h2 { margin: 0; font: 500 1.72rem/1.15 var(--display); letter-spacing: -.025em; }
.challenge-target { margin: 0; color: var(--amber); font-size: .8rem; font-weight: 600; }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; border-block: 1px solid var(--line); }
.metrics div { padding-block: 9px 11px; }
.metrics div + div { border-left: 1px solid var(--line); padding-inline-start: 15px; }
.metrics dt { color: var(--quiet); font-size: .78rem; }
.metrics dd { margin: 2px 0 0; color: var(--paper); font: 500 2rem/1.16 var(--mono); font-variant-numeric: tabular-nums; }
.metric-total { color: var(--quiet); font-size: 1.18rem; }
.beacons { padding: 0; margin: 12px 0 17px; list-style: none; }
.beacons li {
  display: grid;
  grid-template-columns: 11px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  border-bottom: 1px solid #35415a87;
  font-size: .86rem;
}

.beacon-symbol { width: 8px; height: 8px; border: 1px solid #99a6be; transform: rotate(45deg); }
.beacon-state { color: var(--quiet); font-size: .78rem; }
.beacons li.is-lit .beacon-symbol { border-color: var(--amber); background: var(--amber); box-shadow: 0 0 8px #ffbb6680; }
.beacons li.is-lit .beacon-state { color: var(--amber); }

.button {
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  font-size: .84rem;
  font-weight: 650;
  text-align: center;
}

.full { width: 100%; }
.secondary { background: transparent; }
.secondary:hover:not(:disabled) { background: #29364e; border-color: #8392ae; }
.secondary:disabled { color: #9aa5ba; }
.primary { color: #20170f; background: var(--amber); border-color: var(--amber); }
.primary:hover:not(:disabled) { background: #ffdfac; }
.primary:disabled { color: #352417; background: #d9ad72; border-color: #d9ad72; }
.result { margin: 4px 0 12px; font: 500 1.34rem/1.23 var(--display); color: var(--amber); }
.result-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 7px; }
.result-actions .primary { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.replay { grid-column: 1 / -1; color: var(--quiet); border: 0; background: transparent; }
.replay:hover { color: var(--paper); background: #29364e; }
.share-note { margin: 10px 0 0; color: var(--quiet); font-size: .77rem; }
.share-note:empty { display: none; }
#copy-fallback { margin-top: 10px; color: var(--quiet); font-size: .8rem; }
#copy-fallback input { width: 100%; margin-top: 3px; color: var(--paper); background: var(--night); border: 1px solid var(--line); padding: 7px; }
footer p { margin: 16px 0 20px; color: #a2adc1; font-size: .75rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .shell { width: calc(100% - 48px); }
  .game-layout { gap: 14px; grid-template-columns: minmax(0, 1fr) minmax(240px, .54fr); }
  .run-panel { padding: 17px; }
}

@media (max-width: 680px) {
  .shell { width: calc(100% - 32px); }
  .masthead { min-height: 56px; }
  .wordmark { gap: 6px; font-size: 1.05rem; }
  .event-link { font-size: .72rem; }
  .opening { padding-bottom: 18px; }
  .objective { max-width: 33ch; }
  .game-layout { grid-template-columns: minmax(0, 1fr); }
  .board-help { padding: 6px 9px; gap: 6px 10px; min-height: 58px; }
  .board-help p { font-size: .76rem; }
}

@media (max-width: 440px) {
  .scene { aspect-ratio: 320 / 218; overflow: hidden; }
  .scene canvas, .scene .tiles {
    position: absolute;
    inset: auto;
    width: 121%;
    height: auto;
    aspect-ratio: 320 / 204;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .board-help { justify-content: center; padding-block: 8px; }
  .directions { gap: 7px; }
  h1 { font-size: clamp(2.62rem, 12vw, 3.3rem); }
}
