:root {
  --bg: #05060d;
  --panel: rgba(15, 17, 30, 0.92);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9edf8;
  --dim: #8f97b2;
  --accent: #ff8a3d;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); overflow: hidden; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- stage ---------- */
#stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: radial-gradient(120% 90% at 50% 40%, #0b0e1c 0%, #05060d 70%); }
#board { position: relative; overflow: hidden; touch-action: none; cursor: crosshair; box-shadow: 0 0 0 1px rgba(255,255,255,0.05), 0 12px 60px rgba(0,0,0,0.6); }
#sim { position: absolute; left: 0; top: 0; width: 100%; height: 100%; image-rendering: crisp-edges; image-rendering: pixelated; display: block; }
#glow { position: absolute; left: 0; top: 0; pointer-events: none; mix-blend-mode: screen; image-rendering: auto; opacity: 0.95; }
#brush { position: absolute; left: 0; top: 0; border-radius: 50%; pointer-events: none; display: none;
  border: 1.5px solid rgba(255, 255, 255, 0.85); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(0, 0, 0, 0.25); transform: translate(-50%, -50%); }

#hud { position: absolute; left: 12px; top: 10px; display: flex; align-items: baseline; gap: 10px; pointer-events: none;
  padding: 5px 10px; border-radius: 999px; background: rgba(8, 9, 18, 0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border: 1px solid var(--line); }
.logo { font-size: 12px; letter-spacing: 0.22em; font-weight: 800; background: linear-gradient(90deg, #ffd27a, #ff7a2f 60%, #ff4d4d); -webkit-background-clip: text; background-clip: text; color: transparent; }
#stats { font-family: var(--mono); font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
#paused { position: absolute; right: 12px; top: 10px; padding: 5px 12px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 0.2em;
  color: #111; background: var(--accent); pointer-events: none; box-shadow: 0 0 24px rgba(255, 138, 61, 0.5); }
#paused[hidden] { display: none; }
#hint { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: calc(100% - 24px); text-align: center; pointer-events: none;
  padding: 7px 14px; border-radius: 999px; font-size: 12px; color: #cfd5ea; background: rgba(8, 9, 18, 0.7); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line); transition: opacity 0.8s ease; animation: hintIn 0.8s 0.4s both; }
#hint.gone { opacity: 0; }
@keyframes hintIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
kbd { font-family: var(--mono); font-size: 10px; padding: 1px 5px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }

/* ---------- dock ---------- */
#dock { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(20, 22, 38, 0.96), var(--panel)); border-top: 1px solid var(--line); }
#palette { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; width: 100%; max-width: 1240px; }
.chip { position: relative; flex: 0 0 auto; width: 66px; height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 4px 2px 3px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.035); color: var(--dim); cursor: pointer;
  font: 600 11px/1 var(--sans); transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.2s ease, border-color 0.15s ease; }
.chip:hover { background: rgba(255, 255, 255, 0.075); color: var(--text); transform: translateY(-1px); }
.chip:focus-visible, .btn:focus-visible, #size:focus-visible { outline: 2px solid #9db8ff; outline-offset: 2px; }
.chip .sw { width: 26px; height: 22px; border-radius: 7px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22), inset 0 -6px 8px rgba(0, 0, 0, 0.25); }
.chip .nm { letter-spacing: 0.01em; white-space: nowrap; }
.chip .nm.long { letter-spacing: -0.03em; font-size: 10px; }
.chip kbd { position: absolute; right: 4px; top: 3px; font-size: 9px; padding: 0 3px; opacity: 0.6; border-color: rgba(255,255,255,0.14); background: none; text-transform: uppercase; }
.chip[aria-pressed="true"] { color: #fff; background: rgba(255, 255, 255, 0.11); border-color: var(--c, #fff); box-shadow: 0 0 0 1px var(--c, #fff), 0 0 22px -2px var(--c, #fff); transform: translateY(-2px); }

#controls { display: flex; flex-wrap: nowrap; align-items: center; justify-content: center; gap: 8px; width: 100%; max-width: 760px; }
.size { flex: 1 1 260px; display: flex; align-items: center; gap: 10px; min-width: 0; height: 40px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.035); }
.size .lbl { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.size output { font-family: var(--mono); font-size: 12px; min-width: 2ch; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
#size { flex: 1; min-width: 40px; height: 24px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
#size::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, #ff8a3d, #ff4d6d); }
#size::-moz-range-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, #ff8a3d, #ff4d6d); }
#size::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 3px rgba(255, 138, 61, 0.35), 0 2px 6px rgba(0,0,0,0.5); }
#size::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 3px rgba(255, 138, 61, 0.35), 0 2px 6px rgba(0,0,0,0.5); }

.btn { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 40px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--text); cursor: pointer; font: 600 13px/1 var(--sans); transition: background 0.15s ease, transform 0.1s ease; }
.btn:hover { background: rgba(255, 255, 255, 0.11); }
.btn:active { transform: scale(0.96); }
#pause[aria-pressed="true"] { background: var(--accent); color: #1a1006; border-color: var(--accent); }
#pause .ic-play { display: none; }
#pause[aria-pressed="true"] .ic-play { display: block; }
#pause[aria-pressed="true"] .ic-pause { display: none; }
#clear:hover { background: rgba(255, 80, 80, 0.22); }

/* ---------- small screens ---------- */
@media (max-width: 700px) {
  #dock { gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  #palette { gap: 5px; }
  .chip { width: calc((100% - 5 * 5px) / 6); height: 50px; gap: 3px; border-radius: 10px; font-size: 10px; }
  .chip .sw { width: 24px; height: 19px; }
  .chip kbd { display: none; }
  .size { padding: 0 10px; gap: 8px; height: 42px; }
  .size .lbl { display: none; }
  .btn { width: 44px; height: 42px; padding: 0; }
  .btn .txt { display: none; }
  #hint { font-size: 11px; padding: 6px 12px; }
  #hud { left: 8px; top: 8px; }
}
@media (hover: none) { .chip kbd { display: none; } #hint kbd { display: none; } }
@media (max-height: 520px) { #hint { display: none; } }
@media (prefers-reduced-motion: reduce) { .chip, .btn, #hint { transition: none; animation: none; } }
