:root {
  --ink: #1C2130;
  --muted: #5A6070;
  --line: #D5D9E0;
  --line-strong: #C5CAD4;
  --ground: #EEF0F3;
  --panel: #FFFFFF;
  --soft: #F7F8FA;
  --soft2: #E4E7EC;
  --accent: #2F5BD3;
  --accent-dark: #1E3F9E;
  --accent-soft: #E8EEFC;
  --gold: #F2C85B;
  --gold-edge: #B68A1E;
  --gold-ink: #3A2A00;
  --slate: #3B4A6B;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --warn-ink: #8A4B00;
  --chrome: #1C2130;
  --chrome-2: #2C3448;
  --marker: 'Permanent Marker', cursive;
  --typewriter: 'Courier Prime', monospace;
  --page: 'Literata', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 15px/1.45 'IBM Plex Sans', system-ui, sans-serif; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
button { font: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

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

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink); font-weight: 500; font-size: 14px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--line-strong); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-primary:disabled:hover { background: var(--accent); color: #fff; }
.btn-dark { background: var(--chrome); border-color: #4A5368; color: #fff; }
.btn-dark:hover { background: var(--chrome-2); color: #fff; border-color: #4A5368; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8F1C13; color: #fff; border-color: #8F1C13; }
.btn-sm { min-height: 40px; padding: 0 14px; }
.btn-icon { padding: 0 12px; }
.linkbtn { background: none; border: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; font-size: 13px; }
.linkbtn:hover { color: var(--accent-dark); text-decoration: underline; }

.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 8px; background: var(--ground); }
.seg button { min-height: 36px; padding: 0 14px; border: none; background: transparent; border-radius: 6px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(28,33,48,.18); }

/* ---------- top bar ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 20px; padding: 0 20px; background: var(--chrome); }
.brand { display: flex; align-items: center; gap: 10px; height: 60px; }
.brand-name { font-weight: 700; font-size: 17px; color: #fff; }
.title-input { width: 230px; min-height: 40px; padding: 0 10px; border-radius: 6px; border: 1px solid transparent; background: var(--chrome-2); color: #fff; font: 600 16px 'IBM Plex Sans', sans-serif; }
.title-input:focus { outline: 2px solid var(--gold); }
.header-coin { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px 0 4px; border-radius: 20px; border: 1px solid #4A5368; background: transparent; color: #fff; font-size: 13px; font-weight: 500; cursor: pointer; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; flex: 1 1 auto; }
.tab { display: inline-flex; align-items: center; height: 44px; padding: 0 16px; border: none; border-radius: 8px 8px 0 0; background: transparent; font-size: 14px; font-weight: 500; color: #C9CEDA; cursor: pointer; }
.tab:hover { color: #fff; }
.tab[aria-current="page"] { background: var(--ground); color: var(--ink); }
.tab:disabled { color: #7F879A; cursor: not-allowed; }
.topbar-right { display: flex; align-items: center; height: 60px; }
.export { position: relative; }
.export-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(20, 25, 40, .18); padding: 6px; display: flex; flex-direction: column; }
.export-menu[hidden] { display: none; }
.export-menu button { all: unset; box-sizing: border-box; display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; border-radius: 7px; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; }
.export-menu button span { font-weight: 400; color: var(--muted); font-size: 13px; }
.export-menu button:hover, .export-menu button:focus-visible { background: var(--accent-soft); }

.body { flex: 1 1 auto; min-height: 0; display: flex; }
.view { flex: 1 1 auto; min-width: 0; display: flex; min-height: 0; }

/* ---------- coins ---------- */
.coin { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; font: 700 12px 'IBM Plex Sans', sans-serif; padding: 0; cursor: pointer; border: 2px dashed var(--muted); background: transparent; color: var(--muted); }
.coin.a { background: var(--gold); border: 2px solid var(--gold-edge); color: var(--gold-ink); }
.coin.b { background: var(--slate); border: 2px solid var(--chrome); color: #fff; }
.coin.sm { width: 24px; height: 24px; font-size: 10px; }
.coin.static { cursor: default; }

/* ---------- panels ---------- */
.col { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.col-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.col-title { font-size: 15px; font-weight: 600; }
.col-sub { font-size: 12px; color: var(--muted); }
.scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.empty { padding: 28px; border-radius: 10px; border: 2px dashed #9AA1B0; text-align: center; color: var(--muted); font-size: 14px; }
.help { font-size: 12px; color: var(--muted); line-height: 1.4; }
.k { font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }

/* ---------- start ---------- */
.start { flex: 1; overflow-y: auto; padding: 40px 48px; }
.start-inner { max-width: 960px; display: flex; flex-direction: column; gap: 28px; }
.start h1 { margin: 0; font-size: 32px; }
.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.story-card { position: relative; display: flex; flex-direction: column; gap: 12px; padding: 20px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); text-align: left; cursor: pointer; min-height: 200px; color: var(--ink); }
.story-card:hover { border-color: var(--accent); box-shadow: 0 6px 20px rgba(28,33,48,.10); }
.story-card.new { border: 2px dashed #9AA1B0; background: transparent; align-items: center; justify-content: center; text-align: center; }
.story-card .t { font-size: 18px; font-weight: 600; line-height: 1.3; padding-right: 40px; }
.story-card .meta { font-size: 13px; color: var(--muted); }
.story-del { position: absolute; top: 12px; right: 12px; }
.plus-disc { display: flex; align-items: center; justify-content: center; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); }
.pips { margin-top: auto; display: flex; justify-content: space-between; }
.pip { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #9AA1B0; }
.dot.on { background: var(--accent); border-color: var(--accent); }
.profile-card { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; padding: 20px 24px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }

/* ---------- magic moments ---------- */
.flowcol { flex: 0 0 340px; border-right: 1px solid var(--line); }
.flow-locked { flex: 0 0 180px; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 16px; background: var(--soft2); border-right: 1px solid var(--line); text-align: center; }
.flow-list { list-style: none; margin: 0; padding: 14px 18px 40px; background: var(--soft); display: flex; flex-direction: column; min-height: 100%; }
.flow-list .link { align-self: center; width: 2px; height: 16px; background: #9AA1B0; }
.drop-line { height: 4px; border-radius: 2px; background: var(--accent); margin: 4px 0; }
.drop-zone { display: flex; align-items: center; justify-content: center; min-height: 64px; margin-top: 12px; border-radius: 6px; border: 2px dashed #9AA1B0; color: var(--muted); font-size: 13px; }
.fcard { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px; border-radius: 3px; box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 6px 14px -6px rgba(28,33,48,.3); cursor: grab; user-select: none; }
.fcard.sel, .note.sel { outline: 3px solid var(--accent); outline-offset: 3px; }
.fcard.flag { outline: 3px solid var(--chrome); outline-offset: 2px; }
.fcard-top { display: flex; align-items: center; gap: 8px; }
.fcard-num { font: 700 12px 'IBM Plex Sans', sans-serif; color: var(--muted); min-width: 16px; }
.fcard-tags { flex: 1; display: flex; flex-wrap: wrap; gap: 5px; min-height: 26px; }
.fcard-text { font-family: var(--marker); line-height: 1.25; }
.fcard-text .em, .note .em { font-size: 20px; }
.fcard-text .dt { font-size: 16px; }
.grip { flex: none; display: flex; color: var(--muted); cursor: grab; touch-action: none; padding: 2px; }
.ghost { position: fixed; z-index: 1000; pointer-events: none; opacity: .92; transform: rotate(2deg); box-shadow: 0 16px 32px rgba(28,33,48,.35); }
.dragging-src { opacity: .35; }

.tray { padding: 10px 16px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.tray-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; min-height: 30px; padding: 0 10px; border-radius: 15px; border: 1px solid #9AA1B0; background: var(--panel); color: var(--ink); font-size: 12px; font-weight: 600; cursor: grab; touch-action: none; user-select: none; }
.chip.used { background: transparent; border: 1px dashed #9AA1B0; color: var(--muted); cursor: default; }
.chip.custom { background: #FFF8E1; border: 1px dashed var(--gold-edge); color: var(--gold-ink); }
.chip.on-card { min-height: 26px; background: rgba(255,255,255,.65); border-color: rgba(28,33,48,.3); }
.chip.on-card.custom { background: #FFF8E1; border-color: var(--gold-edge); }
.chip.add { border: 1px dashed var(--accent); color: var(--accent); cursor: pointer; }
.tray.drop-hot { background: var(--accent-soft); }

.boardcol { flex: 999 1 420px; min-width: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.swatch { width: 32px; height: 32px; border-radius: 6px; border: 1px solid rgba(28,33,48,.25); cursor: pointer; padding: 0; }
.swatch:disabled { opacity: .35; cursor: not-allowed; }
.vsep { width: 1px; height: 28px; background: var(--line); }
.board { position: relative; flex: 1 1 auto; overflow: auto; background-color: var(--ground); background-image: radial-gradient(#C5CAD4 1px, transparent 1px); background-size: 22px 22px; }
.board-inner { position: relative; width: 1400px; height: 1000px; }
.board.drop-hot { background-color: #E3E8F3; }
.note { position: absolute; width: 168px; min-height: 132px; padding: 14px 14px 18px; border-radius: 2px; font-family: var(--marker); color: var(--ink); cursor: grab; user-select: none; touch-action: none; box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 10px 18px -6px rgba(28,33,48,.28); }
.note .em { display: block; line-height: 1.1; padding-right: 26px; }
.note .dt { display: block; font-size: 16px; line-height: 1.25; margin-top: 6px; }
.note .coin { position: absolute; top: 8px; right: 8px; }
.note:focus-visible, .fcard:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.review-fab { position: absolute; right: 20px; bottom: 20px; }

.suggcol { flex: 0 0 256px; border-left: 1px solid var(--line); background: var(--soft); }
.sugg-grp { font-size: 12px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; cursor: pointer; padding: 4px 0; }
.sugg-grp:hover { color: var(--ink); }
.sugg { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 6px 10px; margin-bottom: 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); text-align: left; cursor: grab; font-size: 14px; color: var(--ink); touch-action: none; user-select: none; }
.sugg:hover { border-color: var(--accent); }
.themecol { flex-basis: 280px; }
.themesugg { cursor: pointer; touch-action: auto; }
.genre-desc { margin: 0 0 8px; font-size: 13px; color: var(--muted); line-height: 1.4; }
.themesugg .ex { display: block; font-size: 12px; color: var(--muted); font-style: italic; margin-top: 2px; }
.sugg .sw { flex: none; width: 10px; height: 10px; border-radius: 2px; border: 1px solid rgba(28,33,48,.25); }
.rail { flex: 0 0 64px; display: flex; flex-direction: column; align-items: center; padding: 14px 0; background: var(--soft); border-left: 1px solid var(--line); }
.rail button { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 52px; min-height: 52px; padding: 6px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 10px; font-weight: 500; cursor: pointer; }

/* ---------- forms ---------- */
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lbl { font-size: 13px; font-weight: 600; }
.req { color: var(--danger); font-weight: 700; }
.inp { width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); font: 14px/1.45 'IBM Plex Sans', sans-serif; color: var(--ink); resize: vertical; }
.inp:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea.inp { min-height: 64px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
@media (max-width: 1100px) { .grid3, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span3 { grid-column: span 2; } }
.pick { display: flex; gap: 6px; }
.dice { flex: none; display: flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--muted); cursor: pointer; padding: 0; }
.dice:hover { border-color: var(--accent); color: var(--accent); }
.grp { font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); padding-top: 8px; border-top: 1px solid var(--soft2); }
.pill { display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid #9AA1B0; background: var(--panel); color: var(--ink); font-size: 13px; font-weight: 600; cursor: pointer; }
.pill.sm { min-height: 30px; padding: 0 12px; font-size: 12px; }
.pill[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }
.pill.side-a[aria-pressed="true"] { background: var(--gold); border: 2px solid var(--gold-edge); color: var(--gold-ink); }
.pill.side-b[aria-pressed="true"] { background: var(--slate); border: 2px solid var(--chrome); color: #fff; }
.warnline { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--warn-ink); }
.alert { padding: 10px 14px; border-radius: 8px; background: var(--danger-soft); color: #8A1C12; font-size: 13px; }
.confirm-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 8px; background: var(--danger-soft); }
.confirm-bar span { flex: 1 1 260px; font-size: 14px; color: #8A1C12; }

/* ---------- foundation ---------- */
.page { flex: 1; overflow-y: auto; padding: 28px 40px 60px; }
.page-inner { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page h1 { margin: 0; font-size: 28px; }
.sec { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.sec.locked { background: var(--soft); border-style: dashed; }
.sechead { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 64px; padding: 14px 22px; border: none; background: transparent; text-align: left; cursor: pointer; color: inherit; border-radius: 12px; }
.sechead:hover { background: var(--soft); }
.sechead:disabled { cursor: not-allowed; }
.sechead .t { font-size: 18px; font-weight: 600; min-width: 130px; }
.sechead .s { flex: 1; font-size: 14px; color: var(--muted); }
.stepnum { flex: none; display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #9AA1B0; font-size: 12px; font-weight: 700; color: var(--muted); }
.stepnum.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.secbody { padding: 0 22px 24px 62px; display: flex; flex-direction: column; gap: 14px; }
.chev { transition: transform .2s; }
.chev.open { transform: rotate(180deg); }

.coin3d { perspective: 1200px; align-self: center; }
.coin3d-inner { position: relative; width: 260px; height: 260px; transition: transform .8s cubic-bezier(.3,.7,.3,1.15); transform-style: preserve-3d; }
.coin3d-inner.flipped { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 36px; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face.a { background: radial-gradient(circle at 35% 30%, #FBE29A, #F2C85B 55%, #D9A93A); border: 6px solid var(--gold-edge); box-shadow: inset 0 0 0 6px rgba(255,255,255,.35), 0 18px 36px -12px rgba(28,33,48,.45); color: var(--gold-ink); }
.face.b { transform: rotateY(180deg); background: radial-gradient(circle at 35% 30%, #5B6C90, #3B4A6B 55%, #26324D); border: 6px solid var(--chrome); box-shadow: inset 0 0 0 6px rgba(255,255,255,.12), 0 18px 36px -12px rgba(28,33,48,.45); color: #fff; }
.face .val { font: 700 26px/1.2 'IBM Plex Sans', sans-serif; text-align: center; }
.coininput { width: 100%; min-height: 48px; border: none; border-bottom: 2px solid currentColor; background: transparent; text-align: center; font: 600 22px 'IBM Plex Sans', sans-serif; color: inherit; outline: none; }
.coininput::placeholder { color: inherit; opacity: .55; }

.chcard { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 64px; padding: 12px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); text-align: left; cursor: pointer; color: inherit; }
.chcard:hover { border-color: var(--accent); }
.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 11px; font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
.badge.main { background: var(--accent-soft); color: var(--accent-dark); }
.badge.secondary { background: var(--ground); color: var(--muted); }
.badge.antag { background: var(--chrome); color: #FFC2D4; }
.badge.action { background: #FFD199; color: #5A2E00; }
.badge.repose { background: #DCCBFF; color: #2E1A66; }
.badge.flag { background: var(--chrome); color: #FFD199; }
.avatar { flex: none; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; font-weight: 700; font-size: 18px; background: var(--soft2); color: var(--ink); }
.avatar.main { background: var(--accent); color: #fff; }
.avatar.antag { background: var(--chrome); color: #FFC2D4; }
.editcard { border-radius: 10px; border: 2px solid var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 16px; background: var(--panel); }
.checkline { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; font-weight: 600; cursor: pointer; }
.checkline input { width: 20px; height: 20px; accent-color: var(--danger); }
.radioline { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 14px; cursor: pointer; }

/* ---------- scene prep / action ---------- */
.mlist { list-style: none; margin: 0; padding: 14px 16px 24px; background: var(--soft); display: flex; flex-direction: column; gap: 10px; }
.mm { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 10px 12px; border-radius: 3px; border: none; text-align: left; cursor: pointer; color: var(--ink); box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 6px 12px -6px rgba(28,33,48,.3); }
.mm[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: 2px; }
.mm-top { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 600; }
.mm-text { font-family: var(--marker); line-height: 1.25; }
.momenthead { display: flex; flex-direction: column; gap: 8px; padding: 16px 20px; border-radius: 4px; box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 8px 16px -8px rgba(28,33,48,.3); }
.sc { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); text-align: left; cursor: pointer; color: inherit; user-select: none; }
.sc:hover { border-color: var(--accent); }
.scn { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); text-align: left; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink); }
.scn[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); }
.nest { list-style: none; margin: 4px 0 4px 14px; padding: 0 0 0 10px; border-left: 2px solid #9AA1B0; display: flex; flex-direction: column; gap: 6px; }
.editor-wrap { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; background: var(--soft2); }
.editor-head { padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.cardpeek { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 20px; padding: 12px 14px; border-radius: 8px; background: var(--soft); border: 1px solid var(--soft2); }
.cardpeek .v { font-size: 13px; line-height: 1.4; }
.editor-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 24px 28px 20px; }
.editor-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.manuscript { width: 100%; min-height: 560px; padding: 48px 56px; border: none; border-radius: 4px; background: var(--panel); box-shadow: 0 2px 10px rgba(28,33,48,.12); font: 18px/1.75 var(--page); color: var(--ink); resize: vertical; outline: none; }
.manuscript:focus { box-shadow: 0 0 0 2px var(--accent), 0 2px 10px rgba(28,33,48,.12); }

/* ---------- assistant director ---------- */
.ad { flex: 0 1 380px; min-width: 300px; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
.ad-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.ad-avatar { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; background: var(--chrome); flex: none; }
.ad-title { flex: 1; min-width: 0; }
.ad-name { font-weight: 600; font-size: 15px; }
.ad-context { font-size: 11px; font-weight: 600; letter-spacing: .5px; color: var(--muted); margin-top: 2px; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-level { display: flex; align-items: center; gap: 10px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: var(--soft); }
.ad-level .seg { background: var(--soft2); }
.ad-level .seg button { min-height: 32px; padding: 0 12px; font-size: 12px; }
.ad-log { flex: 1 1 auto; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.tipbox { padding: 12px 14px; border-radius: 10px; background: #FFF8E1; border: 1px solid #F0DCA0; font-size: 14px; line-height: 1.45; }
.tipbox .k { color: var(--gold-ink); margin-bottom: 4px; display: block; }
.bubble { padding: 12px 15px; border-radius: 4px 14px 14px 14px; background: #F4F5F8; font: 15px/1.5 var(--typewriter); white-space: normal; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin: 0; }
.bubble ul { margin: 0 0 8px; padding-left: 20px; } .bubble li { margin: 2px 0; }
.bubble.me { align-self: flex-end; max-width: 85%; border-radius: 14px 4px 14px 14px; background: var(--accent); color: #fff; font: 14px/1.45 'IBM Plex Sans', sans-serif; }
.bubble.err { background: var(--danger-soft); color: #8A1C12; font-family: 'IBM Plex Sans', sans-serif; font-size: 14px; }
.bubble.busy::after { content: "\2026"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.replies { display: flex; flex-wrap: wrap; gap: 8px; }
.reply { display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--accent); background: var(--panel); color: var(--accent); font-size: 13px; font-weight: 500; cursor: pointer; text-align: left; }
.reply:hover { background: var(--accent-soft); }
.reply:disabled { opacity: .5; cursor: not-allowed; }
.ad-form { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); align-items: flex-end; }
.ad-form textarea { flex: 1; min-width: 0; min-height: 44px; max-height: 160px; padding: 11px 14px; border-radius: 8px; border: 1px solid var(--line-strong); font: 14px/1.4 'IBM Plex Sans', sans-serif; resize: none; }
.ad-form textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* ---------- tooltip, dialog, toast ---------- */
.tooltip { position: fixed; z-index: 2000; max-width: 280px; padding: 12px 14px; border-radius: 8px; background: var(--chrome); color: #fff; box-shadow: 0 10px 24px rgba(28,33,48,.3); font-size: 13px; line-height: 1.45; pointer-events: none; }
.tooltip .tt { display: block; font-weight: 700; color: var(--gold); margin-bottom: 4px; }
.tooltip .ts { display: block; margin-top: 6px; font-size: 12px; color: #C9CEDA; }
.dialog-back { position: fixed; inset: 0; z-index: 1500; display: flex; align-items: center; justify-content: center; background: rgba(28,33,48,.45); padding: 16px; }
.dialog { width: 440px; max-width: 100%; padding: 24px; border-radius: 12px; background: var(--panel); box-shadow: 0 20px 48px rgba(28,33,48,.35); display: flex; flex-direction: column; gap: 14px; }
.dialog h2 { margin: 0; font-size: 18px; }
.dialog p { margin: 0; color: var(--muted); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.dialog-actions .left { margin-right: auto; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2500; padding: 10px 18px; border-radius: 8px; background: var(--chrome); color: #fff; font-size: 14px; box-shadow: 0 10px 24px rgba(28,33,48,.3); }

/* ---------- Character Palette (Foundation) ---------- */
.palette { position: relative; height: 460px; border-radius: 14px; overflow: hidden; background-color: #F4EEE4;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 460' preserveAspectRatio='none'%3E%3Cpath fill='%23E9CFA2' stroke='%23C49A63' stroke-width='5' fill-rule='evenodd' d='M410 18C630 14 786 104 784 228C782 352 650 446 478 442C392 440 368 384 306 386C246 388 252 444 160 442C64 440 16 352 18 248C20 118 196 22 410 18ZM120 300a52 46 0 1 0 104 0a52 46 0 1 0-104 0Z'/%3E%3Cpath fill='none' stroke='%23F6E2BE' stroke-width='3' stroke-linecap='round' d='M330 70C470 52 640 90 712 170'/%3E%3C/svg%3E");
  background-size: 100% 100%; background-repeat: no-repeat; }
.palette-empty { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); max-width: 320px; text-align: center; font-size: 15px; color: #6B4F2A; }
.splash { position: absolute; width: 164px; height: 128px; padding: 0 16px; border: none; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-align: center; cursor: grab; touch-action: none; user-select: none; }
.splat { position: absolute; left: -12px; top: -14px; width: calc(100% + 24px); height: calc(100% + 28px); z-index: 0; overflow: visible; filter: drop-shadow(0 3px 5px rgba(60,40,10,.3)); }
.splash > span { position: relative; z-index: 1; }
.splash-name { font-family: var(--marker); font-size: 21px; line-height: 1.05; text-shadow: 0 1px 0 rgba(0,0,0,.12); overflow-wrap: anywhere; }
.splash-tags { font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; opacity: .9; }
.splash:hover .splat { filter: drop-shadow(0 5px 8px rgba(60,40,10,.38)) brightness(1.06); }
.splash:focus-visible { outline: 3px solid var(--accent); outline-offset: 10px; border-radius: 40%; }
.splash.dragging-src { opacity: .35; }
.charpop-back { position: fixed; inset: 0; z-index: 1400; display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; background: rgba(28,33,48,.45); overflow-y: auto; }
.charpop { width: 760px; max-width: 100%; padding: 22px 26px 24px; border-radius: 14px; background: var(--panel); border-top: 10px solid var(--paint); box-shadow: 0 20px 48px rgba(28,33,48,.35); display: flex; flex-direction: column; gap: 14px; }
.charpop-head { display: flex; align-items: center; gap: 12px; }
.paintdot { flex: none; width: 34px; height: 30px; background: var(--paint); border-radius: 58% 42% 63% 37% / 45% 55% 45% 55%; }
.charpop-name { flex: 1; min-width: 0; border: none; border-bottom: 2px solid var(--line); padding: 4px 2px; font-family: var(--marker); font-size: 28px; color: var(--ink); background: transparent; }
.charpop-name:focus { outline: none; border-color: var(--accent); }
.charpop-row { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.paints { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.paint { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(28,33,48,.25); cursor: pointer; padding: 0; }
.paint.on { box-shadow: 0 0 0 2px var(--ink); }
.madlib { margin: 4px 0 0; font-size: 19px; line-height: 2.3; color: var(--ink); }
.blank { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
.blank-inp { max-width: 100%; border: none; border-bottom: 2px solid var(--paint); padding: 0 4px; font: inherit; font-family: var(--marker); font-size: 20px; color: var(--ink); background: color-mix(in srgb, var(--paint) 9%, transparent); border-radius: 4px 4px 0 0; }
.blank-inp::placeholder { font-family: 'IBM Plex Sans', sans-serif; font-size: 13px; color: var(--muted); }
.blank-inp:focus { outline: none; background: color-mix(in srgb, var(--paint) 18%, transparent); }
.blank .dice { transform: scale(.85); }
.charpop-hints { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.more { border-top: 1px solid var(--line); padding-top: 4px; }
.more[open] { display: flex; flex-direction: column; gap: 12px; }
