:root {
  color-scheme: dark;
  --bg:#101a22; --panel:#20313d; --line:#435660; --muted:#afc1c9; --text:#eff5f3;
  --cold:#78edda; --warm:#ffc17d; --bad:#ff9d8e; --dock-height:196px;
  font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;
  font-synthesis:none; font-size:16px;
}
* { box-sizing:border-box; }
body { margin:0; min-width:0; color:var(--text); background:radial-gradient(ellipse at 80% 0,#2b414c66,transparent 48%),linear-gradient(135deg,#15232c,#101a22 65%); }
button,input,summary,a { -webkit-tap-highlight-color:transparent; }
button,input { font:inherit; }
button { cursor:pointer; border:0; min-height:44px; transition:background .15s,box-shadow .15s,transform .15s; }
button:active:not(:disabled) { transform:translateY(1px); }
button:disabled { opacity:.4; cursor:not-allowed; }
button:focus-visible,a:focus-visible,input:focus-visible,summary:focus-visible { outline:3px solid var(--cold); outline-offset:3px; }
[hidden] { display:none!important; }
p { overflow-wrap:anywhere; }
/* The flat view keeps the same order as the 3D view: level, stock, controls. */
.flat-workspace { width:min(100%,680px); margin:0 auto; padding:16px 12px; }
.flat-topbar { margin-bottom:12px; padding:7px; background:#223742; border:1px solid #4c6370; border-radius:12px; }
.hud-top,.flat-topbar { display:grid; grid-template-columns:auto minmax(0,1fr) auto auto; gap:6px; align-items:center; }
.hud-top { grid-template-columns:auto minmax(0,1fr) auto; }
.flat-topbar .hud-button { min-width:44px; padding:5px 8px; border:1px solid #54707e; border-radius:8px; color:var(--text); background:#314a57; font-size:.875rem; font-weight:650; white-space:nowrap; }
.stock-balance { margin:0; text-align:center; color:var(--cold); font-size:.875rem; font-weight:700; line-height:1.25; font-variant-numeric:tabular-nums; }
.stock-balance.low { color:var(--warm); }
#stock-remaining { white-space:nowrap; }
.level-group { margin:0 0 14px; }
.level-group h3 { margin:0 0 6px; font-size:.875rem; font-weight:650; }
.level-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px; }
.level-row { position:relative; display:grid; place-items:center; min-height:46px; border-radius:7px; border:1px solid #4d6971; background:#293f4b; color:var(--text); font-size:1rem; font-weight:670; font-variant-numeric:tabular-nums; }
.level-row.active { outline:2px solid var(--cold); outline-offset:-2px; }
.level-row:not(:disabled):hover { border-color:var(--cold); }
.level-status { position:absolute; top:3px; right:5px; color:var(--cold); font-size:.75rem; }
.level-progress { color:var(--muted); margin:4px 0 0; font-size:.8125rem; }
.game { min-width:0; }
.info-panel { border:1px solid #49606b; border-radius:10px; background:linear-gradient(135deg,#293f4a70,#182a3460); overflow:hidden; }
.info-panel summary { flex-wrap:wrap; cursor:pointer; min-height:48px; display:flex; gap:12px; align-items:center; padding:12px 15px; font-size:14px; font-weight:550; list-style:none; }
.info-panel summary::-webkit-details-marker { display:none; }
.info-panel summary::after { content:'+'; margin-left:auto; color:var(--cold); font-size:21px; line-height:1; font-weight:400; }
.info-panel[open] summary::after { content:'−'; }
.info-panel[open] summary { border-bottom:1px solid #ffffff12; }
.summary-note { color:var(--muted); font-size:12px; font-weight:400; }
.panel-content { padding:3px 15px 15px; }
.panel-content p { font-size:14px; line-height:1.7; }
.subtle { color:var(--muted); font-size:13px!important; }
.board-frame { border:1px solid #768992; border-radius:16px; overflow:hidden; padding:4px; background:linear-gradient(135deg,#718590,#374d59 18%,#20333e 65%,#82949d); box-shadow:0 22px 40px #0004,inset 0 1px #d7e4e760,inset 0 -1px #0009; }
.board-wrap { position:relative; isolation:isolate; background:#172a35; }
#board { display:block; width:100%; height:auto; aspect-ratio:1; outline:none; touch-action:none; user-select:none; -webkit-user-select:none; cursor:crosshair; }
#board:focus-visible { box-shadow:inset 0 0 0 3px var(--cold); }
.repair-button,.outline-button { background:#ffc17d0c; color:var(--warm); border:1px solid #ffc17d70; border-radius:7px; padding:9px 12px; font-size:14px; }
.repair-button { flex-shrink:0; }
.dock { border:1px solid #67808c; border-radius:12px; padding:12px; background:linear-gradient(120deg,#2c424e,#20333e); box-shadow:0 10px 25px #0003,inset 0 1px #ffffff12; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }
.feedback { display:flex; align-items:flex-start; gap:10px; min-width:0; margin-bottom:11px; border-left:3px solid #7896a0; padding:2px 8px 2px 10px; }
.feedback[data-empty=true] { display:none; }
.feedback-copy { min-width:0; flex:1; overflow-wrap:anywhere; }
.feedback strong { display:block; font-size:14px; line-height:1.5; font-weight:600; }
.feedback p { font-size:13px; color:#c0d0d8; line-height:1.55; margin:3px 0 0; }
.feedback.error { border-color:var(--bad); }
.feedback.success { border-color:var(--cold); }
.locate-button { flex-shrink:0; background:#ffc17d0e; color:var(--warm); border:1px solid #ffc17d66; border-radius:6px; padding:5px 10px; line-height:1.35; font-size:12px; min-width:44px; }
.controls { display:flex; gap:9px; align-items:stretch; }
.primary { min-height:49px; border:1px solid #d9fff566; border-radius:8px; padding:12px 18px; background:linear-gradient(#a4f4df,#74d9c4 55%,#64baa9); color:#102c2b; font-size:15px; font-weight:650; box-shadow:inset 0 1px #effffb9c,0 3px 0 #1b554e,0 5px 10px #0003; line-height:1.4; }
.primary:hover { background:linear-gradient(#c3ffed,#8ce7d1); }
.controls .primary { flex:1; min-width:0; }
.primary>span { margin-right:6px; }
.tool { display:flex; align-items:center; justify-content:center; gap:7px; min-width:76px; border:1px solid #758995; border-radius:8px; padding:9px 12px; background:linear-gradient(#405a68,#2d4654); color:#e2edef; box-shadow:inset 0 1px #ffffff22,0 3px 0 #152934; }
.tool>span { font-size:23px; line-height:1; }
.tool small { font-size:13px; }
.tool[aria-pressed=true] { color:var(--warm); border-color:var(--warm); background:linear-gradient(#604d3f,#3a302c); box-shadow:inset 0 0 0 1px #ffc17d30; }
.quiet { background:transparent; color:#d0dde3; border-radius:7px; padding:10px 12px; font-size:14px; line-height:1.4; }
.quiet:hover { background:#ffffff09; }
#hint-button { color:var(--warm); }
.information-grid { display:grid; grid-template-columns:1fr; gap:10px; }
.menu-options { margin-top:8px; }
.flat-game .dock { margin-top:12px; }
.check { display:flex; align-items:flex-start; gap:9px; color:#c0d1d8; font-size:14px; line-height:1.6; padding:8px 0; }
.check i { display:grid; place-items:center; width:21px; height:21px; border:1px solid #7b929e; border-radius:50%; font-style:normal; font-size:13px; margin-top:1px; flex-shrink:0; }
.check.good { color:var(--cold); }
.check.good i { border-color:var(--cold); }
.check.bad { color:var(--bad); }
.check.bad i { border-color:var(--bad); }
.check small { margin-left:auto; flex-shrink:0; font-size:12px; }
#best-record { color:var(--warm); font-size:14px; line-height:1.8; padding:10px 0; }
#storage-warning { color:var(--warm); font-size:.8125rem; line-height:1.6; }
.motion-option { display:flex; align-items:center; gap:10px; min-height:44px; cursor:pointer; color:#c2d1d8; font-size:13px; margin-top:5px; }
.motion-option input { width:20px; height:20px; accent-color:var(--cold); margin:0; }
dialog { color:var(--text); background:linear-gradient(130deg,#2d4653,#1b303c); border:1px solid #8198a4; border-radius:16px; padding:22px; max-width:490px; width:calc(100% - 28px); max-height:calc(100svh - 32px); overflow:auto; box-shadow:0 24px 80px #0008,inset 0 1px #ffffff25; }
dialog::backdrop { background:#071117d9; backdrop-filter:blur(7px); }
#success-actions { position:fixed; inset:0; width:min(336px,calc(100% - 28px)); height:fit-content; margin:auto; text-align:center; }
#success-actions::backdrop { background:transparent; backdrop-filter:none; }
#success-title { margin:0 0 18px; font-size:24px; }
#success-actions > .primary { width:min(100%,152px); }
.dialog-head { position:sticky; top:-22px; z-index:2; display:flex; justify-content:space-between; align-items:flex-start; gap:16px; margin:-22px -22px 12px; padding:22px 22px 12px; background:linear-gradient(130deg,#2d4653,#233b47); border-bottom:1px solid #ffffff17; }
.dialog-head>div { flex:1; min-width:0; }
.dialog-head h2 { overflow-wrap:anywhere; }
.dialog-head h2 { font-size:23px; line-height:1.4; font-weight:600; margin:5px 0; }
.dialog-close { width:44px; height:44px; flex-shrink:0; border-radius:50%; background:#ffffff08; color:#dfebe9; border:1px solid #78909b; font-size:27px; }
.help-steps { font-size:15px; padding-left:23px; margin:18px 0; }
.help-steps li { padding:0 0 13px 5px; }
.help-steps p,dialog>p { font-size:14px; line-height:1.75; color:#c2d4dc; }
.help-steps p { margin:5px 0; }
.keyboard-help { font-size:12px; line-height:1.7; color:#bdcfd8; border-top:1px solid #ffffff18; padding-top:15px; }
.close-help { width:100%; margin-top:8px; }
.dialog-actions { display:flex; flex-wrap:wrap; justify-content:flex-end; gap:8px; margin-top:18px; }
svg text { font-family:inherit; pointer-events:none; }
#board .flow-line { stroke-dasharray:3 13; animation:flow-dash .9s linear infinite; pointer-events:none; }
#board .problem-pulse,#board .hint-mark { animation:pulse 1.4s ease-in-out infinite; }
@keyframes flow-dash { to { stroke-dashoffset:-32; } }
@keyframes pulse { 50% { opacity:.55; } }
@media (max-width:900px) {
  .flat-game { padding-bottom:calc(var(--dock-height,112px) + 12px); }
  .board-frame { width:100%; }
  .flat-game .dock { position:fixed; z-index:10; left:0; right:0; bottom:0; max-width:680px; margin:0 auto; padding:10px 12px calc(12px + env(safe-area-inset-bottom)); border-radius:14px 14px 0 0; border-bottom:0; max-height:64svh; overflow:auto; overscroll-behavior:contain; box-shadow:0 -8px 28px #0005,inset 0 1px #ffffff20; }
  .controls { gap:8px; }
  .controls .primary { min-height:48px; padding:10px; }
  .tool { min-width:68px; padding:9px 10px; }
  .information-grid { grid-template-columns:1fr; }
}
@media (max-width:430px) {
  .board-frame { border-radius:12px; padding:3px; }
  .controls { display:grid; grid-template-columns:minmax(126px,1fr) minmax(57px,max-content) minmax(57px,max-content); gap:7px; }
  .controls .primary { min-width:126px; overflow-wrap:anywhere; }
  .tool { min-width:57px; padding:7px 5px; gap:3px; flex-direction:column; }
  .tool>span { font-size:21px; }
  .tool small { font-size:12px; }
  .primary { font-size:14px; }
  .summary-note { font-size:12px; }
  dialog { padding:18px; }
  .dialog-head { top:-18px; margin:-18px -18px 12px; padding:18px 18px 10px; }
}
@media (max-width:350px) {
  .tool { min-width:57px; }
}
@media (max-height:500px) and (max-width:900px) {
  .dock { max-height:48svh; }
}
@media (prefers-reduced-motion:reduce) {
  *,*::before,*::after { animation:none!important; transition:none!important; scroll-behavior:auto!important; }
}
.reduce-motion *,.reduce-motion *::before,.reduce-motion *::after { animation:none!important; transition:none!important; scroll-behavior:auto!important; }

.tool>svg { width:22px; height:22px; flex-shrink:0; }
#draw-button[aria-pressed=true] { color:var(--cold); border-color:var(--cold); background:linear-gradient(#31584f,#27463f); box-shadow:inset 0 0 0 1px #83dfc526; }

:is(#hint-dialog,#stock-tip-dialog) p { font-size:15px; line-height:1.7; overflow-wrap:anywhere; }
#hint-go { min-height:44px; }

/* Match visual order to keyboard order, with reset in the first slot. */
#dock .play-actions {
  display:grid;
  grid-template-columns:repeat(5,minmax(0,1fr));
  align-items:stretch;
  gap:3px;
}
#dock .play-actions > .controls { display:contents; }
#dock .play-actions .tool {
  width:100%;
  min-width:0;
  min-height:52px;
  flex-direction:column;
  justify-content:center;
  gap:3px;
  padding:4px 0;
  border:0;
  border-radius:10px;
  background:transparent;
  color:var(--dock-icon,#dae7eb);
  box-shadow:none;
}
#dock .play-actions .tool > svg { width:20px; height:20px; }
#dock .play-actions .tool small { font-size:12px; line-height:1.2; font-weight:570; white-space:nowrap; }
#dock .play-actions .tool:active:not(:disabled) { background:var(--dock-hover,#ffffff13); }
@media (hover:hover) {
  #dock .play-actions .tool:hover:not(:disabled) { background:var(--dock-hover,#ffffff13); }
}
#dock .play-actions .tool[aria-pressed=true] {
  background:var(--dock-selected,#31584f);
  color:var(--dock-accent,#c1f5e8);
}
#dock #test-button { color:var(--dock-accent,#c1f5e8); }
#dock #reset-button { color:var(--dock-muted,#a4b8bf); }
:is(#reset-dialog, #hint-dialog, #stock-tip-dialog, #success-actions) > :is(#next-click-button, #next-click-message) { display:none; }

#campaign-archive { margin-top:16px; }
#campaign-archive select { display:block; max-width:100%; min-height:44px; margin:6px 0; font:inherit; }
#campaign-archive select[hidden] { display:none; }
.archive-best { display:flex; align-items:center; gap:8px; min-height:44px; }
#archive-board { display:block; width:min(100%,420px); height:auto; margin:auto; }
