* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: #1f2330; color: #e8eaf0; }
[hidden] { display: none !important; }
.muted { color: #9aa1b5; }
.small { font-size: 12px; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 8px 12px; background: #4f7cff; color: white; }
button:hover { filter: brightness(1.1); }
input { font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid #3a4052; background: #151823; color: inherit; }
input:focus { outline: 2px solid #4f7cff; border-color: transparent; }

#join { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 30% 20%, #2c3550, #171a24); }
.card { width: min(420px, 92vw); background: #232838; padding: 28px; border-radius: 16px; box-shadow: 0 20px 60px #0008; display: flex; flex-direction: column; gap: 12px; }
.card h1 { margin: 0; font-size: 24px; }
.card p { margin: 0; }
.card label, .label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
#swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.swatch.on { border-color: white; }

#app { display: flex; height: 100vh; }
#stage { flex: 1; position: relative; overflow: hidden; background: #11131a; }
#game { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
#hint { position: absolute; left: 12px; bottom: 12px; background: #000a; padding: 6px 10px; border-radius: 8px; font-size: 12px; pointer-events: none; }

#side { width: 320px; display: flex; flex-direction: column; background: #232838; border-left: 1px solid #333a4d; }
#side header { padding: 16px; border-bottom: 1px solid #333a4d; }
#side h2 { margin: 2px 0 10px; font-size: 20px; }
.controls { display: flex; gap: 8px; }
#mic-btn.on { background: #2f9e62; }
#mic-btn.muted { background: #c2453d; }
#mic-btn:disabled { background: #3a4054; color: #b8bfd0; cursor: default; }
.demo-note { background: #2f3a5c; border: 1px solid #4f7cff55; border-radius: 8px; padding: 8px 10px; color: #dfe5f5; }
.demo-cta { display: block; margin-top: 12px; padding: 9px 12px; border-radius: 8px; background: #f7c548; color: #1f2330; font-weight: 600; text-align: center; text-decoration: none; }
.demo-cta:hover { background: #ffd666; }
#demo-back a { color: #9fb6ff; }
.badge.npc { background: #4b5263; color: #e6e9f2; }
#side section { padding: 12px 16px; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #9aa1b5; margin-bottom: 8px; }
#people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow: auto; }
#people li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.speaking { box-shadow: 0 0 0 3px #43d17a; }
#chat { flex: 1; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid #333a4d; }
#chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 6px; font-size: 14px; padding-bottom: 8px; }
.msg b { margin-right: 6px; }
.sys { color: #9aa1b5; font-style: italic; font-size: 12px; }
#side footer { padding: 8px 16px; border-top: 1px solid #333a4d; }

/* ---------- Mode builder ---------- */
button.ghost { background: #353c52; }
button.danger { background: #c2453d; }
button.small { font-size: 12px; padding: 6px 10px; }
#build-btn.on { background: #f59e0b; color: #1f2330; }
#builder { position: absolute; top: 12px; left: 12px; width: 300px; max-height: calc(100% - 64px); overflow: auto; background: rgba(35, 40, 56, 0.96);
  border: 1px solid #3a4052; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 30px #0007; }
.b-head { display: flex; align-items: center; justify-content: space-between; cursor: grab; user-select: none; touch-action: none;
  margin: -12px -12px 0; padding: 12px 12px 0; }
.b-head.grabbing { cursor: grabbing; }
.b-head .grip { color: #6b7aa6; margin-right: 6px; letter-spacing: -2px; }
.b-head button { padding: 4px 10px; font-size: 12px; }
#b-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
#b-tabs button { padding: 4px 9px; font-size: 12px; background: #353c52; }
#b-tabs button.on { background: #4f7cff; }
#b-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
#b-grid canvas { width: 48px; height: 48px; background: #2e3446; border-radius: 8px; border: 2px solid transparent; cursor: pointer; image-rendering: pixelated; }
#b-grid canvas:hover { border-color: #6b7aa6; }
#b-grid canvas.on { border-color: #f59e0b; background: #3a3420; }
#b-sel { border-top: 1px solid #3a4052; padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
#b-sel-name { font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: auto; }
.b-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.b-actions button { font-size: 12px; padding: 6px 9px; }
.b-help { line-height: 1.5; }

#admin-login { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(360px, 90%); z-index: 5; }
.error { color: #f87171; min-height: 1em; }
.badge { font-size: 11px; background: #f59e0b; color: #1f2330; border-radius: 6px; padding: 1px 6px; }
