:root {
  --bg: #1d2b22; --card: rgba(20, 30, 24, 0.92); --ink: #eef3e8; --muted: #a9b8a4;
  --accent: #c9e27a; --accent-ink: #1d2b22; --danger: #e07a5f; --line: rgba(255,255,255,0.12);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button, .btn { font: inherit; border: 0; border-radius: 12px; padding: 12px 16px; background: var(--accent);
  color: var(--accent-ink); font-weight: 600; cursor: pointer; text-decoration: none; text-align: center; display: inline-block; }
button.ghost, .btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
input, textarea { font: inherit; width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0,0,0,0.3); color: var(--ink); }

.panel { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 32px));
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 24px; backdrop-filter: blur(8px); }
.panel h1 { margin: 0 0 6px; font-size: 28px; }
.panel form { display: grid; gap: 10px; margin-top: 16px; }
.sub { color: var(--muted); margin: 0; }
.msg { min-height: 1.4em; margin: 12px 0 0; color: var(--accent); }
.msg.err { color: var(--danger); }
.fine { font-size: 13px; color: var(--muted); margin: 16px 0 0; }
.fine a { color: var(--muted); }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#stats { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; display: flex; gap: 8px; }
#stats span { background: var(--card); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; font-size: 15px; }
#online { color: var(--muted); }
#top-buttons { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }
#top-buttons button { width: 44px; height: 44px; padding: 0; background: var(--card); color: var(--ink); border: 1px solid var(--line); font-size: 20px; }
#hint { position: absolute; top: calc(max(12px, env(safe-area-inset-top)) + 52px); left: 50%; transform: translateX(-50%);
  color: var(--muted); font-size: 13px; text-align: center; pointer-events: none; width: calc(100% - 32px); }
#action { position: absolute; right: 20px; bottom: calc(28px + env(safe-area-inset-bottom)); padding: 16px 22px; border-radius: 999px;
  font-size: 17px; box-shadow: 0 6px 24px rgba(0,0,0,0.35); }
#stick { position: absolute; left: 24px; bottom: calc(24px + env(safe-area-inset-bottom)); width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,0.08); border: 1px solid var(--line); touch-action: none; }
#knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,0.35); pointer-events: none; }
@media (hover: hover) and (pointer: fine) { #stick { display: none; } }
#toast { position: absolute; left: 50%; bottom: calc(170px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--card);
  border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; opacity: 0; transition: opacity .3s; pointer-events: none; white-space: nowrap; }
#toast.show { opacity: 1; }

#thought { position: fixed; left: 0; right: 0; top: 18%; text-align: center; padding: 0 28px; pointer-events: none; }
#thought p { font-family: Georgia, "Iowan Old Style", serif; font-style: italic; font-size: clamp(20px, 5vw, 30px); margin: 0 auto;
  max-width: 640px; text-shadow: 0 2px 16px rgba(0,0,0,0.8); transition: opacity 1.2s; }
#thought small { color: var(--muted); display: block; margin-top: 12px; text-shadow: 0 1px 6px #000; }

.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.35); padding: 16px; }
.card { width: min(480px, 100%); max-height: calc(100% - 32px); overflow: auto; background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; padding: 20px; display: grid; gap: 10px; }
.card h2 { margin: 0; }
.row { display: flex; gap: 8px; } .row > * { flex: 1; }
pre#code { margin: 0; background: #0e1511; color: #d6f5a8; padding: 14px; border-radius: 12px; overflow-x: auto;
  font: 14px/1.5 ui-monospace, "SF Mono", Menlo, monospace; }
#question { margin: 0; font-weight: 600; }
#options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#options button { background: rgba(255,255,255,0.08); color: var(--ink); border: 1px solid var(--line); font-family: ui-monospace, Menlo, monospace; }
#options button.right { background: var(--accent); color: var(--accent-ink); }
#options button.wrong { background: var(--danger); color: #fff; }
#verdict { margin: 0; min-height: 1.4em; color: var(--muted); }
#streak { font-size: 14px; color: var(--accent); font-weight: 400; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.item .sw { width: 28px; height: 28px; border-radius: 8px; flex: none; display: grid; place-items: center; }
.item .nm { flex: 1; } .item .nm small { display: block; color: var(--muted); }
.item button { padding: 8px 12px; }
button:disabled { opacity: 0.45; cursor: default; }
#hb { position: absolute; right: 24px; bottom: calc(100px + env(safe-area-inset-bottom)); width: 64px; height: 64px; border-radius: 50%;
  padding: 0; font-size: 26px; background: var(--card); border: 1px solid var(--line); touch-action: none; }
#speed { position: absolute; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--line); padding: 6px 14px; border-radius: 999px; font-variant-numeric: tabular-nums; }
#boom { position: fixed; left: 0; right: 0; top: 22%; text-align: center; padding: 0 24px; pointer-events: none; text-shadow: 0 2px 18px #000; }
#boom h2 { margin: 0; font-size: clamp(48px, 14vw, 96px); color: #ffb347; letter-spacing: 2px; }
#boom p { font-family: Georgia, serif; font-style: italic; font-size: clamp(18px, 4.5vw, 24px); max-width: 560px; margin: 8px auto; }
#boom b { color: var(--accent); font-size: 20px; }
#boom.pop h2 { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#chatbar { position: absolute; left: 12px; right: 12px; bottom: calc(160px + env(safe-area-inset-bottom)); display: flex; gap: 8px;
  align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 8px; max-width: 560px; margin: 0 auto; }
#chatbar input { flex: 1; padding: 10px 12px; }
#chatbar button { padding: 10px 14px; }
#chat-count { color: var(--muted); font-size: 12px; min-width: 2.2em; text-align: right; font-variant-numeric: tabular-nums; }
@media (hover: hover) and (pointer: fine) { #chatbar { bottom: 24px; } }

/* Desktop mouse: no accidental text selection while dragging to look, clear affordances. */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, pre#code, .panel .fine, #privacy { -webkit-user-select: text; user-select: text; }
button, .btn { touch-action: manipulation; transition: filter .12s, transform .06s; }
button:not(:disabled) { cursor: pointer; }
@media (hover: hover) { button:not(:disabled):hover, .btn:hover { filter: brightness(1.12); } }
button:not(:disabled):active, .btn:active { transform: scale(0.96); }
button:focus { outline: none; }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
canvas#scene { cursor: grab; }
canvas#scene:active { cursor: grabbing; }

#boombox h3 { margin: 16px 0 6px; } #boombox .fine { font-size: 13px; color: var(--muted); }
#bb-library, #bb-pack-items { display: grid; gap: 8px; max-height: 40vh; overflow: auto; }
#bb-form { display: grid; gap: 8px; } textarea { resize: vertical; box-sizing: border-box; }
