:root {
  --bg: #0e0e11;
  --bar: #1b1b20;
  --line: #2c2c34;
  --text: #e8e8ee;
  --muted: #8a8a96;
  --accent: #8b7bff;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none; touch-action: none;
}
button { font: inherit; color: inherit; }

/* Idle: an empty black screen. Tap to reveal a tiny status line. */
#idle { position: fixed; inset: 0; display: grid; place-items: center; }
#idle .status, #idle #install { opacity: 0; transition: opacity .3s; }
#idle.reveal .status, #idle.reveal #install { opacity: 1; }
#idle .status { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
#idle #install { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom)); padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--bar); }
#idle #install[hidden], #idle #setup-link[hidden], #menu [hidden] { display: none; }
#idle #setup-link { position: absolute; bottom: calc(76px + env(safe-area-inset-bottom)); color: var(--accent); font-size: 14px; text-decoration: none; opacity: 0; transition: opacity .3s; }
#idle.reveal #setup-link { opacity: 1; }
#idle #setup-link, #idle #install { pointer-events: none; }
#idle.reveal #setup-link, #idle.reveal #install { pointer-events: auto; }
#menu a.row { color: var(--accent); text-decoration: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c0453a; }
body.online .dot { background: #3fb950; }
.txt-on { display: none; }
body.online .txt-on { display: inline; }
body.online .txt-off { display: none; }

#board { position: fixed; inset: 0; display: flex; flex-direction: column; }
#board[hidden], #idle[hidden] { display: none; }

#toolbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top));
  padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right));
  background: var(--bar); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none; flex-shrink: 0; touch-action: pan-x;
}
#toolbar::-webkit-scrollbar { display: none; }
#toolbar button {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer;
}
#toolbar button:active { background: #ffffff14; }
#toolbar button.on { background: #8b7bff2e; color: var(--accent); }
#toolbar button:disabled { opacity: .35; }
#toolbar button.text { width: auto; padding: 0 14px; background: var(--accent); color: #fff; font-weight: 600; }
#toolbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#toolbar svg circle { fill: currentColor; stroke: none; }
#toolbar svg .hl { stroke: #ffd60a; stroke-width: 3; }
#title { color: var(--muted); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; min-width: 0; }
.group { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.group[hidden] { display: none; }
.sep { width: 1px; height: 26px; background: var(--line); flex-shrink: 0; margin: 0 4px; }
.grow { flex: 1; }

#toolbar .swatch { width: 34px; height: 40px; }
#toolbar .swatch::before {
  content: ""; width: 22px; height: 22px; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 0 0 1px #ffffff30;
}
#toolbar .swatch.on::before { box-shadow: 0 0 0 2px var(--bar), 0 0 0 4px var(--text); }
#toolbar .swatch.custom { display: grid; place-items: center; position: relative; cursor: pointer; }
#toolbar .swatch.custom::before { background: conic-gradient(#f44, #fd4, #4f6, #4df, #64f, #f4d, #f44); }
#toolbar .swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
#toolbar .size i { display: block; border-radius: 50%; background: currentColor; }

#menu {
  position: fixed; right: 10px; top: calc(56px + env(safe-area-inset-top)); z-index: 10; width: 280px;
  background: var(--bar); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  box-shadow: 0 12px 40px #0009;
}
#menu[hidden] { display: none; }
#menu .row { display: flex; gap: 10px; align-items: center; width: 100%; padding: 10px; border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer; }
#menu .row:active { background: #ffffff14; }
#menu .danger { color: #ff7b72; }
#menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
#menu input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
#menu .hint { color: var(--muted); font-size: 12px; margin: 6px 10px 4px; }

#stage { position: relative; flex: 1; overflow: hidden; background: #2a2a30; touch-action: none; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#live { cursor: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(30px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #000c; color: #fff; padding: 8px 16px; border-radius: 20px; opacity: 0; transition: opacity .2s; pointer-events: none;
  z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; }
