:root {
  color-scheme: dark;
  --ink: #15212a;
  --outline: #485d67;
  --paper: #fff4da;
  --gold: #ffbf60;
  --mint: #a8e3b8;
  font: 16px/1.25 "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-width: 300px;
  min-height: 100dvh;
  margin: 0;
  color: var(--paper);
  background-color: #111a22;
  background-image: radial-gradient(ellipse at 50% 0, #314453 0, transparent 70%),
    linear-gradient(#a4c4dd0d 1px, transparent 1px), linear-gradient(90deg, #a4c4dd0d 1px, transparent 1px);
  background-size: auto, 24px 24px, 24px 24px;
}
button { font: inherit; cursor: pointer; color: inherit; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible { outline: 3px solid #96edff; outline-offset: 3px; }
svg { display: block; width: 24px; height: 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.machine { max-width: 704px; margin: 0 auto; padding: 8px 14px 14px; }
.masthead, .site-top, .bed-top, .map-header, .reward { display: flex; align-items: center; }
.masthead, .map-header { justify-content: space-between; }
.masthead { min-height: 47px; margin-bottom: 7px; }
.wordmark { display: flex; align-items: center; margin: 0; line-height: 1; font-size: clamp(1.13rem, 5vw, 1.55rem); font-weight: 950; letter-spacing: -.065em; transform: skewX(-5deg); }
.wordmark > span:last-child { color: var(--gold); }
.brand-mark { display: grid; grid-template-columns: repeat(2, 7px); gap: 2px; margin-right: 8px; transform: skewX(5deg); }
.brand-mark i { height: 7px; background: var(--gold); border-radius: 1px; }
.brand-mark i:first-child { grid-column: 2; }
.header-controls { display: flex; gap: 7px; }
.utility {
  min-width: 44px; min-height: 44px; display: grid; place-items: center;
  padding: 0; border: 1px solid var(--outline); border-radius: 9px; background: #263845;
}
.utility:hover { background: #36505d; }
.utility:disabled { opacity: .46; }
.site { background: #1b2730; border: 1px solid var(--outline); border-radius: 14px; overflow: hidden; box-shadow: 0 5px 16px #090e1480; }
.site-top { min-height: 47px; gap: 10px; padding: 5px 9px; }
.level-number {
  min-width: 35px; min-height: 34px; display: grid; place-items: center;
  border: 1px solid #ffd385; border-radius: 7px; color: var(--ink); background: var(--gold);
  box-shadow: inset 0 -3px #d58e3c; font-size: 1.3rem; font-weight: 950;
}
.stage-icon { color: #d6e2dd; }
.stage-icon svg { width: 25px; height: 25px; }
.dev-mark { font-size: .69rem; font-weight: 800; letter-spacing: .12em; color: #ffca7b; }
.progress { margin-left: auto; display: flex; gap: 5px; }
.progress span { width: 28px; height: 22px; display: grid; place-items: center; border: 1px solid #50666e; border-radius: 5px; background: #253641; }
.progress .current { background: var(--gold); color: var(--ink); border-color: #ffdb9b; }
.progress .done { background: var(--mint); color: var(--ink); border-color: #c0eccb; }
.progress svg { width: 16px; height: 16px; }
.scene-area { position: relative; background: #accbc6; }
canvas { width: 100%; aspect-ratio: 12 / 5; height: auto; display: block; }
.stripe { height: 5px; background: repeating-linear-gradient(-53deg,#303630 0 7px,#e9ad53 7px 14px); }
.gate-gesture {
  position: absolute; top: 34%; left: 51%; width: 31%; height: 41%;
  display: grid; place-items: center; background: transparent; border: 0; border-radius: 8px; touch-action: none;
}
.gate-gesture svg { width: 42px; height: 34px; padding: 4px; color: var(--ink); background: var(--gold); border: 1px solid #6c552e; border-radius: 7px; box-shadow: 0 2px #433829; animation: slide 1.15s ease-in-out 3; }
@keyframes slide { 50% { transform: translateX(9px); } }
.effect { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.effect i { position: absolute; top: 64%; left: 50%; width: 6px; height: 10px; border-radius: 1px; animation: spark .7s ease-out both; }
@keyframes spark { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }
.console { margin-top: 8px; padding: 8px 9px 10px; background: #1d2b35; border: 1px solid var(--outline); border-radius: 12px; box-shadow: 0 3px 9px #090f1580; }
.equation-row { display: grid; grid-template-columns: auto 1fr auto; gap: 5px; align-items: center; margin: 0 1px 9px; }
.equation {
  min-width: 0; display: flex; justify-content: center; align-items: baseline; gap: .18em;
  white-space: nowrap; font-size: clamp(1.95rem, 8.4vw, 3.4rem); font-weight: 950; font-variant-numeric: tabular-nums;
  letter-spacing: -.065em; line-height: 1.14;
}
.operator { color: #b1c1c8; font-weight: 700; }
.unknown { color: var(--gold); }
.solved { color: var(--mint); }
.show { color: var(--gold); border-color: #876940; background: #352f2b; }
.show:not(:disabled):hover { background: #4e4130; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.15fr) 22px minmax(0, 1fr); align-items: stretch; gap: 5px; }
.crates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
.crate-slot { min-width: 0; display: flex; align-items: stretch; }
.crate {
  position: relative; width: 100%; min-height: 97px; padding: 4px; display: grid; place-items: center;
  border: 1px solid #5c402c; border-radius: 7px; color: #2a2117;
  background: repeating-linear-gradient(0deg, transparent 0 17px, #885d3c99 17px 18px), linear-gradient(145deg, #e4af72, #b67842);
  box-shadow: inset 0 0 0 3px #e0a267, inset 0 0 0 4px #795438, 0 3px #0e171d;
}
.crate::before, .crate::after { content: ""; position: absolute; top: 7px; width: 4px; height: 4px; border-radius: 50%; background: #795539; }
.crate::before { left: 8px; } .crate::after { right: 8px; }
.crate:hover { filter: brightness(1.13); }
.crate b {
  display: grid; place-items: center; min-width: 36px; padding: 0 5px; color: #2a241b;
  border: 1px solid #80654a; border-radius: 4px; background: #ffe7a5;
  font-size: clamp(1.25rem, 5.2vw, 1.85rem); font-weight: 950; line-height: 1.25;
}
.crate-content { width: 100%; min-height: 97px; padding: 5px; border: 1px solid #997046; border-radius: 7px; background: #302b25; box-shadow: inset 0 2px 3px #0d1114; }
.crate-count { display: block; margin-bottom: 4px; text-align: center; color: #ffdca1; font-size: .94rem; font-weight: 900; }
.tokens { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; align-content: start; }
.token {
  flex: none; display: grid; place-items: center; min-width: 29px; min-height: 35px; padding: 1px 3px;
  border: 1px solid #ffc791; border-radius: 5px; color: #261b17; background: #f4ad7c;
  box-shadow: inset 0 -3px #ba744f; font-weight: 950; font-size: .94rem; user-select: none; touch-action: none;
}
.token.ten {
  min-width: 42px; border-color: #b9e0e6;
  background: repeating-linear-gradient(90deg,#90ced8 0 3px,#6ab2c1 3px 4px);
  box-shadow: inset 0 -3px #508795;
  text-shadow: 0 1px #afe3eb;
}
.token:hover { filter: brightness(1.13); }
.token.dragging { opacity: .38; }
.drag-ghost { position: fixed; z-index: 20; transform: translate(-50%, -50%); pointer-events: none; }
.cargo-cue { display: grid; align-self: center; justify-content: center; color: #80939b; pointer-events: none; }
.cargo-cue svg { width: 20px; height: 20px; }
.cargo-cue.live { color: var(--gold); animation: slide 1s ease-in-out 3; }
.bed-panel { min-width: 0; display: flex; flex-direction: column; border: 1px solid #607782; border-radius: 7px; background: #243844; padding: 0 4px 4px; }
.bed-top { min-height: 43px; gap: 3px; justify-content: space-between; padding-left: 4px; color: #bfd0d1; }
.bed-top > span svg { width: 24px; height: 24px; }
.bed-top output { flex: 1; text-align: center; color: var(--mint); font-size: clamp(1.08rem, 4.7vw, 1.45rem); font-weight: 950; font-variant-numeric: tabular-nums; }
.undo { min-width: 34px; min-height: 39px; border: 0; color: var(--gold); background: transparent; }
.undo svg { width: 18px; height: 18px; }
.bed { flex: 1; min-height: 50px; padding: 4px; border: 1px dashed #7f969b; border-radius: 5px; background: repeating-linear-gradient(0deg, #192a33 0 12px, #233743 12px 13px); }
.bed.target { border: 2px solid var(--gold); padding: 3px; background: #3b4234; }
.delivered .token { min-height: 22px; min-width: 20px; padding: 0 2px; font-size: .75rem; }
.delivered .token.ten { min-width: 24px; }
.cue, .hinted { outline: 2px solid var(--gold); outline-offset: 1px; animation: cue 1s ease-in-out 3; }
@keyframes cue { 50% { box-shadow: 0 0 10px #ffbf609c; } }
.answer-dock { position: sticky; bottom: 0; z-index: 2; padding: 8px 0 max(4px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, #17212a 13%); }
.answers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.answer, .operation {
  min-height: 60px; display: grid; place-items: center; border: 1px solid #fff5df; border-radius: 9px;
  color: var(--ink); background: #f5ecd4; font-size: clamp(1.95rem, 8vw, 2.55rem); font-weight: 950;
  box-shadow: inset 0 -4px #c9bda0, 0 3px #0e171f; font-variant-numeric: tabular-nums;
}
.answer:hover { background: #ffe3ab; }
.answer:active, .operation:active { transform: translateY(2px); }
.answer.missed { background: #ddc4af; border-color: #f3b789; box-shadow: inset 0 -4px #b89880; animation: bump .28s ease-out; }
@keyframes bump { 30% { transform: translateX(-4px); } 65% { transform: translateX(4px); } }
.reward { gap: 7px; padding: 7px; border: 1px solid #6b8d7b; border-radius: 11px; background: #243a33; margin-top: 8px; }
.stamp { width: 42px; min-height: 44px; display: grid; place-items: center; color: var(--mint); }
.operation { flex: 1; min-height: 50px; border-color: #ffd897; background: var(--gold); box-shadow: inset 0 -4px #d5923e; }
.operation:hover { background: #ffcf79; }
.operation svg { width: 30px; height: 30px; }
.operation[aria-disabled="true"] { opacity: .7; cursor: default; }
.operation.ready { outline: 2px solid var(--gold); outline-offset: 2px; }
dialog { width: min(470px, calc(100vw - 24px)); max-height: 89dvh; padding: 12px; border: 1px solid #687b84; border-radius: 13px; color: var(--paper); background: #1e303b; box-shadow: 0 8px 40px #0008; }
dialog::backdrop { background: #0b1219c9; }
.map-header { padding: 0 0 9px 5px; color: var(--gold); }
.map-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.map-tile {
  width: 100%; min-height: 61px; display: flex; justify-content: space-between; align-items: center; gap: 4px;
  padding: 0 9px; color: #d5e4e5; background: #2c414d; border: 1px solid #57707b; border-radius: 7px; font-size: 1.2rem; font-weight: 950;
}
.map-tile > svg, .map-tile span > svg { width: 22px; height: 22px; }
.map-tile:disabled { color: #a6b9be; background: #24343e; }
.map-tile.built { border-color: #75a383; color: var(--mint); }
.map-tile.open { border-color: #b7925b; color: var(--gold); }
@media (max-width: 490px) {
  .machine { padding: 5px 8px 10px; }
  .console { padding: 6px 6px 8px; }
  .workspace { gap: 3px; grid-template-columns: minmax(0, 1.15fr) 17px minmax(0, 1fr); }
  .cargo-cue svg { width: 16px; height: 16px; }
}
@media (max-width: 355px) {
  .equation { font-size: clamp(1.55rem, 8vw, 2rem); }
  .equation-row { gap: 3px; }
  .crate-content { padding: 4px 2px; }
  .token { min-width: 24px; padding: 1px 2px; }
  .token.ten { min-width: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .effect { display: none; }
}
