:root {
  /* the dark look: Ashfall at night, lit by the furnace; the accent is the house amber (game-ui-colour §2) */
  --bg: #0b0d14;
  --bg2: #1b1a22;
  --ink: #e8e6ef;
  --accent: #ffb338;
  --accentLine: #ffd27a;
  --accentInk: #3a2204;
  --kInk1: #a4a2b5;
  --kInk2: #f5f3f9;
  --kLine1: #3a3546;
  --kLine2: #ffb338;
  --kBg2: #2c2420;
  --kBg3: #0b0d14;
  --kBg6: rgba(10, 9, 14, 0.9);
  --kBg9: #f5f3f9;
  --kInkG2: #0b0d14;
  --good: #7ad98a;
  --want: #ff8f6b;
}

/* R-C40: the light look */
:root[data-theme="light"] {
  --bg: #eef1f6;
  --bg2: #d9dde8;
  --ink: #16151c;
  --accent: #b26f00;
  --accentLine: #8a5600;
  --accentInk: #111111;
  --kInk1: #403e52;
  --kInk2: #0b0a10;
  --kLine1: #9c99ae;
  --kLine2: #b26f00;
  --kBg2: #ecdcc8;
  --kBg3: #dfe3ec;
  --kBg6: rgba(236, 239, 245, 0.94);
  --kBg9: #16151c;
  --kInkG2: #ffffff;
  --good: #1d7a32;
  --want: #b23a14;
}

* { 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); }
#saveNote { margin: 0 12px 6px; padding: 8px 12px; border-radius: 12px; background: var(--bg2); border: 2px solid var(--kLine1); color: var(--ink); font-weight: 800; font-size: 14px; line-height: 1.4; text-align: center; }
#saveNote[hidden] { display: none; }

.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(30px, 8.5vw, 42px); 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: 52px; font-size: 18px; font-weight: 800; background: var(--bg2); color: var(--ink); border: 3px solid var(--kLine1); cursor: pointer; font-family: inherit; padding: 4px 10px; }
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; }

#scr-play { padding: 0 6px 6px; gap: 6px; }
#playTop { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; padding: 2px 4px 0; min-height: 22px; font-variant-numeric: tabular-nums; }
#robotsOut { text-align: right; color: var(--kInk1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#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; cursor: pointer; }
#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; }

/* under the smithy: the order, what the anvil makes, and the four tabs */
#foot { flex: none; display: flex; flex-direction: column; gap: 6px; padding-bottom: max(2px, env(safe-area-inset-bottom)); }
#orderRow { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
#orderSay { font-size: 14px; font-weight: 700; line-height: 1.35; min-height: 38px; }
#orderSay b { color: var(--kInk2); }
#orderSay .have { color: var(--good); }
#orderSay .left { color: var(--want); }
#btnGive { width: auto; min-width: 104px; min-height: 48px; font-size: 16px; }
#goodsRow { display: flex; flex-wrap: wrap; gap: 6px; }
.good { flex: 1 1 52px; min-width: 52px; min-height: 48px; border-radius: 12px; border: 3px solid var(--kLine1); background: var(--bg2); color: var(--ink); font-family: inherit; font-weight: 800; font-size: 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; padding: 2px; }
.good b { font-size: 20px; }
.good.sel { border-color: var(--kLine2); background: var(--kBg2); }
#anvilSay { text-align: center; font-size: 13.5px; font-weight: 700; color: var(--kInk1); min-height: 18px; }
#tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tab { min-height: 44px; border-radius: 12px; border: 3px solid var(--kLine1); background: var(--bg2); color: var(--ink); font-family: inherit; font-weight: 800; font-size: 13px; cursor: pointer; padding: 0 2px; }
.tab:disabled { opacity: 0.35; cursor: default; }

/* a tab's sheet, over the smithy */
.ovl { position: absolute; inset: 0; display: none; align-items: flex-start; justify-content: center; background: var(--kBg6); border-radius: 12px; padding: 12px; overflow-y: auto; overscroll-behavior: contain; }
.ovl.on { display: flex; }
.sheetCard { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 8px; margin: auto; }
.sheetTop { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 18px; color: var(--kInk2); }
.sheetTop .pill { min-width: 44px; min-height: 44px; border-radius: 999px; border: 2px solid var(--kLine1); background: var(--bg2); color: inherit; font-size: 15px; cursor: pointer; }
#sheetBody { display: flex; flex-direction: column; gap: 8px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; background: var(--bg2); border: 2px solid var(--kLine1); border-radius: 12px; padding: 8px 10px; font-size: 14px; font-weight: 700; }
.item small { display: block; color: var(--kInk1); font-weight: 600; font-size: 12.5px; }
.item button { min-height: 44px; min-width: 88px; border-radius: 12px; border: 3px solid var(--accentLine); background: var(--accent); color: var(--accentInk); font-family: inherit; font-weight: 800; font-size: 14px; cursor: pointer; padding: 0 8px; }
.item button:disabled { opacity: 0.4; cursor: default; }
.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); }
#ovlSub { color: var(--kInk1); font-weight: 700; line-height: 1.4; }
#ovlRows .row { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; padding: 5px 10px; border-bottom: 1px solid var(--kLine1); text-align: left; }

#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); }
.legend { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.lgRow { font-size: 14px; font-weight: 700; }
#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: 190px; 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; } }
/* R6.7 the building bar, over the bottom of the floor (nothing below the picture moves) */
#buildBar { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 16px; background: var(--bg); border: 3px solid var(--kLine1); opacity: 0.96; }
#buildBar[hidden] { display: none; }
#buildSay { font-weight: 700; font-size: 14px; text-align: center; min-height: 1.3em; }

/* R10 (v1.3.0) walking: the pills over the picture's top right; the stick's ring under the finger */
#stagePills { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
#stagePills .pill { min-width: 44px; min-height: 44px; border-radius: 999px; border: 2px solid var(--kLine1); background: var(--bg2); color: inherit; font-size: 18px; cursor: pointer; opacity: 0.94; }
#stagePills .pill[hidden] { display: none; }
#walkRing { position: absolute; width: 140px; height: 140px; margin: -70px 0 0 -70px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.55); pointer-events: none; }
#walkRing[hidden] { display: none; }
#walkKnob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); }
#walkSay { position: absolute; left: 8px; right: 60px; top: 10px; font-weight: 700; font-size: 13px; color: #fff; text-shadow: 0 1px 3px #000; pointer-events: none; }
#walkSay[hidden] { display: none; }
#scr-play.walking #foot { visibility: hidden; }   /* its height kept, so the picture does not resize (R-C19) */
