*{box-sizing:border-box}
:root{--bg:#f6f7fb;--ink:#111;--muted:#6b7280;--card:#fff;--border:#e5e7eb}
body{margin:0;padding:0;background:var(--bg);color:var(--ink);font:14px/1.5 system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto}
.topbar{padding:18px 16px;border-bottom:1px solid var(--border);background:#fff;display:flex;justify-content:space-between;align-items:center;position:sticky;top:0;z-index:10}
.topbar h1{margin:0;font-size:20px}
.actions{display:flex;gap:8px;flex-wrap:wrap}
.actions button{padding:8px 12px;border:1px solid var(--border);background:#fff;border-radius:12px;cursor:pointer}
.actions button:hover{background:#f4f6ff}
.layout{display:grid;grid-template-columns:2fr 1fr;gap:16px;padding:16px;max-width:1200px;margin:0 auto}
@media(max-width:900px){.layout{grid-template-columns:1fr}}
.board h2,.palette h2,.narration h3,.output h3{margin:6px 0 10px}
.panels{display:grid;grid-template-columns:1fr 1fr;gap:12px}
@media(max-width:900px){.panels{grid-template-columns:1fr}}
.panel{background:#fff;border:1px solid var(--border);border-radius:16px;padding:12px;min-height:200px;display:flex;flex-direction:column;gap:8px}
.panel-head{display:flex;justify-content:space-between;align-items:center;color:var(--muted);font-size:12px}
.tokens{display:grid;gap:6px}
.token{display:flex;align-items:center;gap:8px;border:1px solid var(--border);background:#fff;border-radius:12px;padding:8px;cursor:grab}
.token .emoji{font-size:18px}
.badge{margin-left:auto;font-size:11px;padding:2px 6px;border:1px solid var(--border);border-radius:999px;color:#555}
.remove{margin-left:6px;font-size:11px;padding:2px 6px;border:1px solid var(--border);border-radius:8px;cursor:pointer;background:#fff}
.remove:hover{background:#f8fafc}
.caption{width:100%;border:1px solid var(--border);border-radius:12px;padding:8px;resize:vertical;min-height:60px}
.palette .group{margin-bottom:12px}
.group-head{display:flex;align-items:center;gap:6px;cursor:pointer;padding:6px 4px;border-radius:8px}
.group-head:hover{background:#f8fafc}
.group-head .caret{width:1em;display:inline-block;color:#555}
.group-head .title{font-weight:600}
.group-body{display:grid;gap:6px;margin-top:6px}
.group.collapsed .group-body{display:none}
.group h3{margin:8px 0 6px;font-size:14px}
.hint{color:var(--muted);font-size:12px}
.story-text{white-space:pre-wrap;background:#fff;border:1px solid var(--border);border-radius:12px;padding:8px;margin:0 16px}
.output{padding:12px 16px}
.raw,.err{white-space:pre-wrap;border:1px solid var(--border);border-radius:12px;background:#fff;padding:8px}
.err{border-color:#fecaca;background:#fee2e2;color:#b91c1c;margin-top:8px}
.modal{position:fixed;inset:0;background:rgba(0,0,0,.15);display:flex;align-items:center;justify-content:center}
.dialog{background:#fff;border:1px solid var(--border);border-radius:16px;padding:14px;width:520px;max-width:92vw}
.dialog label{display:block;margin:8px 0}
.dialog input,.dialog textarea{width:100%;padding:8px;border:1px solid var(--border);border-radius:10px}
.dialog .row{display:flex;gap:8px;margin-top:8px}
.small{font-size:12px;color:var(--muted)}
.shape-character{border-radius:999px}
.shape-place{border-radius:8px}
.shape-event{border-radius:2px}
.shape-prop{border-radius:14px}
.shape-emotion{border-radius:16px}
