/* Язык IRemoted (docs/DESIGN.md, направление «Монохром»): чёрный, серый, белый.
   Янтарный — «ждёт тебя» (здесь: канал стоит проверить), синий — выделение.
   Зелёный и красный — только статусы. Углы ступеньками по 3 px, как PixelShape. */
@font-face { font-family: "Geist"; src: url("/static/fonts/geist.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url("/static/fonts/geist_mono.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Pixelify Sans"; src: url("/static/fonts/pixelify_sans.ttf") format("truetype"); font-weight: 400 700; font-display: swap; }

:root {
  --bg: #000;
  --panel: #0e0e0e;
  --raised: #141414;
  --sunk: #0a0a0d;
  --line: #262626;
  --hair: #1a1a1a;
  --ink: #ededed;
  --silver: #a1a1a1;
  --muted: #8f8f8f;
  --dim: #6f6f6f;
  --amber: #ffb547;
  --blue: #6e9bff;
  --mint: #3fb950;
  --danger: #ff6b6b;
  --body: "Geist", system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  --pixel: "Pixelify Sans", "Geist", sans-serif;
  /* Пружины IRemoted: spring(.62, 520) и нажатие spring(.6, 700). */
  --spring: cubic-bezier(.34, 1.42, .64, 1);
  --press: cubic-bezier(.3, 1.6, .6, 1);
}

* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: dark; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--body); -webkit-font-smoothing: antialiased; scrollbar-color: var(--line) transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
input, textarea { background: transparent; border: 0; outline: none; }
::placeholder { color: var(--dim); }
::selection { background: color-mix(in srgb, var(--blue) 35%, transparent); }
:focus-visible { outline: 1px solid var(--blue); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }
a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.hint { color: var(--dim); margin: 0; }
.mono { font-family: var(--mono); }
.no { color: var(--dim); }

/* --- Пиксельные поверхности ----------------------------------------------
   Внешний слой — кромка, ::before на 1 px внутри — заливка. Оба режутся одной
   ступенчатой формой, поэтому кромка тоже идёт ступеньками. */
.px { position: relative; isolation: isolate; clip-path: var(--shape); background: var(--edge, var(--line)); }
.px::before { content: ""; position: absolute; inset: 1px; z-index: -1; clip-path: var(--shape); background: var(--fill, var(--raised)); }
/* Горящая поверхность: белая LED-матрица с тёмными швами между клетками. */
.lit { --edge: var(--ink); color: #000; }
.lit::before {
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .13) 1px, transparent 1px) 0 0 / 3px 3px,
    linear-gradient(rgba(0, 0, 0, .13) 1px, transparent 1px) 0 0 / 3px 3px,
    var(--ink);
}
.px:is(button):active { transform: scale(.95); transition: transform .18s var(--press); }

.ghost { --fill: var(--raised); --edge: #2a2a2a; padding: 7px 13px; font-weight: 500; color: var(--ink); white-space: nowrap; }
.ghost:hover { --fill: #1c1c1c; }
.wide { width: 100%; }
.primary { padding: 0 22px; min-height: 50px; font: 500 16px var(--pixel); letter-spacing: .01em; word-spacing: .3em; white-space: nowrap; }
.primary:disabled { cursor: progress; opacity: .45; }

.field { --fill: var(--sunk); display: flex; align-items: center; min-width: 0; }
.field input { width: 100%; padding: 8px 10px; font-family: var(--mono); font-size: 13px; color: var(--ink); }
.field:focus-within { --edge: color-mix(in srgb, var(--ink) 70%, transparent); }
.field:focus-within::before {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px) 0 0 / 3px 3px,
    linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px) 0 0 / 3px 3px,
    var(--sunk);
}
.field.big { flex: 1; min-height: 50px; }
.field.big input { font: 16px var(--body); padding: 0 16px; }

/* --- Шапка: ASCII-поле и запрос ---------------------------------------------- */
.top { position: relative; overflow: hidden; border-bottom: 1px solid var(--hair); }
.ascii { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.top-in { position: relative; padding: 16px 24px 22px; max-width: 980px; }
.top-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 26px; font: 12px var(--mono); color: var(--dim); }
.brand { color: var(--silver); }
.signal { display: inline-flex; align-items: end; gap: 2px; height: 12px; }
.signal i { width: 3px; background: var(--ink); opacity: .14; border-radius: 1px; }
.signal i:nth-child(1) { height: 38%; } .signal i:nth-child(2) { height: 69%; } .signal i:nth-child(3) { height: 100%; }
.signal span { margin-left: 8px; line-height: 12px; white-space: nowrap; }
.signal.on i { animation: breathe 2.4s ease-in-out infinite; }
.signal.on i:nth-child(2) { animation-delay: .23s; } .signal.on i:nth-child(3) { animation-delay: .46s; }
.signal.off i:nth-child(1) { opacity: .35; }
.signal.off span { color: var(--amber); }
@keyframes breathe { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

.ask-label { display: block; font: 500 40px/1.05 var(--pixel); letter-spacing: -.02em; margin-bottom: 16px; }
.ask-row { display: flex; gap: 8px; }
.ask-more { margin-top: 12px; color: var(--muted); }
.ask-more summary { cursor: pointer; width: max-content; font: 13px var(--mono); list-style: none; }
.ask-more summary::before { content: "› "; color: var(--dim); }
.ask-more[open] summary::before { content: "▾ "; }
.ask-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-top: 12px; }
.ask-grid label { display: grid; gap: 5px; font-size: 12px; color: var(--dim); }
.seg { --fill: var(--sunk); display: flex; padding: 3px; gap: 2px; }
.seg button { flex: 1; padding: 5px 12px; font: 13px var(--mono); color: var(--muted); }
.seg button.on { color: #000; background: var(--ink); }
.warn { margin: 14px 0 0; color: var(--amber); font: 13px var(--mono); }

/* --- Раскладка: фильтры | таблица | карточка ----------------------------------- */
.layout { display: grid; grid-template-columns: 236px minmax(0, 1fr); align-items: start; padding-bottom: 96px; }
.layout.with-card { grid-template-columns: 236px minmax(0, 1fr) 390px; }
.filters { position: sticky; top: 0; max-height: 100vh; overflow: auto; padding: 20px 16px 110px 22px; }
.filters fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.filters legend { font-size: 12px; color: var(--muted); margin-bottom: 7px; padding: 0; }
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { --fill: var(--panel); --edge: #2a2a2a; padding: 5px 10px; display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--silver); }
.chips button.on { --edge: var(--ink); --fill: var(--ink); color: #000; }
.sq { width: 6px; height: 6px; display: inline-block; flex: none; }
.sq.good { background: var(--mint); } .sq.check { background: var(--amber); } .sq.weak { background: var(--danger); }
.sheet-head { display: none; }

.results { min-width: 0; padding: 20px 20px 40px 4px; }
.bar { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.bar h1 { font: 500 22px/1.15 var(--pixel); margin: 0; letter-spacing: -.01em; }
.bar-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.only-narrow { display: none; }
#selCount:empty { display: none; }

/* Ожидание как в Claude Code: звезда меняет форму, по глаголу бежит блик. */
.thinking { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; }
.thinking .glyph { font: 15px var(--mono); color: #d47452; width: 1ch; }
.thinking .verb { color: var(--dim); }
.thinking.running .verb {
  color: transparent;
  background: linear-gradient(90deg, var(--dim) 0 35%, #fff 50%, var(--dim) 65% 100%) 0 0 / 300% 100%;
  -webkit-background-clip: text; background-clip: text;
  animation: shimmer 1.8s linear infinite;
}
.thinking.done .glyph { color: var(--mint); }
.thinking.error .glyph, .thinking.error .verb { color: var(--danger); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
/* Загрузка — ряд пикселей, по которому идёт волна. */
.pxloader { display: flex; gap: 2px; margin-top: 10px; height: 6px; overflow: hidden; max-width: 420px; }
.pxloader i { flex: none; width: 6px; height: 6px; background: var(--ink); opacity: .08; animation: wave 1.6s ease-in-out infinite; }
@keyframes wave { 0%, 100% { opacity: .08; } 40% { opacity: .9; } }

/* --- Таблица -------------------------------------------------------------------- */
.table-wrap { background: #050505; overflow: auto; max-height: calc(100vh - 140px); padding-bottom: 76px; }
.table-wrap::before { display: none; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--hair); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 2; background: #050505; font: 11.5px var(--mono); color: var(--dim); user-select: none; }
th[data-sort] { cursor: pointer; }
th[data-sort]:hover, th.sorted { color: var(--ink); }
th.sorted::after { content: " ▾"; } th.sorted.asc::after { content: " ▴"; }
td { font-variant-numeric: tabular-nums; }
td.num { font-family: var(--mono); font-size: 13px; }
.num { text-align: right; }
tbody tr { cursor: pointer; background: #050505; }
tbody tr:hover, tbody tr:focus-visible { background: var(--panel); outline: none; }
tbody tr.open { background: #0b0f1a; }
tbody tr.open td.sel { box-shadow: inset 2px 0 var(--blue); }
td.name, th.name { position: sticky; left: 34px; background: inherit; z-index: 1; max-width: 270px; }
th.name { z-index: 3; }
/* Колонка чекбоксов строго 34 px: на неё опирается липкая колонка «Канал» (left: 34px).
   Без min-width пустая таблица сжимала её, и «Канал» наезжал на «Оценку». */
td.sel, th.sel { position: sticky; left: 0; width: 34px; min-width: 34px; max-width: 34px; padding: 0 0 0 12px; background: inherit; z-index: 1; }
th.sel { z-index: 3; }
td.sel input { appearance: none; margin: 0; width: 15px; height: 15px; background: var(--raised); border: 1px solid #333; display: grid; place-content: center; cursor: pointer; }
td.sel input:checked { background: var(--ink); border-color: var(--ink); }
td.sel input:checked::after { content: ""; width: 7px; height: 7px; background: #000; }
.ch-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 250px; }
.ch-user { font: 11.5px var(--mono); color: var(--dim); }
.fav { color: var(--amber); }
.sim-col { display: none; }
.similar .sim-col { display: table-cell; }
.score-cell { display: inline-flex; align-items: center; gap: 9px; font-weight: 500; }
.empty { padding: 44px 22px; color: var(--muted); max-width: 52ch; margin: 0; }
#more { margin: 10px; width: calc(100% - 20px); }

/* Оценка — десять LED-клеток, как полоска сигнала. */
.meter { display: inline-flex; gap: 1px; }
.meter i { width: 3px; height: 11px; background: #1f1f1f; }
.meter i.on { background: currentColor; }
.s-good { color: var(--mint); } .s-check { color: var(--amber); } .s-weak { color: var(--danger); }

/* --- История ---------------------------------------------------------------------- */
.history { display: grid; }
.history button { display: grid; grid-template-columns: 1fr auto auto; gap: 18px; text-align: left; padding: 14px 4px; border-bottom: 1px solid var(--hair); }
.history button:hover { background: var(--panel); }
.history .q::before { content: "› "; color: var(--dim); font-family: var(--mono); }
.history .hint { font: 12px var(--mono); }

/* --- Карточка канала ------------------------------------------------------------ */
.card { position: sticky; top: 0; max-height: 100vh; overflow: auto; background: #070707; border-left: 1px solid var(--hair); padding: 18px 20px 120px; }
.card h2 { font: 500 22px/1.15 var(--pixel); margin: 0 0 6px; letter-spacing: -.01em; }
.card h3 { font: 12px var(--mono); color: var(--dim); margin: 24px 0 9px; }
.card .about { white-space: pre-wrap; margin: 0; color: var(--silver); max-width: 60ch; }
.card-sub { font: 12px var(--mono); color: var(--dim); margin: 0; }
.card-top { display: flex; justify-content: flex-end; margin-bottom: 6px; }
/* Дисплейная полоса над оценкой: сетка клеток гаснет книзу. */
.verdict {
  display: flex; align-items: end; gap: 16px; margin: 16px -20px 4px; padding: 18px 20px 14px;
  background:
    linear-gradient(90deg, #070707 1px, transparent 1px) 0 0 / 3px 3px,
    linear-gradient(#070707 1px, transparent 1px) 0 0 / 3px 3px,
    linear-gradient(rgba(255, 255, 255, .07), transparent 85%);
}
.big-score { font: 500 64px/.85 var(--pixel); letter-spacing: -.04em; }
.big-score small { font: 13px var(--mono); color: var(--dim); letter-spacing: 0; margin-left: 4px; }
.verdict .meter { margin-bottom: 4px; } .verdict .meter i { width: 5px; height: 22px; }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 2px; }
.why ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 5px; }
.why li { padding-left: 18px; position: relative; }
.why li::before { position: absolute; left: 0; font-family: var(--mono); }
.why .plus li::before { content: "+"; color: var(--mint); }
.why .minus li::before { content: "−"; color: var(--danger); }
.why li.no::before { content: none; }
.flags { --fill: #1f1708; --edge: color-mix(in srgb, var(--amber) 35%, transparent); margin-top: 14px; padding: 12px 14px; }
.flags strong { color: var(--amber); font-weight: 500; }
.flags ul { margin: 6px 0 0; padding-left: 0; list-style: none; display: grid; gap: 4px; color: #f3dcb4; }
.flags li::before { content: "! "; font-family: var(--mono); color: var(--amber); }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; font: 13px var(--mono); }
dl.kv dd.key { color: #fff; font-weight: 600; }
.contact { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.contact strong { font: 500 16px var(--mono); margin-right: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 22px; }
.actions .primary { min-height: 44px; font-size: 15px; }
.marks { display: grid; gap: 8px; }
.marks textarea { width: 100%; min-height: 76px; resize: vertical; padding: 9px 10px; font-size: 13px; }
.marks .field.area { align-items: stretch; }
.star.on { --edge: var(--amber); --fill: #1f1708; color: var(--amber); }
.mark-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.spark { width: 100%; height: 40px; color: var(--ink); margin: 6px 0; }
.hist-table { width: 100%; font: 12px var(--mono); }
.hist-table td, .hist-table th { padding: 4px 0; border: 0; position: static; background: none; }
.delta { font: 500 15px var(--mono); }

/* --- Плавающая панель разделов -------------------------------------------------- */
.dock {
  --fill: rgba(12, 12, 12, .96); --edge: #222;
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 45;
  transform: translateX(-50%); display: grid; grid-template-columns: repeat(3, 1fr); padding: 5px; width: min(420px, calc(100vw - 28px));
}
.dock button { position: relative; z-index: 1; height: 46px; font-weight: 500; color: var(--muted); transition: color .22s; }
.dock button.on { color: #000; }
.dock-blob { position: absolute; top: 5px; left: 5px; height: 46px; width: calc((100% - 10px) / 3); transition: transform .42s var(--spring); }

.toast { --fill: var(--raised); position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); padding: 11px 16px; z-index: 60; max-width: 90vw; font-size: 13px; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); z-index: 30; }

/* --- Узкий экран: фильтры и карточка — шторки ----------------------------------- */
@media (max-width: 1100px) {
  .layout, .layout.with-card { grid-template-columns: minmax(0, 1fr); }
  .results { padding: 16px 12px 40px; }
  .only-narrow { display: inline-block; }
  .filters, .card {
    position: fixed; z-index: 50; top: auto; left: 0; right: 0; bottom: 0; max-height: 88vh;
    background: #070707; border: 0; border-top: 1px solid var(--line); padding: 0 18px 32px;
    transform: translateY(105%); transition: transform .42s var(--spring); overflow: auto;
  }
  .filters.open, .card.open { transform: none; }
  .card { max-height: 94vh; }
  .sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #070707; padding: 14px 0 10px; z-index: 2; }
  .sheet-head h2 { margin: 0; font: 500 20px var(--pixel); }
  .card-top { position: sticky; top: 0; background: #070707; padding: 12px 0 6px; z-index: 2; }
  .table-wrap { max-height: none; }
}
@media (max-width: 640px) {
  .top-in { padding: 14px 14px 18px; }
  .top-meta { margin-bottom: 20px; }
  .ask-label { font-size: 32px; }
  .ask-row { flex-direction: column; }
  .ask-grid { grid-template-columns: 1fr; }
  th, td { padding: 9px 9px; }
  /* Четыре кнопки над таблицей — одной ровной строкой. */
  .bar-actions { display: grid; grid-template-columns: repeat(4, auto); width: 100%; }
  .bar-actions .ghost { padding: 7px 8px; font-size: 13px; text-align: center; }
  #selCount { grid-column: 1 / -1; order: 5; }
}
@media (pointer: coarse) {
  .ghost, .chips button { min-height: 40px; }
  .seg button { min-height: 36px; }
  td.sel input { width: 20px; height: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .filters, .card, .dock-blob { transition: none; }
  .signal.on i, .pxloader i, .thinking.running .verb { animation: none; }
  .thinking.running .verb { color: var(--silver); background: none; }
}

/* Ступенчатые формы: тот же расчёт, что PixelShape в IRemoted (клетка 3 px). */
.px9 { --shape: polygon(0px 9px, 0px 6px, 0px 3px, 3px 3px, 3px 0px, calc(100% - 3px) 0px, calc(100% - 3px) 3px, calc(100% - 0px) 3px, calc(100% - 0px) 6px, calc(100% - 0px) 9px, calc(100% - 0px) calc(100% - 9px), calc(100% - 0px) calc(100% - 6px), calc(100% - 0px) calc(100% - 3px), calc(100% - 3px) calc(100% - 3px), calc(100% - 3px) calc(100% - 0px), 3px calc(100% - 0px), 3px calc(100% - 3px), 0px calc(100% - 3px), 0px calc(100% - 6px), 0px calc(100% - 9px)); }
.px12 { --shape: polygon(0px 12px, 0px 9px, 0px 6px, 3px 6px, 3px 3px, 6px 3px, 6px 0px, calc(100% - 6px) 0px, calc(100% - 6px) 3px, calc(100% - 3px) 3px, calc(100% - 3px) 6px, calc(100% - 0px) 6px, calc(100% - 0px) 9px, calc(100% - 0px) 12px, calc(100% - 0px) calc(100% - 12px), calc(100% - 0px) calc(100% - 9px), calc(100% - 0px) calc(100% - 6px), calc(100% - 3px) calc(100% - 6px), calc(100% - 3px) calc(100% - 3px), calc(100% - 6px) calc(100% - 3px), calc(100% - 6px) calc(100% - 0px), 6px calc(100% - 0px), 6px calc(100% - 3px), 3px calc(100% - 3px), 3px calc(100% - 6px), 0px calc(100% - 6px), 0px calc(100% - 9px), 0px calc(100% - 12px)); }
.px15 { --shape: polygon(0px 15px, 0px 12px, 0px 9px, 3px 9px, 3px 6px, 3px 3px, 9px 3px, 9px 0px, calc(100% - 9px) 0px, calc(100% - 9px) 3px, calc(100% - 3px) 3px, calc(100% - 3px) 6px, calc(100% - 3px) 9px, calc(100% - 0px) 9px, calc(100% - 0px) 12px, calc(100% - 0px) 15px, calc(100% - 0px) calc(100% - 15px), calc(100% - 0px) calc(100% - 12px), calc(100% - 0px) calc(100% - 9px), calc(100% - 3px) calc(100% - 9px), calc(100% - 3px) calc(100% - 6px), calc(100% - 3px) calc(100% - 3px), calc(100% - 9px) calc(100% - 3px), calc(100% - 9px) calc(100% - 0px), 9px calc(100% - 0px), 9px calc(100% - 3px), 3px calc(100% - 3px), 3px calc(100% - 6px), 3px calc(100% - 9px), 0px calc(100% - 9px), 0px calc(100% - 12px), 0px calc(100% - 15px)); }
.px20 { --shape: polygon(0px 21px, 0px 18px, 0px 15px, 0px 12px, 3px 12px, 3px 9px, 3px 6px, 6px 6px, 6px 3px, 12px 3px, 12px 0px, calc(100% - 12px) 0px, calc(100% - 12px) 3px, calc(100% - 6px) 3px, calc(100% - 6px) 6px, calc(100% - 3px) 6px, calc(100% - 3px) 9px, calc(100% - 3px) 12px, calc(100% - 0px) 12px, calc(100% - 0px) 15px, calc(100% - 0px) 18px, calc(100% - 0px) 21px, calc(100% - 0px) calc(100% - 21px), calc(100% - 0px) calc(100% - 18px), calc(100% - 0px) calc(100% - 15px), calc(100% - 0px) calc(100% - 12px), calc(100% - 3px) calc(100% - 12px), calc(100% - 3px) calc(100% - 9px), calc(100% - 3px) calc(100% - 6px), calc(100% - 6px) calc(100% - 6px), calc(100% - 6px) calc(100% - 3px), calc(100% - 12px) calc(100% - 3px), calc(100% - 12px) calc(100% - 0px), 12px calc(100% - 0px), 12px calc(100% - 3px), 6px calc(100% - 3px), 6px calc(100% - 6px), 3px calc(100% - 6px), 3px calc(100% - 9px), 3px calc(100% - 12px), 0px calc(100% - 12px), 0px calc(100% - 15px), 0px calc(100% - 18px), 0px calc(100% - 21px)); }
