/* Thread tree. Palette and square language ported from Petr's progress-tree. */
:host, .tt {
  --bg: #102329; --panel: #19343b; --card: #17343a; --card-hi: #21464e; --line: #41666b; --line-soft: #2b4b51;
  --ink: #ecebd8; --muted: #abc3c4; --dim: #7f9a9d; --mint: #70dfb8; --amber: #ffc088; --empty: #6b878c; --focus: #fff0b9;
  --sans: 'Avenir Next', Avenir, 'Segoe UI', system-ui, sans-serif;
  --serif: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
}
.tt { position: relative; display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.4 var(--sans); -webkit-font-smoothing: antialiased; color-scheme: dark; text-align: left; letter-spacing: 0; }
.tt.overlay { position: fixed; inset: 0; z-index: 2147483000; }
.tt *, .tt *::before, .tt *::after { box-sizing: border-box; }
.tt[hidden], .tt [hidden] { display: none !important; }
.tt button { font: inherit; color: inherit; background: transparent; border: 1px solid var(--line); border-radius: 7px; padding: 6px 11px; cursor: pointer; line-height: 1.2; }
.tt button:hover { background: #29464d; border-color: var(--mint); }
.tt button:focus-visible, .tt a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.tt .plane:focus, .tt .plane:focus-visible { outline: none; }
.tt a { color: var(--mint); text-underline-offset: 3px; }
.tt img { display: block; }

/* ---------- bar ---------- */
.bar { display: flex; align-items: center; gap: 18px; padding: 12px 20px; border-bottom: 1px solid var(--line-soft); min-height: 58px; flex: none; }
.bar .title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.bar .title .av { width: 28px; height: 28px; border-radius: 50%; flex: none; background: var(--panel); }
.bar .title h1 { margin: 0; font: 400 21px/1.15 var(--serif); letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar .title h1 small { font: 13px var(--sans); color: var(--muted); margin-right: 10px; }
.stats { display: flex; gap: 14px; align-items: baseline; color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats b { color: var(--ink); font-weight: 600; }
.stats .miss { color: var(--dim); cursor: help; border-bottom: 1px dotted var(--line); }
.tt .stats .new { color: var(--amber); border: 1px solid #ffc08866; border-radius: 999px; padding: 1px 9px; font-size: inherit; }
.tt .stats .new:hover { background: #ffc0881a; border-color: var(--amber); }
.progress { width: 120px; height: 4px; border-radius: 2px; background: var(--line-soft); overflow: hidden; flex: none; }
.progress i { display: block; height: 100%; background: var(--mint); width: 0; transition: width .35s ease; }
.crawl { display: flex; align-items: center; gap: 10px; color: var(--amber); font-size: 13px; white-space: nowrap; }
.crawl .spin { width: 10px; height: 10px; border: 1.5px solid var(--amber); border-right-color: transparent; border-radius: 50%; animation: tt-spin 1s linear infinite; }
.crawl.idle .spin { display: none; }
.crawl button { padding: 4px 9px; font-size: 12px; }
@keyframes tt-spin { to { transform: rotate(1turn); } }
.tools { display: flex; align-items: center; gap: 6px; flex: none; }
.tools button { font-size: 12.5px; padding: 6px 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.tt .seg button { border: 0; border-radius: 0; padding: 6px 10px; color: var(--muted); }
.tt .seg button[aria-pressed="true"], .tt .plane-tools .seg button[aria-pressed="true"] { background: var(--card-hi); color: var(--ink); }
.tt .tools .x { font-size: 18px; padding: 2px 10px 4px; margin-left: 6px; }
.tt .tools select { font: inherit; font-size: 12.5px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; }

/* ---------- body ---------- */
.body { flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 440px); min-height: 0; }
.plane-wrap { position: relative; min-height: 0; min-width: 0; display: grid; }
.plane-tools { position: absolute; right: 14px; top: 12px; z-index: 2; display: flex; gap: 6px; padding: 4px; border-radius: 10px; background: #102329d9; }
.tt .plane-tools button { background: var(--bg); font-size: 12.5px; padding: 6px 10px; }
.tt .plane-tools .seg { background: var(--bg); }
.plane { position: relative; overflow: auto; min-height: 0; min-width: 0; cursor: grab; outline: none; overscroll-behavior: contain;
  background: radial-gradient(ellipse at 40% 0%, #1c3b3d66, transparent 60%); scrollbar-color: #54747b var(--bg); scrollbar-width: thin; }
.plane.dragging { cursor: grabbing; }
.sizer { position: relative; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; transition: opacity .18s; }
.tt .world.still .n { transition: none; }
.edges path { fill: none; stroke: var(--line); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.edges path.trace { stroke: var(--mint); stroke-width: 2; }
.nodes { position: absolute; left: 0; top: 0; }

/* nodes */
.tt .n { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 6px; padding: 0 9px 0 7px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); white-space: nowrap; overflow: hidden; font-size: 12.5px;
  transition: transform .28s cubic-bezier(.2,.7,.2,1), opacity .2s, background .15s, border-color .15s; will-change: transform; }
.tt .n:hover { background: var(--card-hi); border-color: var(--ink); }
.n .sq { flex: none; position: relative; width: 14px; height: 14px; border: 1.5px solid var(--empty); border-radius: 3px; background: var(--bg); }
.n .av { width: 16px; height: 16px; border-radius: 50%; flex: none; background: var(--panel); }
.n .who { color: var(--ink); font-weight: 600; }
.n .who { flex: 0 0 auto; max-width: 44%; overflow: hidden; text-overflow: ellipsis; }
.n .tx { overflow: hidden; text-overflow: ellipsis; flex: 1 1 0; min-width: 0; }
.n.op .sq { border-color: var(--amber); }
.n.read { color: var(--dim); }
.n.read .sq { background: var(--mint); border-color: var(--mint); }
.n.read.op .sq { border-color: var(--amber); }
.n.read .who { color: var(--muted); font-weight: 500; }
.n.fresh .sq::after { content: ''; position: absolute; right: -5px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 2px var(--bg); }
.tt:not(.squares) .n.fresh { padding-left: 11px; }
.tt:not(.squares) .n.fresh::before { content: ''; position: absolute; left: 3px; top: 5px; bottom: 5px; width: 3px; border-radius: 2px; background: var(--amber); }
.tt .n.cur { border-color: var(--focus); background: var(--card-hi); color: var(--ink); box-shadow: 0 0 0 1px var(--focus); }
.n.anc { border-color: var(--mint); }
.n.hl { border-color: var(--amber); }
.n.dim { opacity: .35; }
.n.squeezed { gap: 7px; color: var(--muted); border-style: dashed; border-color: var(--line); background: transparent; }
.n.squeezed .stack { width: 16px; height: 16px; flex: none; position: relative; }
.n.squeezed .stack i { position: absolute; width: 12px; height: 12px; border-radius: 3px; background: var(--mint); box-shadow: 0 0 0 1.5px var(--bg); }
.n.squeezed .stack i:nth-child(1) { left: 4px; top: 0; opacity: .45; } .n.squeezed .stack i:nth-child(2) { left: 2px; top: 2px; opacity: .7; } .n.squeezed .stack i:nth-child(3) { left: 0; top: 4px; }
.n .cnt { color: var(--mint); font-variant-numeric: tabular-nums; }
.n .more { color: var(--amber); font-size: 11px; margin-left: auto; flex: none; font-variant-numeric: tabular-nums; }
.n .more.fold { color: var(--muted); }
/* squares density: the ring sits on the square, labels sit beside it */
.squares .n { padding: 0; border: 0; background: transparent; gap: 4px; overflow: visible; border-radius: 4px; justify-content: flex-start; }
.squares .n .sq { width: 18px; height: 18px; }
.tt.squares .n:hover { background: transparent; }
.squares .n:hover .sq { border-color: var(--ink); }
.tt.squares .n.cur { background: transparent; box-shadow: none; }
.squares .n.cur .sq { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--focus); }
.squares .n.anc .sq { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--mint); }
.squares .n.hl .sq { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--amber); }
.squares .n.squeezed { padding: 0 2px; border: 0; }
.squares .n .more { font-size: 10.5px; margin: 0; }
.squares .edges path { stroke-width: 1.2; }
.squares .edges path.trace { stroke-width: 1.8; }

/* ---------- reader ---------- */
.reader { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line-soft); background: #132b31; }
.reader .scroll { flex: 1 1 auto; overflow: auto; padding: 18px 22px 28px; scrollbar-width: thin; scrollbar-color: #54747b #132b31; }
.path { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.tt .anc-row { display: grid; grid-template-columns: 14px 18px minmax(0, 1fr); align-items: center; gap: 8px; border: 0; border-radius: 6px; padding: 4px 6px; text-align: left; color: var(--dim); font-size: 12.5px; }
.tt .anc-row:hover { background: var(--panel); }
.anc-row .sq, .kid .sq { width: 12px; height: 12px; border: 1.5px solid var(--empty); border-radius: 3px; background: var(--bg); }
.anc-row.read .sq, .kid.read .sq { background: var(--mint); border-color: var(--mint); }
.anc-row.op .sq, .kid.op .sq { border-color: var(--amber); }
.anc-row .av { width: 18px; height: 18px; border-radius: 50%; background: var(--panel); }
.anc-row span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.anc-row b { color: var(--muted); font: 600 12.5px var(--sans); margin-right: 6px; }
.anc-row.parent { align-items: start; }
.anc-row.parent span { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; color: var(--muted); font: 14px/1.5 var(--serif); }
.anc-row.parent .sq, .anc-row.parent .av { margin-top: 3px; }
.tt .gap-row { border: 0; padding: 2px 6px 2px 34px; color: var(--dim); font-size: 12px; text-align: left; }
.tt .gap-row:hover { color: var(--mint); background: transparent; }
.thread-line { margin-left: 12px; border-left: 1.5px solid var(--line); height: 12px; }

.tw { padding: 2px 0 4px; }
.tw header { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.tw header .av { width: 40px; height: 40px; border-radius: 50%; background: var(--panel); }
.tw .name { font-weight: 600; font-size: 15px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tw .h { color: var(--muted); font-size: 13px; }
.tw .op-tag { color: var(--amber); font-size: 12px; margin-left: 6px; }
.tw .time { color: var(--muted); font-size: 13px; text-decoration: none; }
.tw .time:hover { color: var(--mint); }
.tw .text { font: 17px/1.62 var(--serif); margin: 14px 0 12px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.tw .text a { color: var(--mint); text-decoration: none; }
.tw .text a:hover { text-decoration: underline; }
.media { display: grid; gap: 4px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin: 0 0 12px; border-radius: 10px; overflow: hidden; }
.media img { width: 100%; max-height: 300px; object-fit: cover; background: var(--panel); }
.tt .quoted { display: block; text-decoration: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; font-size: 13.5px; line-height: 1.5; color: var(--muted); overflow-wrap: anywhere; }
.tt .quoted:hover { border-color: var(--mint); }
.quoted b { color: var(--ink); font-weight: 600; margin-right: 6px; }
.metrics { display: flex; gap: 16px; align-items: center; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; padding: 8px 0 14px; border-bottom: 1px solid var(--line-soft); }
.metrics span { display: inline-flex; align-items: center; gap: 5px; }
.metrics svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.metrics .onx { margin-left: auto; color: var(--mint); text-decoration: none; font-size: 13px; }
.metrics .onx:hover { text-decoration: underline; }
.kids { padding-top: 14px; }
.kids-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.kids-head h2 { margin: 0; font: 600 13px var(--sans); color: var(--muted); }
.tt .kids-head button { border: 0; padding: 2px 4px; font-size: 12.5px; color: var(--muted); }
.tt .kids-head button:hover { color: var(--mint); background: transparent; }
.tt .kid { display: grid; grid-template-columns: 12px 22px minmax(0, 1fr) auto; gap: 9px; align-items: start; width: 100%; border: 0; border-radius: 8px; padding: 8px 8px; text-align: left; }
.tt .kid:hover { background: var(--panel); }
.kid .sq { margin-top: 5px; }
.kid .av { width: 22px; height: 22px; border-radius: 50%; background: var(--panel); }
.kid .body2 { min-width: 0; font-size: 13.5px; color: var(--muted); }
.kid .body2 b { color: var(--ink); font-weight: 600; margin-right: 6px; }
.kid .body2 span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kid .rc { color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kid.read .body2 { color: var(--dim); }
.kid.read .body2 b { color: var(--muted); }
.unloaded { margin: 8px 0 0; color: var(--dim); font-size: 12.5px; display: flex; gap: 10px; align-items: center; }
.tt .unloaded button { font-size: 12px; padding: 4px 9px; }
.leaf-note { color: var(--dim); font-size: 13px; padding: 6px 0; }
.steps { flex: none; display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 8px; padding: 12px 22px; border-top: 1px solid var(--line-soft); background: #132b31; }
.steps > button { justify-self: start; white-space: nowrap; }
.tt .steps .ico { padding: 6px 9px; }
.steps .ico svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tt .steps > .primary { justify-self: end; }
.tt .steps button:disabled { opacity: .4; cursor: default; background: transparent; border-color: var(--line); }
.tt .steps .primary { background: var(--mint); color: var(--bg); border-color: var(--mint); font-weight: 600; }
.tt .steps .primary:hover { background: #8de8c8; }
.tt .steps .primary:disabled { opacity: .45; cursor: default; }
.tt .steps .mark[aria-pressed="true"] { color: var(--mint); border-color: var(--mint); }
.steps kbd, .help kbd { font: 11px var(--sans); color: var(--dim); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 6px; }
.steps .primary kbd { color: var(--bg); border-color: #0f2a2f55; }
.done { text-align: center; padding: 30px 10px 10px; color: var(--muted); }
.done h2 { font: 400 22px var(--serif); color: var(--ink); margin: 0 0 6px; }

/* ---------- floating bits ---------- */
.tip { position: fixed; z-index: 10; width: 300px; max-width: calc(100vw - 24px); padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; pointer-events: none; font-size: 13px; color: var(--muted); }
.tip .tip-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: var(--ink); font-weight: 600; }
.tip .tip-h img { width: 20px; height: 20px; border-radius: 50%; }
.tip .tip-h span { color: var(--muted); font-weight: 400; }
.tip p { margin: 0; font: 14px/1.5 var(--serif); color: var(--ink); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.tip .tip-m { margin-top: 8px; font-size: 12px; color: var(--dim); }
.help { position: absolute; right: 20px; top: 62px; z-index: 9; width: 290px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; font-size: 13px; color: var(--muted); }
.help table { border-collapse: collapse; width: 100%; }
.help td { padding: 3px 0; }
.help td:first-child { width: 96px; white-space: nowrap; }
.tt .help .reset { margin-top: 12px; width: 100%; font-size: 12.5px; }
.tt .tools .share { background: var(--mint); color: var(--bg); border-color: var(--mint); font-weight: 600; }
.tt .tools .share:hover { filter: brightness(1.08); }
.tt .barlink { color: var(--mint); font-size: 13px; text-decoration: none; margin-right: 6px; white-space: nowrap; }
.tt .barlink:hover { text-decoration: underline; }
.toast { position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%); z-index: 11; padding: 9px 14px; border-radius: 9px; background: var(--ink); color: var(--bg); font-size: 13px; max-width: min(520px, 90%); }
.pill { position: fixed; left: 22px; bottom: 22px; z-index: 2147483000; display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: 600 13px var(--sans); cursor: pointer; box-shadow: 0 6px 24px #0007; }
.pill i { width: 12px; height: 12px; border-radius: 3px; background: var(--mint); }
.pill:hover { border-color: var(--mint); }
.pill[hidden] { display: none; }
.pill:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- narrow screens ---------- */
@media (max-width: 860px) {
  .bar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .bar .title { flex-basis: 100%; }
  .bar .title h1 { font-size: 18px; }
  .stats { gap: 10px; font-size: 12px; }
  .progress { width: 60px; }
  .tools { margin-left: auto; }
  .tools [data-act="help"], .bar .title h1 small, .plane-tools .seg.sort { display: none; }
  .tools select { max-width: 200px; }
  .plane-tools { right: 10px; top: 8px; }
  .body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 42fr) minmax(0, 58fr); }
  .reader { border-left: 0; border-top: 1px solid var(--line-soft); }
  .reader .scroll { padding: 14px 16px 20px; }
  .tw .text { font-size: 16px; }
  .steps { padding: 10px 16px; grid-template-columns: auto auto 1fr auto; }
  .steps kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) { .tt * { transition: none !important; animation: none !important; } }
