:root {
  color-scheme: dark;
  --night: #090e1e; --snow: #f7f5ff; --subtle: #c9c7df; --jade: #aeffdc;
  --tile: #141d38; --wire: #8988bd; --focus: #faf2ca;
  font-family: system-ui, sans-serif; background: var(--night); color: var(--snow);
}
* { box-sizing: border-box }
body, h1, h2, p, dl, dd { margin: 0 }
body { min-width: 260px }
button, a { font: inherit; color: inherit }
button { cursor: pointer }
a { text-underline-offset: .28em }
button:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px }
[hidden] { display: none !important }
#stage {
  width: 100%; min-height: 100svh; overflow-y: auto;
  background: radial-gradient(ellipse at 74% 40%,#252447 0,transparent 58%), var(--night);
  padding: clamp(1.2rem,4vw,4.2rem) clamp(1.25rem,6.1vw,8rem) 2rem;
}
#stage:fullscreen { height: 100%; }
header, .layout, .status { max-width: 95rem; margin-inline: auto }
header { display: flex; align-items: center; justify-content: space-between; gap: .75rem }
header a { color: var(--subtle); text-decoration: none }
header a:hover { text-decoration: underline }
.quiet, .primary { display: inline-flex; align-items: center; justify-content: center; min-height: 2.8rem; border-radius: 2rem; padding: .65rem 1.15rem; line-height: 1.2; text-decoration: none }
.quiet { color: var(--snow); background: transparent; border: 1px solid #676681 }
.primary { color: #0b1821; background: var(--jade); border: 1px solid var(--jade) }
.layout { display: grid; grid-template-columns: minmax(13rem,.75fr) minmax(0,1.25fr); gap: clamp(2.2rem,7vw,8rem); align-items: center; margin-top: clamp(2.5rem,10vh,8rem) }
.maker { color: #b6ace2; letter-spacing: .045em }
h1 { margin: .55rem 0 1.4rem; font-size: clamp(4.5rem,8vw,9rem); font-weight: 500; line-height: .89; letter-spacing: -.08em }
.intro { color: var(--subtle); max-width: 25rem; font-size: clamp(1.03rem,1.45vw,1.4rem); line-height: 1.55 }
.intro strong { font-weight: 650; color: var(--snow) }
.hud { display: flex; gap: 2.4rem; margin-top: 1.65rem; font-variant-numeric: tabular-nums }
dt { color: var(--subtle); font-size: .9rem } dd { font-size: 1.45rem }
.actions { margin-top: 1.55rem }
.play { min-width: 0 }
.play h2 { font-size: clamp(1.4rem,3vw,3rem); font-weight: 500; letter-spacing: -.055em; margin-bottom: 1rem }
#playfield { position: relative; padding-inline: 1.65rem }
#board { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: clamp(.24rem,.45vw,.56rem) }
.tile {
  width: 100%; aspect-ratio: 1.1; padding: 0; border: 1px solid #414767; border-radius: clamp(.35rem,1vw,.8rem);
  background: linear-gradient(140deg,#1d284a,var(--tile)); color: var(--wire); position: relative;
  contain: layout; touch-action: manipulation;
}
.tile:focus { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 1; background: #302f4b }
.tile:focus::after { content: ''; position: absolute; top: .27rem; right: .27rem; width: .43rem; height: .43rem; background: var(--focus); border-radius: 50% }
.tile.lit { color: var(--jade) }
.trace, .socket { display: block; position: absolute; background: currentColor; pointer-events: none }
.trace.n, .trace.s { width: 7%; left: 46.5%; height: 50% }
.trace.e, .trace.w { height: 7%; top: 46.5%; width: 50% }
.trace.n { top: 0 } .trace.s { bottom: 0 } .trace.e { right: 0 } .trace.w { left: 0 }
.socket { left: 41%; top: 40%; width: 18%; height: 20%; border: 2px solid currentColor; border-radius: 50%; background: var(--tile) }
.lit .socket { background: currentColor; box-shadow: 0 0 .55rem #a1ffc04d }
.terminal { position: absolute; transform: translateY(-50%); font-size: clamp(.53rem,.85vw,.8rem); font-weight: 700; color: #d7cdf8; line-height: 1 }
.source { left: 0; color: var(--jade) } .sink { right: -.15rem }
.terminal.row0 { top: 16.4% } .terminal.row1 { top: 50% } .terminal.row2 { top: 83.6% }
.sink.complete { color: var(--jade); text-decoration: double underline }
.keys { color: var(--subtle); margin: 1rem 1.65rem 0; font-size: clamp(.85rem,1.05vw,1.1rem); line-height: 1.55 }
.keys span { color: #9281c5; padding: 0 .12em }
.status { min-height: 1.6em; color: var(--jade); margin-top: 1.35rem }
dialog { width: min(27rem,calc(100% - 2rem)); border-radius: 1rem; border: 1px solid #62617d; background: #171d34; color: var(--snow); padding: 1.8rem }
dialog::backdrop { background: #070a16ce }
dialog h2 { font-size: 2rem; font-weight: 500; letter-spacing: -.05em }
dialog p { color: var(--subtle); margin: .75rem 0 1.6rem; line-height: 1.55 }
dialog .quiet { margin-left: .5rem }
@media(max-width: 720px) {
  #stage { padding: 1.15rem 1.25rem 1.5rem }
  .layout { grid-template-columns: 1fr; gap: 1.7rem; margin-top: 2rem }
  h1 { font-size: clamp(3.75rem,12vw,5.5rem); margin: .4rem 0 .8rem } h1 br { display: none } h1 br::after { content: ' ' }
  .intro { max-width: 36rem }
  .brief { position: relative } .hud { margin-top: 1rem; gap: 1.8rem }
  .actions { position: absolute; bottom: 0; right: 0; margin: 0 }
  .play { padding-block: .2rem }
  #playfield { padding-inline: 1.4rem } .keys { margin-inline: 0 }
}
@media (min-width: 721px) and (max-height: 560px) {
  #stage { padding-block: 1rem } .layout { margin-top: 1.2rem } h1 { font-size: 4.7rem }
  .play { max-width: 32rem; justify-self: center; width: 100% }
}
@media(prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; scroll-behavior: auto !important } }
