@font-face {
  font-family: "Keynope C64";
  src: url("keynope-c64.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
:root {
  color-scheme: light;
  --blue-dark: #150027;
  --dark-velvet: #561257;
  --velvet: #831b84;
  --magenta: #e331d0;
  --white: #fff;
  --muted: #625368;
  --console-line: #60386e;
  --console-text: #e5c6e9;
  --focus: #f6a5ec;
  --terminal-height: clamp(70px, 10dvh, 90px);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --c64: "Keynope C64", var(--mono);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  margin: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--blue-dark);
  color: var(--blue-dark);
}
button { font: inherit; color: inherit; }
button:not(:disabled) { cursor: pointer; }
button:focus-visible, dialog:focus-visible { outline: 3px solid var(--velvet); outline-offset: 3px; }
svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }
.brand, .header-actions { display: flex; align-items: center; white-space: nowrap; }
.brand { gap: 15px; }
.brand-wordmark { display: block; width: 72px; height: auto; }
.brand h1 { padding-left: 15px; border-left: 1px solid var(--console-line); font: 400 17px/1.6 var(--c64); }
.header-actions { gap: 9px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border-radius: 8px;
  padding: 6px 11px;
  background: var(--white);
  border: 1px solid #e1d1e5;
  font-size: 13px;
  font-weight: 650;
}
.button:hover { background: #f6eaf6; }
.button svg { width: 16px; height: 16px; }
.factory-header .button { color: var(--white); background: #2b123e; border-color: #775482; }
.factory-header .button:hover { background: var(--dark-velvet); }
.factory-header .button:focus-visible { outline-color: var(--focus); }
.factory-header .sound-button { background: transparent; border-color: transparent; color: var(--console-text); }
.factory-header .help-button { background: var(--dark-velvet); border-color: #a144a2; }
.factory-header .help-button:hover { background: var(--velvet); }
h1, h2, p { margin: 0; }
.micro {
  font: 700 11px var(--mono);
  letter-spacing: .05em;
}
.layout { display: grid; min-height: 0; }
.factory {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  container-type: inline-size;
  background: var(--blue-dark);
}
.factory-header {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 17px;
  color: var(--white);
  background: var(--blue-dark);
  border-bottom: 2px solid var(--velvet);
}
.hint-header h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 760;
  letter-spacing: -.015em;
}
.scoreboard { display: flex; align-items: baseline; gap: 15px; min-width: 0; font: 400 16px var(--c64); }
.score { display: flex; align-items: baseline; gap: 12px; color: var(--console-text); white-space: nowrap; }
.score strong { color: var(--white); font: inherit; }
.streak-display { color: var(--console-text); white-space: nowrap; }
.streak-display.boosted { color: var(--focus); }
.shift-clock { flex: none; padding: 6px 9px; border: 1px solid var(--console-line); border-radius: 6px; background: #200933; color: #f6c9f1; }
.shift-clock svg { display: block; width: 87px; height: 25px; fill: #43234f; stroke: none; }
.shift-clock .lit { fill: currentColor; }
.shift-clock.urgent { color: #ffbe83; border-color: #987354; }
#last-task { color: var(--console-text); font: 500 10px var(--mono); }
.map-viewport {
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
  overflow: hidden;
  background-color: #21112d;
  background-image: linear-gradient(#362143 1px, transparent 1px), linear-gradient(90deg, #362143 1px, transparent 1px);
  background-size: 50px 50px;
}
.board {
  position: relative;
  width: min(100cqw, calc(100cqh * var(--map-ratio)));
  aspect-ratio: var(--map-ratio);
  container-type: inline-size;
  background: #31203e;
  box-shadow: 0 0 0 1px #4b305a, 0 0 30px #15002780;
  touch-action: manipulation;
}
#floor { width: 100%; height: 100%; display: block; }
#stations { position: absolute; inset: 0; pointer-events: none; }
#machine-arrows { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; pointer-events: none; }
.station {
  position: absolute;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 8px;
  touch-action: manipulation;
  pointer-events: auto;
}
.station:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
#start-shift {
  z-index: 2;
  overflow: hidden;
  color: transparent;
}
.station-label {
  position: absolute;
  left: 50%;
  top: var(--label-top);
  transform: translate(-50%, -50%);
  min-width: 4.4em;
  padding: .24em .52em;
  border: 1px solid #587165;
  border-radius: 4px;
  color: var(--station-color, #e4efe3);
  background: #21392f;
  font: 750 clamp(8px, 1vw, 12px) / 1.05 var(--mono);
  pointer-events: none;
}
.tool-label { width: max-content; max-width: 100%; }
[data-station="brain"] .station-label, [data-station="delivery"] .station-label, [data-station="guardrail"] .station-label {
  width: max-content;
  white-space: nowrap;
}
@container (max-width: 480px) {
  [data-station="brain"] .station-label { top: 112%; }
}
.policy-display {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffe4a3;
  font: 750 clamp(6px, 1.12cqw, 13px) / 1 var(--mono);
  pointer-events: none;
}
@media (hover: hover) {
  .station:enabled:hover .station-label { border-color: var(--focus); }
}
kbd { display: inline-grid; place-items: center; min-width: 18px; min-height: 18px; padding: 1px 4px; border-radius: 4px; border: 1px solid #d7bedc; border-bottom-width: 2px; background: var(--white); color: var(--dark-velvet); font: 700 10px var(--mono); vertical-align: baseline; }
.package-terminal {
  position: relative;
  height: var(--terminal-height);
  overflow: auto hidden;
  scrollbar-width: thin;
  scrollbar-color: #944c98 var(--blue-dark);
  border-bottom: 1px solid var(--console-line);
  background: var(--blue-dark);
}
.package-terminal:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
#package-display { display: block; }
.visually-hidden {
  position: absolute;
  inset: 0 auto auto 0;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
.hints {
  position: absolute;
  z-index: 1;
  top: calc(100% + var(--terminal-height) + 5px);
  right: 10px;
  width: min(305px, calc(100% - 20px));
  border: 1px solid #8b5a94;
  border-radius: 10px;
  background: #291238;
  box-shadow: 0 8px 22px #150027b3;
}
.hints.has-hint { border-color: #b75eb8; border-left: 3px solid var(--magenta); }
.hint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  padding: 7px 11px;
  border-bottom: 1px solid var(--console-line);
}
.hint-header svg { width: 17px; height: 17px; color: var(--console-text); }
.hints.has-hint .hint-header h2 svg { color: var(--focus); }
.hints .icon-button { width: 30px; min-height: 27px; padding: 4px; }
.hint-body { padding: 10px 11px; }
#hint-title { font-size: 14px; font-weight: 760; line-height: 1.25; }
#hint-detail { color: var(--console-text); font-size: 12px; line-height: 1.5; margin-top: 4px; overflow-wrap: anywhere; }
dialog { max-width: min(calc(100% - 30px), 515px); max-height: calc(100% - 26px); border: 1px solid #e1d1e5; border-radius: 14px; padding: 21px; background: var(--white); color: var(--blue-dark); box-shadow: 0 18px 55px #15002780; }
dialog::backdrop { background: #150027b3; }
#game-over {
  position: fixed;
  inset: 0;
  height: fit-content;
  pointer-events: none;
  width: min(calc(100% - 36px), 520px);
  margin: auto;
  padding: clamp(24px, 6vw, 48px) 20px;
  border: 3px solid var(--magenta);
  border-radius: 0;
  background: var(--dark-velvet);
  box-shadow: 0 0 0 6px var(--blue-dark), inset 0 0 0 2px var(--velvet);
  color: var(--white);
  text-align: center;
  font: 400 clamp(17px, 4.6vw, 24px) var(--c64);
}
#game-over h2 { font: inherit; }
#game-over-summary { margin-top: 16px; color: inherit; font: inherit; }
@media (max-width: 630px) {
  #game-over { left: 24%; right: 12px; width: auto; padding-inline: 8px; }
}
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 9px; }
.dialog-header h2 { font-size: 24px; letter-spacing: -.055em; }
.icon-button { width: 35px; padding: 5px; }
dialog p, dialog ol { color: #57455f; font-size: 14px; line-height: 1.55; }
dialog ol { padding-left: 22px; }
dialog li + li { margin-top: 8px; }
dialog kbd + kbd { margin-left: 2px; }
#instructions {
  width: min(1060px, calc(100% - 32px));
  max-width: none;
  padding: 0;
}
.instructions-header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 16px 24px 12px;
  border-bottom: 1px solid #e1d1e5;
  background: var(--white);
}
.instructions-header .dialog-header { padding-bottom: 0; }
.instructions-pages { display: none; }
.instructions-spread { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.instructions-page { padding: 18px 24px 24px; }
.instructions-page + .instructions-page {
  border-inline-start: 1px solid #e1d1e5;
  box-shadow: inset 11px 0 16px -18px var(--dark-velvet);
}
.instructions-page h3 { margin: 0 0 10px; color: var(--dark-velvet); font-size: 16px; }
.instructions-page p + p { margin-top: 8px; }
.instruction-section + .instruction-section { margin-top: 12px; }
.policy-rules {
  display: grid;
  gap: 8px;
  margin-block: 0 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f7edf7;
}
.policy-rules dt { color: var(--dark-velvet); font: 750 11px var(--mono); }
.policy-rules dt span { color: var(--muted); font-weight: 500; }
.policy-rules dd { margin: 2px 0 0; color: #57455f; font-size: 13px; line-height: 1.4; }
@media (min-width: 880px) and (max-height: 790px) {
  .instructions-header { padding: 12px 20px 8px; }
  .instructions-page { padding: 14px 20px 16px; }
  .instructions-page p, .instructions-page ol { font-size: 13px; line-height: 1.37; }
  .instructions-page p + p, .instructions-page li + li { margin-top: 6px; }
  .policy-rules dd { font-size: 12px; line-height: 1.35; }
}
@media (min-width: 880px) and (max-height: 720px) {
  .instructions-header { padding-block: 7px; }
  .instructions-page { padding: 10px 16px 12px; }
  .instructions-page h3 { margin-bottom: 6px; }
  .instructions-page p, .instructions-page ol { line-height: 1.27; }
  .instructions-page ol { margin-block: 7px; }
  .instruction-section + .instruction-section { margin-top: 8px; }
  .policy-rules { gap: 5px; margin-bottom: 6px; padding-block: 7px; }
}
@media (max-width: 879px) {
  #instructions { width: min(520px, calc(100% - 24px)); }
  .instructions-header { padding: 12px 14px 8px; }
  .instructions-pages { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  .instructions-pages .button[aria-pressed="true"] { background: var(--dark-velvet); color: var(--white); }
  .instructions-spread { display: block; }
  .instructions-page { display: contents; }
  .instructions-page h3 { display: none; }
  .instruction-section { padding: 12px 14px 18px; }
  .instruction-section + .instruction-section { margin: 0; }
  .instruction-section ol { margin-top: 0; }
  .instruction-section p, .instruction-section ol { font-size: 13px; line-height: 1.38; }
  .instruction-section:not(.active) { display: none; }
}
@media (max-width: 360px) and (max-height: 600px) {
  .instructions-header { padding: 8px 10px; }
  .instruction-section { padding: 10px 12px 14px; }
  .instruction-section li + li { margin-top: 5px; }
  .instruction-section ol { margin-bottom: 8px; }
}
@media (max-width: 960px) {
  .factory-header .sound-button span { display: none; }
}
@container (max-width: 1340px) {
  .factory-header { display: grid; grid-template-columns: 1fr auto; padding: 8px 10px; gap: 8px; }
  .scoreboard { grid-area: 2 / 1; }
  .factory-header .header-actions { grid-area: 1 / 2; }
  .shift-clock { grid-area: 2 / 2; justify-self: end; }
}
@media (max-width: 660px) {
  #last-task { display: none; }
  .scoreboard { gap: 8px; font-size: 12px; }
}
@media (max-width: 480px) {
  .scoreboard { grid-area: 2 / 1 / 3 / -1; }
  .shift-clock { grid-area: 3 / 1 / 4 / -1; justify-self: start; }
}
@media (max-width: 620px) {
  .brand { gap: 9px; }
  .brand-wordmark { width: 54px; }
  .brand h1 { padding-left: 9px; font-size: 14px; }
  .header-actions { gap: 2px; }
  #get-hint span { display: none; }
  .button { min-height: 32px; padding: 5px 7px; }
  .station-label { font-size: clamp(5.5px, 1.8vw, 8px); }
  .tool-label { padding-inline: .3em; }
}
@media (max-width: 460px) {
  .help-button span { display: none; }
}
@media (max-width: 350px) {
  .brand { gap: 7px; }
  .brand-wordmark { width: 48px; }
  .brand h1 { padding-left: 7px; font-size: 12px; }
  .factory-header .button { font-size: 12px; }
  .scoreboard { font-size: 11px; }
}

#highscores-dialog {
  width: min(465px, calc(100% - 24px));
  max-width: none;
  padding: 12px;
  border: 0;
  background: transparent;
  color: #fff0fc;
  box-shadow: none;
  font: 16px/1.4 var(--c64);
  text-shadow: -1px -1px #150027, 1px -1px #150027, -1px 1px #150027, 1px 1px #150027, 0 2px 6px #150027;
}
#highscores-dialog::backdrop { background: transparent; }
body:has(#highscores-dialog[open]) #game-over { visibility: hidden; }
.highscores-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.highscores-header h2 { font: 400 clamp(16px, 5vw, 24px) var(--c64); }
#highscores-board { display: grid; gap: 4px; padding: 0; margin: 14px 0; list-style: none; color: inherit; font: inherit; }
#highscores-board li { display: grid; grid-template-columns: 3ch minmax(0, 1fr) 6ch; gap: 1ch; margin: 0; }
#highscores-board li span:last-child { text-align: end; }
#highscores-dialog p { color: inherit; font: inherit; }
#highscores-status { margin-top: 12px; min-height: 1.5em; }
#highscores-name { display: block; min-height: 1.6em; margin-block: 10px; color: #f6a5ec; }
#highscores-dialog button, #claim-score {
  padding: 4px 7px;
  border: 1px solid #d5a7de;
  border-radius: 0;
  background: #150027;
  color: #fff;
  font: inherit;
}
#highscores-dialog button:enabled:hover, #claim-score:hover { background: #561257; }
#highscores-dialog button:disabled { opacity: .55; }
.highscore-key-row { display: flex; justify-content: center; gap: 3px; margin-block: 5px; }
.highscore-key-row button { flex: 0 1 34px; min-width: 0; padding-inline: 4px; }
.highscore-key-row #highscores-delete, .highscore-key-row #highscores-submit { flex-basis: auto; padding-inline: 8px; }
#claim-score { pointer-events: auto; margin-top: 14px; font-size: 12px; }
@media (max-width: 650px) {
  #highscores-button span { display: none; }
  #highscores-dialog { font-size: 12px; }
  .factory-header .header-actions .button { padding-inline: 5px; }
}
@media (max-width: 370px) {
  .brand h1 { font-size: 10px; }
  .brand-wordmark { width: 44px; }
}
