:root {
  color-scheme: dark;
  font-family: "Hiragino Sans", "Yu Gothic", "Helvetica Neue", sans-serif;
  color: #fff4ea;
  background: #07111f;
  --navy: #07111f;
  --panel: #10192c;
  --line: #31405c;
  --mint: #53e0b7;
  --gold: #ffd27a;
  --orange: #ff9a4d;
  --pink: #ffc4d6;
  --muted: #9aa6c2;
  --cold: #4a5878;
}

* { box-sizing: border-box; }

html, body { overscroll-behavior: none; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 16% 0%, rgba(83, 224, 183, .16), transparent 22rem),
    radial-gradient(circle at 88% 8%, rgba(255, 210, 122, .12), transparent 20rem),
    var(--navy);
}

button, a { font: inherit; }
a { color: inherit; }

a:focus-visible,
button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 4px;
}

.site-header,
main {
  width: min(92vw, 1120px);
  margin-inline: auto;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 68px;
  border-bottom: 1px solid var(--line);
}

.site-header a {
  color: var(--mint);
  font-size: .9rem;
  font-weight: 800;
  text-decoration: none;
}

.site-header p {
  margin: 0;
  color: var(--muted);
  font: 700 .72rem/1 "Trebuchet MS", ui-monospace, monospace;
  letter-spacing: .08em;
}

main {
  display: grid;
  grid-template-columns: minmax(210px, .5fr) minmax(0, 1.5fr);
  gap: clamp(1.5rem, 5vw, 4rem);
  padding: clamp(2.5rem, 6vw, 5rem) 0 4rem;
}

.intro { align-self: start; position: sticky; top: 2rem; }
.eyebrow {
  margin: 0 0 .8rem;
  color: var(--mint);
  font: 800 .72rem/1 "Trebuchet MS", ui-monospace, monospace;
  letter-spacing: .14em;
}

h1 {
  margin: 0;
  font-size: clamp(2.8rem, 7vw, 5.2rem);
  line-height: .92;
  letter-spacing: -.04em;
  white-space: nowrap;
}

h1 span { color: var(--gold); }
.intro > p:last-child {
  margin: 1.5rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.8;
}

.game-panel,
.help {
  border: 1px solid var(--line);
  border-radius: 1.4rem;
  background: rgba(16, 25, 44, .94);
  box-shadow: 0 25px 70px rgba(0,0,0,.32);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.scoreboard p {
  margin: 0;
  padding: .85rem .55rem;
  border-right: 1px solid var(--line);
}

.scoreboard p:last-child { border-right: 0; }
.scoreboard span {
  display: block;
  margin-bottom: .3rem;
  color: var(--muted);
  font-size: .62rem;
  font-weight: 750;
  letter-spacing: .04em;
}
.scoreboard strong { color: var(--gold); font-size: .95rem; }
.scoreboard b { color: #fff; font-size: 1.2rem; }

.stage {
  position: relative;
  overflow: hidden;
  padding: 1rem 1rem .4rem;
  background:
    linear-gradient(180deg, #0b1426 0%, #151a2e 58%, #1c1630 100%);
}

.city {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 6px;
  height: 52px;
  margin-bottom: .85rem;
  align-items: end;
  padding: 0 4px 4px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.city i {
  display: block;
  height: 16px;
  border-radius: 2px 2px 0 0;
  background: #2a3550;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

.city i.on {
  height: 32px;
  background: linear-gradient(180deg, #ffe7a6, #53e0b7);
  box-shadow: 0 0 12px rgba(83, 224, 183, .55);
}

.stage.is-clear .city i {
  height: 34px;
  background: linear-gradient(180deg, #fff4c8, #ff9a4d);
  box-shadow: 0 0 14px rgba(255, 210, 122, .55);
}

.board {
  display: grid;
  gap: 6px;
  width: min(100%, 440px);
  margin: 0 auto;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
}

.tile {
  position: relative;
  aspect-ratio: 1;
  min-height: 56px;
  padding: 0;
  border: 1px solid #24324c;
  border-radius: .7rem;
  color: inherit;
  background:
    linear-gradient(160deg, #1c2740, #121a2c 55%, #0d1422);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.08),
    0 8px 16px rgba(0,0,0,.28);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.tile:disabled { cursor: default; }

.tile-rot {
  display: block;
  width: 100%;
  height: 100%;
  transition: transform .18s ease;
}

.tile svg {
  width: 100%;
  height: 100%;
  display: block;
}

.pipe {
  fill: none;
  stroke: var(--cold);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hub { fill: var(--cold); }

.tile.is-powered .pipe {
  stroke: var(--mint);
  stroke-width: 12;
  filter: drop-shadow(0 0 4px rgba(83, 224, 183, .7));
}

.tile.is-powered .hub { fill: var(--mint); }

.tile.is-lamp.is-powered .pipe {
  stroke: var(--gold);
  filter: drop-shadow(0 0 5px rgba(255, 210, 122, .8));
}

.tile.is-lamp.is-powered .hub { fill: var(--gold); }

.glyph {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .62rem;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  background: #0b1020;
  color: var(--muted);
  box-shadow: 0 0 0 2px #24324c;
}

.tile.is-generator .glyph {
  border-radius: .3rem;
  color: #0b1020;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(255, 210, 122, .45);
}

.tile.is-lamp .glyph {
  color: #9aa6c2;
  background: #141c2e;
}

.tile.is-lamp.is-powered .glyph {
  color: #0b1020;
  background: var(--gold);
  box-shadow: 0 0 12px rgba(255, 210, 122, .7);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: .4rem;
  padding: 1.5rem;
  text-align: center;
  background: rgba(7, 17, 31, .52);
  pointer-events: none;
}

.overlay.is-hidden { display: none; }

.overlay-kicker {
  margin: 0;
  color: var(--mint);
  font: 800 .72rem/1 "Trebuchet MS", sans-serif;
  letter-spacing: .16em;
}

.overlay-lead {
  margin: 0;
  color: #fff;
  font-size: clamp(1.25rem, 4vw, 1.9rem);
  font-weight: 900;
  line-height: 1.35;
  text-shadow: 0 6px 18px rgba(0,0,0,.45);
}

.overlay-note {
  margin: .35rem 0 0;
  color: var(--pink);
  font-weight: 700;
}

.guide {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.guide p {
  margin: 0;
  padding: .8rem 1rem;
}

.guide p:first-child { border-right: 1px solid var(--line); }
.guide span {
  display: block;
  margin-bottom: .25rem;
  color: var(--mint);
  font-size: .68rem;
  font-weight: 800;
}
.guide strong { font-size: .92rem; }

.burapi-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: .9rem;
  align-items: center;
  padding: .9rem 1.1rem 0;
}

.burapi-row img {
  width: 88px;
  height: 88px;
  object-fit: contain;
  image-rendering: pixelated;
}

.burapi-row p {
  margin: 0;
  padding: .7rem .9rem;
  border-radius: 1rem 1rem 1rem .3rem;
  background: #18233a;
  color: #fff4ea;
  font-weight: 700;
  line-height: 1.55;
}

.burapi-row p.is-react {
  color: #0b1020;
  background: var(--gold);
}

.status {
  min-height: 1.5em;
  margin: .9rem 1.2rem .5rem;
  color: #e8e4f6;
  text-align: center;
  font-weight: 700;
}

.actions {
  display: grid;
  grid-template-columns: 1.4fr .9fr;
  gap: .7rem;
  padding: 0 1.2rem;
}

.share-x {
  grid-column: 1 / -1;
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  background: #24324c;
  color: #fff4ea;
  font-weight: 800;
  cursor: pointer;
}
.share-x[hidden] { display: none !important; }

.action,
.hint {
  min-height: 56px;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.action {
  color: #0b1024;
  background: var(--mint);
  box-shadow: 0 10px 28px rgba(83, 224, 183, .22);
}

.hint {
  color: #fff4ea;
  background: #24324c;
}

.hint:disabled {
  opacity: .45;
  cursor: default;
}

.action:hover { filter: brightness(1.06); }
.key-hint {
  margin: .8rem 1.2rem 1.2rem;
  color: var(--muted);
  font-size: .78rem;
  text-align: center;
  line-height: 1.6;
}
kbd {
  padding: .15rem .4rem;
  border: 1px solid #52647b;
  border-radius: .3rem;
  background: #09182a;
}

.help {
  grid-column: 2;
  display: grid;
  grid-template-columns: .85fr 1.15fr;
  gap: 1.2rem;
  margin-top: 1.2rem;
  padding: 1.5rem;
}

.help h2 {
  margin: 0;
  font-size: clamp(1.3rem, 3vw, 1.9rem);
  line-height: 1.3;
}

.help ol {
  display: grid;
  gap: .8rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.help li {
  display: grid;
  grid-template-columns: 1.8rem 1fr;
  gap: .7rem;
  align-items: start;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.55;
}

.help li span {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  color: #0b1024;
  background: var(--gold);
  font-weight: 900;
}

.records {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--gold);
  font-weight: 800;
}

.reset {
  justify-self: start;
  border: 0;
  padding: 0;
  color: var(--muted);
  background: transparent;
  font-size: .78rem;
  text-decoration: underline;
  cursor: pointer;
}

.save-note {
  margin: 0;
  color: #8b88a6;
  font-size: .72rem;
  line-height: 1.5;
}

@media (max-width: 900px) {
  .scoreboard { grid-template-columns: repeat(3, 1fr); }
  .scoreboard p:nth-child(n+4) { border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; padding-top: 2.2rem; }
  .intro { position: static; }
  .intro br { display: none; }
  .help { grid-column: 1; grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr; }
  .action, .hint { min-height: 64px; }
}

@media (max-width: 520px) {
  .site-header p { display: none; }
  .scoreboard p { padding: .65rem .4rem; }
  .scoreboard strong { font-size: .8rem; }
  .scoreboard b { font-size: 1.02rem; }
  .tile { min-height: 52px; border-radius: .55rem; }
  .burapi-row { grid-template-columns: 72px 1fr; }
  .burapi-row img { width: 72px; height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
