:root {
  --bg: #eaf4ff;
  --panel: #ffffff;
  --ink: #1b2a3a;
  --muted: #5d6f82;
  --line: #d3dfec;
  --accent: #2b6cb0;
  --accent-ink: #ffffff;
  --sea: #3d86d6;
  --danger: #c0392b;
  --chip: #f1f6fc;
  --shadow: 0 -6px 24px rgba(20, 40, 70, 0.18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1a26;
    --panel: #18263a;
    --ink: #e8f0f8;
    --muted: #9db0c4;
    --line: #2c405a;
    --accent: #5aa2f0;
    --accent-ink: #0b1420;
    --sea: #1f4f8a;
    --danger: #ff6b5b;
    --chip: #213349;
    --shadow: 0 -6px 24px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1a26; --panel: #18263a; --ink: #e8f0f8; --muted: #9db0c4; --line: #2c405a;
  --accent: #5aa2f0; --accent-ink: #0b1420; --sea: #1f4f8a; --danger: #ff6b5b; --chip: #213349;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  background: var(--accent); color: var(--accent-ink);
}
#topbar .name {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 6px 4px;
  font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: inherit;
}
#topbar .status { font-size: 12px; opacity: 0.9; white-space: nowrap; }
.icon {
  width: 38px; height: 38px; border-radius: 10px; border: 0;
  background: rgba(255, 255, 255, 0.18); color: inherit; font-size: 18px; line-height: 1;
}
.icon:disabled { opacity: 0.35; }
#peekBtn[aria-pressed="false"] { opacity: 0.45; }

#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--sea); }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#hud {
  position: absolute; left: 8px; top: 8px; max-width: calc(100% - 70px);
  background: rgba(10, 20, 35, 0.72); color: #fff; padding: 5px 9px; border-radius: 9px;
  font-size: 13px; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#hud:empty { display: none; }
#zoomBtns { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; }
#zoomBtns .icon { background: rgba(10, 20, 35, 0.6); color: #fff; }

#dock {
  background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.palette {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 8px 4px; scrollbar-width: none;
}
.palette::-webkit-scrollbar { display: none; }
.swatch {
  flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 5px 9px 5px 5px;
  border-radius: 20px; border: 2px solid var(--line); background: var(--chip); font-size: 13px; white-space: nowrap;
}
.swatch i { width: 22px; height: 22px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
.swatch.on { border-color: var(--accent); background: var(--panel); font-weight: 700; }
.swatch.edit { padding: 5px 11px; }

.tools { display: flex; gap: 4px; overflow-x: auto; padding: 4px 6px; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.tool {
  flex: 1 0 58px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  border: 0; background: none; border-radius: 10px; padding: 5px 2px; font-size: 11px; color: var(--muted);
}
.tool b { font-size: 20px; font-weight: normal; line-height: 1.1; }
.tool.active { background: var(--chip); color: var(--ink); font-weight: 700; box-shadow: inset 0 0 0 2px var(--accent); }

#tabs { display: flex; border-top: 1px solid var(--line); }
#tabs button { flex: 1; border: 0; background: none; padding: 9px 2px; font-size: 13px; font-weight: 600; }

#scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.25); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 78vh; overflow-y: auto;
  background: var(--panel); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding: 4px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--panel); padding: 10px 0 6px; z-index: 1; }
.sheet h2 { margin: 0; font-size: 19px; }
.sheet h3 { margin: 18px 0 6px; font-size: 15px; }
.sheet .close { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 7px 14px; font-weight: 700; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }
.row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.row > span { flex: 0 0 104px; font-weight: 600; }
.row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.row input[type="number"], .row input:not([type]) {
  flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--chip);
}
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); margin-left: auto; }
.btnrow { display: flex; gap: 8px; margin: 8px 0; }
.btnrow button, .wide, .row > button, .nudge button, .seg button {
  border: 1px solid var(--line); background: var(--chip); border-radius: 10px; padding: 10px 12px; font-weight: 600;
}
.btnrow button { flex: 1; }
.wide { width: 100%; margin: 8px 0; }
.danger { color: var(--danger); }
.seg { display: flex; gap: 4px; flex: 1; }
.seg button { flex: 1; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.nudge { display: flex; gap: 6px; flex: 1; }
.nudge button { flex: 1; padding: 8px 0; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { display: flex; align-items: center; gap: 5px; background: var(--chip); border: 1px solid var(--line); border-radius: 18px; padding: 6px 10px; font-size: 13px; }

.blocklist, .designlist { list-style: none; margin: 0; padding: 0; }
.blocklist li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.blocklist input[type="color"] { width: 40px; height: 34px; border: 0; padding: 0; background: none; border-radius: 8px; }
.blocklist input[type="text"] { flex: 1; min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--chip); }
.blocklist .count { min-width: 38px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.blocklist button { border: 0; background: none; font-size: 16px; padding: 6px; color: var(--muted); }

.tracemap { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.tracemap label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.tracemap label span { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--ink); }
.tracemap label i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.tracemap select { padding: 7px; border-radius: 8px; border: 1px solid var(--line); background: var(--chip); color: var(--ink); font: inherit; }

.codebox { display: flex; align-items: center; justify-content: space-between; background: var(--chip); border-radius: 12px; padding: 12px 14px; margin: 8px 0; }
.codebox b { font-size: 22px; letter-spacing: 2px; font-family: ui-monospace, Menlo, monospace; }
.designlist li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.designlist li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.designlist li small { color: var(--muted); }
.designlist li.current span { font-weight: 700; }
.designlist button { border: 1px solid var(--line); background: var(--chip); border-radius: 8px; padding: 6px 10px; }
.help { padding-left: 20px; }
.help li { margin: 8px 0; }

#toast {
  position: fixed; left: 50%; bottom: 190px; transform: translateX(-50%); z-index: 20;
  background: rgba(10, 20, 35, 0.88); color: #fff; padding: 9px 14px; border-radius: 12px; font-size: 14px; max-width: 90vw; text-align: center;
}

@media (min-width: 760px) {
  .tool { flex: 0 0 74px; }
  .tools { justify-content: center; }
}

/* The Kanto sheet stays short and see-through so the map can be watched while adjusting it. */
#sheet-kanto { max-height: 46vh; }
#scrim.clear { background: transparent; }

.tool.brush b { font-weight: 800; font-size: 17px; min-width: 26px; border: 2px solid currentColor; border-radius: 6px; padding: 0 3px; }
.tool.brush { color: var(--ink); }
.btnrow button small { font-weight: 400; color: var(--muted); }
.select { flex: 1; min-width: 0; padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--chip); color: var(--ink); font: inherit; }

/* Floor planner */
#floorBar {
  position: absolute; left: 8px; right: 8px; top: 8px; z-index: 2; display: flex; align-items: center; gap: 8px;
  background: rgba(10, 20, 35, 0.82); color: #fff; border-radius: 12px; padding: 6px;
}
#floorBar span { flex: 1; min-width: 0; font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#floorBar button { border: 0; border-radius: 9px; padding: 7px 10px; font-weight: 700; background: rgba(255, 255, 255, 0.18); color: #fff; }
#stage.floor-mode #hud { top: 58px; }
#stage.floor-mode #zoomBtns { top: 58px; }
#tabs button { font-size: 12px; padding: 9px 1px; }
.building { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.floorchip { border: 1px solid var(--line); background: var(--chip); border-radius: 18px; padding: 7px 11px; font-size: 13px; font-weight: 600; }
.floorchip.started { box-shadow: inset 0 -3px 0 #2fae5a; }
.floorchip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#floorBar[hidden] { display: none; }
