/* The original matrix re-drawn as a cream sheet pinned to a grey wall, with a conversation
   panel beside it (a bottom sheet on phones). Every word is printed ink, exactly like the
   original; suggested moves are numbered pen marks tied back to the dot. */
:root {
  --wall: #E4E3DD; --board: #F7F5EF; --ink: #151515; --ink-2: #5B5954; --ink-3: #97948D; --line: #A9A69E;
  --pen: #1E5FC2; --pen-ink: #F7F5EF; --pen-soft: rgba(30, 95, 194, .14);
  --panel: #FFFFFF; --field: #F1F0EB; --edge: #DAD8D1;
  --danger: #B3261E; --danger-ink: #FFFFFF; --danger-soft: rgba(179, 38, 30, .1);
  --heart: #D6456F; --heart-ink: #FFFFFF;
  --shadow: 0 10px 30px rgba(20, 20, 20, .12);
  --font-ui: 'Archivo', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --wall: #141518; --board: #222328; --ink: #ECEAE3; --ink-2: #B3B0A8; --ink-3: #77746D; --line: #55555C;
    --pen: #86B5FF; --pen-ink: #141518; --pen-soft: rgba(134, 181, 255, .2);
    --panel: #1C1D21; --field: #2A2B31; --edge: #36373E;
    --danger: #FF7A70; --danger-ink: #141518; --danger-soft: rgba(255, 122, 112, .14);
    --heart: #FF7FA3; --heart-ink: #141518;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--wall); color: var(--ink); font-family: var(--font-ui); font-size: 15px; line-height: 1.45;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: calc(22px + env(safe-area-inset-top, 0px)); padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}
a { color: inherit; }

.top { max-width: 1260px; margin: 0 auto 16px; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
h1 { font-weight: 700; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.025em; margin: 0; line-height: 1.02; text-wrap: balance; }
.sub { margin: 8px 0 0; color: var(--ink-2); max-width: 64ch; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.btn { font: inherit; font-weight: 600; border: 1.5px solid var(--ink); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 8px 16px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: var(--field); }
.btn.primary { background: var(--ink); color: var(--board); border-color: var(--ink); }
.btn.primary:hover { opacity: .88; background: var(--ink); }
.btn.pen { border-color: var(--pen); color: var(--pen); }
.btn.active, .btn.pen.active { background: var(--pen); color: var(--pen-ink); border-color: var(--pen); }
.btn.active:hover { background: var(--pen); opacity: .9; }
.btn.down { border-color: var(--danger); color: var(--danger); }
.btn.down.active { background: var(--danger); color: var(--danger-ink); border-color: var(--danger); }
.btn.down.active:hover { background: var(--danger); opacity: .9; }
.btn.heartbtn { border-color: var(--heart); color: var(--heart); }
.btn.heartbtn.active { background: var(--heart); color: var(--heart-ink); border-color: var(--heart); }
.btn.heartbtn.active:hover { background: var(--heart); opacity: .9; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn-browse { display: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, .pt:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

.stage { max-width: 1260px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 384px; gap: 22px; align-items: start; }
.board-wrap { min-width: 0; }
.scroll-hint { display: none; margin: 0 0 8px; font-size: 13px; color: var(--ink-2); }
.board-scroll { overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }
.board { position: relative; background: var(--board); border-radius: 6px; box-shadow: var(--shadow); width: min(100%, 88vh); min-width: 640px; aspect-ratio: 1 / 1; }
.board svg { display: block; width: 100%; height: 100%; }
.board svg.placing { cursor: crosshair; touch-action: none; }
.hint { position: absolute; top: 12px; left: 12px; z-index: 4; background: var(--pen); color: var(--pen-ink); padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 13px; pointer-events: none; }

/* chart */
.arr { fill: none; stroke: var(--line); stroke-width: 1.6; }
.axis-line { stroke: var(--line); stroke-width: 2; fill: none; }
.axis-label { font-family: var(--font-ui); font-weight: 700; font-size: 26px; fill: var(--ink); }
.pt { cursor: pointer; outline: none; }
.pt text { font-family: var(--font-ui); font-size: 25px; fill: var(--ink); paint-order: stroke; stroke: var(--board); stroke-width: 7px; stroke-linejoin: round; }
.pt.bold text { font-weight: 700; }
.pt circle.dot { fill: var(--ink); }
.pt circle.hit { fill: transparent; }
.pt line.leader { stroke: var(--ink-3); stroke-width: 1.5; }
.pt:hover text.lbl, .pt:focus-visible text.lbl { fill: var(--pen); }
.pt.selected text.lbl { fill: var(--pen); font-weight: 700; }
.pt.moved circle.dot { stroke: var(--pen); stroke-width: 3; paint-order: stroke; }
.pt.selected circle.dot { stroke: var(--pen); stroke-width: 4; paint-order: stroke; }
.pt.removed { opacity: .45; }
.pt.draft circle.dot { stroke: var(--pen); stroke-width: 3; stroke-dasharray: 4 3; paint-order: stroke; }
.pt.draft { cursor: grab; }
svg.dim #pts .pt:not(.selected) { opacity: .28; }
.heart path { fill: var(--heart); }
.heart text { font-family: var(--font-ui); font-weight: 700; font-size: 14px; fill: var(--heart); stroke: var(--board); stroke-width: 4px; paint-order: stroke; stroke-linejoin: round; pointer-events: none; }
.hk { color: var(--heart); }
.badge circle { fill: var(--pen); }
.badge text { font-family: var(--font-ui); font-weight: 700; font-size: 13px; fill: var(--pen-ink); stroke: none; text-anchor: middle; pointer-events: none; }
.origin line { stroke: var(--ink-3); stroke-width: 2; stroke-dasharray: 3 5; fill: none; }
.origin circle { fill: none; stroke: var(--ink); stroke-width: 2.5; }
.origin text { font-family: var(--font-ui); font-size: 14px; fill: var(--ink-2); text-anchor: middle; paint-order: stroke; stroke: var(--board); stroke-width: 4px; stroke-linejoin: round; }
.ghost line { stroke: var(--pen); stroke-width: 2; stroke-dasharray: 7 6; fill: none; }
.ghost circle { fill: var(--board); stroke: var(--pen); stroke-width: 3; cursor: pointer; }
.ghost text { font-family: var(--font-ui); font-weight: 700; font-size: 15px; fill: var(--pen); text-anchor: middle; pointer-events: none; }
.ghost text.cnt { font-size: 14px; text-anchor: start; paint-order: stroke; stroke: var(--board); stroke-width: 5px; stroke-linejoin: round; }
.ghost.hot circle { stroke-width: 6; }
.ghost.draft circle { cursor: grab; stroke-dasharray: 5 4; }
#draft { touch-action: none; }

/* placement form */
#float { position: absolute; z-index: 5; width: min(300px, 78%); background: var(--panel); border: 1.5px solid var(--ink); border-radius: 12px; padding: 12px 12px 10px; box-shadow: var(--shadow); margin: 0; }
#float label { display: block; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); margin: 0 0 4px; }
#float .f-row + .f-row { margin-top: 9px; }
#float input, #float textarea, .composer textarea, .hform input { font: inherit; font-size: 14px; border: 1px solid var(--edge); background: var(--field); color: var(--ink); border-radius: 8px; padding: 8px 10px; }
#float input, #float textarea, .composer textarea { width: 100%; resize: vertical; }
#float .acts { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.f-dupe { font-size: 12px; color: var(--ink-2); margin-top: 5px; line-height: 1.4; }
#float .f-handle { margin-right: auto; font-size: 12px; min-width: 0; }

.tip { position: absolute; z-index: 6; pointer-events: none; background: var(--ink); color: var(--board); font-size: 13px; line-height: 1.35; padding: 6px 10px; border-radius: 8px; max-width: 240px; transform: translate(-50%, calc(-100% - 14px)); }
.tip.below { transform: translate(-50%, 18px); }
.tip b { font-weight: 700; }

.legend { display: flex; gap: 10px 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-top: 12px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.sw { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.sw.ink { background: var(--ink); }
.sw.ring { background: var(--ink); box-shadow: 0 0 0 2.5px var(--pen); width: 9px; height: 9px; margin: 0 2px; }
.sw.pen { border: 2.5px solid var(--pen); background: transparent; }
.sw.count { background: var(--pen); }
.sw.heart { background: none; color: var(--heart); font-size: 15px; line-height: 1; width: auto; height: auto; border-radius: 0; font-style: normal; }
.notice { background: var(--field); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--ink-2); margin-top: 12px; }

/* panel */
.panel { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 18px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel-head { display: flex; gap: 10px; align-items: flex-start; }
.panel-head > div { flex: 1; min-width: 0; }
.word { font-size: 26px; font-weight: 700; letter-spacing: -.015em; line-height: 1.1; overflow-wrap: anywhere; text-wrap: balance; }
.meta { color: var(--ink-2); font-size: 13px; }
.meta b { color: var(--ink); font-weight: 600; }
.where { font-weight: 600; margin-top: 4px; }
.close { background: none; border: 0; font-size: 28px; line-height: 1; cursor: pointer; color: var(--ink-2); padding: 0 4px; flex: none; }
.close:hover { color: var(--ink); }
.banner { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600; }
.why { font-size: 14px; background: var(--field); border-radius: 10px; padding: 10px 12px; }
.why .meta { display: block; margin-bottom: 2px; }
.tally { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: var(--field); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.tile .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.tile .l { font-size: 12px; color: var(--ink-2); margin-top: 5px; line-height: 1.3; }
.tile.lead { box-shadow: inset 0 0 0 1.5px var(--pen); }
.vote-row { display: flex; flex-wrap: wrap; gap: 8px; }
.section-title { font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin-top: 2px; }
.thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.post { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; border-radius: 8px; }
.post.hot { background: var(--pen-soft); }
.post > .av { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--edge); color: var(--ink-2); font-size: 12px; font-weight: 700; flex: none; }
.post > div { min-width: 0; }
.post .who { font-size: 13px; color: var(--ink-2); }
.post .who b { color: var(--ink); font-weight: 600; }
.post .txt { overflow-wrap: anywhere; white-space: pre-wrap; margin-top: 2px; }
.post .move { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--pen); margin: 3px 0 1px; font-size: 14px; flex-wrap: wrap; }
.num { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--pen); color: var(--pen); font-size: 12px; font-weight: 700; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; flex: none; background: var(--panel); }
.num.leading { background: var(--pen); color: var(--pen-ink); }
.chip { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; background: var(--pen); color: var(--pen-ink); border-radius: 999px; padding: 2px 8px; }
.post .acts { display: flex; gap: 12px; align-items: center; margin-top: 7px; flex-wrap: wrap; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--ink-2); cursor: pointer; text-decoration: underline; }
.linkbtn.danger { color: var(--danger); }
.composer { display: flex; flex-direction: column; gap: 8px; }
.composer .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.hform { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.hform .at { color: var(--ink-2); font-weight: 600; }
.hform input { width: 140px; font-size: 13px; padding: 5px 8px; }
.empty { color: var(--ink-3); font-style: italic; font-size: 14px; }
.idle-msg { display: flex; flex-direction: column; gap: 10px; }
.idle-msg p { margin: 0; }
#q { width: 100%; font: inherit; font-size: 14px; border: 1px solid var(--edge); background: var(--field); color: var(--ink); border-radius: 8px; padding: 8px 10px; }
.wlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.wrow { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; margin: 0 -8px; width: calc(100% + 16px); border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; }
.wrow:hover { background: var(--field); }
.wrow .wl { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.wrow .wmeta { color: var(--ink-2); font-size: 12px; white-space: nowrap; flex: none; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--board); padding: 10px 16px; border-radius: 999px; font-weight: 600; z-index: 30; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }

@media (max-width: 980px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .panel { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 20; max-height: 72vh; border-radius: 16px 16px 0 0;
    padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .panel.idle { display: none; }
  .panel.idle.open { display: flex; }
  body.placing .panel { display: none; }
  .board { width: auto; }
  .btn-browse { display: inline-flex; }
}
@media (max-width: 700px) {
  .scroll-hint { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
