:root {
  /* the dark look: a Deepwing depot at night; the accent is the house amber (game-ui-colour §2) */
  --bg: #0b0e14;
  --bg2: #171c26;
  --ink: #e4e8ef;
  --accent: #ffb338;
  --accentLine: #ffd27a;
  --accentInk: #3a2204;
  --kInk1: #9aa4b5;
  --kInk2: #f3f5f9;
  --kLine1: #2c3444;
  --kLine2: #ffb338;
  --kBg2: #2a2a20;
  --kBg3: #0b0e14;
  --kBg6: rgba(8, 10, 16, 0.88);
  --kBg9: #f3f5f9;
  --kInkG2: #0b0e14;
  --star: #ffc63a;
}

/* R-C40: the light look */
:root[data-theme="light"] {
  --bg: #e8edf3;
  --bg2: #cfd6e0;
  --ink: #161a22;
  --accent: #b26f00;
  --accentLine: #8a5600;
  --accentInk: #111111;
  --kInk1: #3b4454;
  --kInk2: #0a0d12;
  --kLine1: #97a2b3;
  --kLine2: #b26f00;
  --kBg2: #ece2c6;
  --kBg3: #dfe5ee;
  --kBg6: rgba(232, 237, 243, 0.92);
  --kBg9: #161a22;
  --kInkG2: #ffffff;
  --star: #8a5600;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: manipulation; overflow: hidden;
}
#app { height: 100%; display: flex; flex-direction: column; max-width: min(100%, 820px); margin: 0 auto; }
#hdr { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
#hdr .pill { background: var(--bg2); border: 2px solid var(--kLine1); border-radius: 999px; padding: 6px 11px; font-weight: 800; font-size: 15px; min-width: 44px; min-height: 44px; display: flex; align-items: center; cursor: pointer; justify-content: center; color: inherit; font-family: inherit; }
#hdrStatus { flex: 1; min-width: 0; text-align: center; font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--kInk1); }

.scr { flex: 1; display: none; flex-direction: column; overflow-y: auto; padding: 6px 14px 18px; }
.scr.on { display: flex; }
#scr-menu { align-items: center; text-align: center; gap: 12px; }
#scr-menu h1 { font-size: clamp(32px, 9vw, 44px); color: var(--kInk2); display: flex; align-items: center; gap: 10px; margin-top: 6px; }
#scr-menu h1 .logo { width: 1.1em; height: 1.1em; }
#scr-menu .sub { color: var(--kInk1); font-weight: 600; }
button.big { width: 100%; border-radius: 16px; min-height: 56px; font-size: 19px; font-weight: 800; background: var(--bg2); color: var(--ink); border: 3px solid var(--kLine1); cursor: pointer; font-family: inherit; }
button.big:active { transform: translateY(2px); }
button.big.primary { background: var(--accent); border-color: var(--accentLine); color: var(--accentInk); }
button.big:disabled { opacity: 0.5; }
/* the armed 🧹 Start over (start-over.js adds .danger): outlined in the accent, the fill unchanged */
button.big.danger { border-color: var(--accent); }
.menuRow { display: flex; gap: 8px; width: 100%; }
#statsLine { color: var(--kInk1); font-weight: 700; font-size: 14px; }
#needs { color: var(--kInk2); font-weight: 700; font-size: 14px; line-height: 1.4; }
#needs[hidden] { display: none; }
#depots { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.depot { background: var(--bg2); border: 3px solid var(--kLine1); border-radius: 16px; padding: 10px; text-align: left; }
.depot h2 { font-size: 16px; color: var(--kInk2); margin-bottom: 8px; }
.loads { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.load { min-height: 48px; min-width: 44px; border-radius: 10px; border: 2px solid var(--kLine1); background: var(--bg); color: var(--ink); font-family: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 2px; }
.load b { font-size: 14px; font-weight: 800; }
.load small { font-size: 11px; color: var(--star); letter-spacing: -1px; }
.load:disabled { opacity: 0.45; cursor: default; }
@media (max-width: 359px) { .loads { grid-template-columns: repeat(4, 1fr); } }

#scr-play { padding: 0 6px 6px; }
#playTop { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; padding: 2px 4px 6px; min-height: 22px; }
#loadName { color: var(--kInk2); }
#movesOut { color: var(--kInk1); }
#bestOut { color: var(--star); white-space: nowrap; }
#stageWrap { flex: 1; position: relative; min-height: 0; border-radius: 12px; overflow: hidden; background: var(--kBg3); }
canvas#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#glFail { position: absolute; inset: 16px; display: flex; align-items: center; justify-content: center; text-align: center; font-weight: 800; font-size: 16px; line-height: 1.5; color: var(--kInk2); background: var(--kBg6); border-radius: 12px; padding: 12px; }
#glFail[hidden] { display: none; }
#fpsNow { position: absolute; left: 6px; bottom: 6px; font: 11px/1.3 ui-monospace, monospace; color: var(--kInk1); background: var(--kBg6); padding: 2px 6px; border-radius: 6px; pointer-events: none; }
#fpsNow[hidden] { display: none; }

/* the footer: Undo and Restart, then one line on how to drive (game-controls §2, §3) */
#foot { flex: none; display: flex; flex-direction: column; gap: 6px; padding: 8px 0 max(4px, env(safe-area-inset-bottom)); }
.btnRow { display: flex; gap: 6px; }
.pb { flex: 1; min-height: 48px; border-radius: 14px; background: var(--bg2); border: 3px solid var(--kLine1); color: var(--ink); font-size: 17px; font-weight: 800; font-family: inherit; cursor: pointer; }
.pb:disabled { opacity: 0.45; }
#hint { text-align: center; font-weight: 700; font-size: 14px; color: var(--kInk1); min-height: 20px; }
#stickKnob { position: absolute; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: var(--accent); opacity: 0.7; pointer-events: none; }
#stickKnob[hidden] { display: block; visibility: hidden; }

.ovl { position: absolute; inset: 0; display: none; align-items: flex-start; justify-content: center; background: var(--kBg6); border-radius: 12px; padding: 16px; overflow-y: auto; overscroll-behavior: contain; }
.ovl.on { display: flex; }
.ovlCard { text-align: center; width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; margin: auto; }
#ovlTitle { font-size: 24px; font-weight: 800; color: var(--kInk2); }
#ovlStars { font-size: 34px; color: var(--star); letter-spacing: 4px; }
#ovlSub { color: var(--kInk1); font-weight: 700; line-height: 1.4; }

#scr-how .card, #scr-set .card { background: var(--bg2); border: 3px solid var(--kLine1); border-radius: 16px; padding: 14px; margin-bottom: 10px; font-size: 15px; line-height: 1.55; font-weight: 600; }
#scr-how h2, #scr-set h2 { margin-bottom: 8px; color: var(--kInk2); }
#scr-how p { margin-bottom: 6px; }
#scr-set .card { display: flex; flex-direction: column; gap: 12px; }
.setRow { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1; min-height: 44px; min-width: 64px; border-radius: 12px; border: 3px solid var(--kLine1); background: var(--bg); color: var(--ink); font: 800 15px inherit; font-family: inherit; cursor: pointer; padding: 0 6px; }
.seg button.sel { border-color: var(--kLine2); background: var(--kBg2); }
.setNote { font: 12px/1.4 ui-monospace, monospace; color: var(--kInk1); }
.setNote2 { font-size: 14px; color: var(--kInk1); line-height: 1.4; }
.startRow { display: flex; gap: 8px; }

#toast { position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); background: var(--kBg9); color: var(--kInkG2); font-weight: 800; padding: 9px 16px; border-radius: 999px; opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 40; max-width: 90%; text-align: center; }
#toast.on { opacity: 1; }
html, body { overflow: hidden; overscroll-behavior: none; }
.scr { overscroll-behavior: contain; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
