:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --card: var(--tg-theme-bg-color, #ffffff);
  --ink: var(--tg-theme-text-color, #16181d);
  --muted: var(--tg-theme-hint-color, #6b7280);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-ink: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2a7de1);
  --line: rgba(127, 127, 127, .18);
  --soft: rgba(127, 127, 127, .09);
  --warm: #fff6e0;
  --warm-ink: #5b4300;
  --ok: #1f9d55;
  --bad: #d14343;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) { --bg: #101114; --card: #1b1d22; --ink: #eceef2; --muted: #9aa1ad; --warm: #3a3320; --warm-ink: #f3e3b0; }
}
:root[data-dark] { --warm: #3a3320; --warm-ink: #f3e3b0; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.42 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; }

header#top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 12px 16px 8px; }
#title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
#subtitle { font-size: 13px; color: var(--muted); min-height: 18px; }
main { padding: 0 12px 12px; }

nav#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: center; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav#tabs a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 0 8px;
  color: var(--muted); font-size: 11px; }
nav#tabs a .ti { font-size: 18px; filter: grayscale(1); opacity: .7; }
nav#tabs a.on { color: var(--accent); font-weight: 600; }
nav#tabs a.on .ti { filter: none; opacity: 1; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; border-radius: 16px; padding: 6px 11px; background: var(--card); font-size: 13px; color: var(--ink); cursor: pointer; }
.chip b { font-weight: 600; color: var(--muted); margin-left: 3px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chip.on b { color: var(--accent-ink); opacity: .85; }
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 2px; margin: 0 0 10px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 6px 4px; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.card { background: var(--card); border-radius: var(--radius); padding: 11px 13px; margin-bottom: 8px; cursor: pointer; }
.card:active { opacity: .85; }
.row1 { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); }
.age.hot { color: #d9480f; font-weight: 600; }
.sum { font-weight: 600; margin: 3px 0 2px; font-size: 15px; }
.txt { font-size: 13.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.badge { font-size: 11.5px; background: var(--soft); border-radius: 8px; padding: 2px 7px; color: var(--ink); }
.badge.mine { background: #e7f6ec; color: #11683a; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 34px; margin-bottom: 6px; }

.box { background: var(--card); border-radius: var(--radius); padding: 12px 13px; margin-bottom: 10px; }
.box h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.post-text { font-size: 15.5px; white-space: pre-wrap; word-wrap: break-word; }
.root-text { font-size: 13.5px; color: var(--muted); white-space: pre-wrap; border-left: 3px solid var(--line); padding-left: 9px; margin-bottom: 8px; }
.meta { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.status-line { font-size: 13px; padding: 9px 12px; border-radius: 10px; background: var(--soft); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

details.thread summary { cursor: pointer; font-size: 14px; font-weight: 600; list-style: none; }
details.thread summary::-webkit-details-marker { display: none; }
details.thread summary::after { content: " ▾"; color: var(--muted); }
.cm { border-top: 1px solid var(--line); padding: 7px 0; font-size: 13.5px; }
.cm .who { font-size: 12px; color: var(--muted); }
.cm .who b { color: var(--ink); font-weight: 600; }
.cm.own { background: #eef8f1; margin: 0 -8px; padding: 7px 8px; border-radius: 8px; }

.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 12px; font-size: 15px; font-weight: 600; text-align: center;
  background: var(--soft); color: var(--ink); cursor: pointer; }
.btn.main { background: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 8px 10px; font-size: 13.5px; font-weight: 500; }
.btn[disabled] { opacity: .5; }
.btns { display: flex; gap: 8px; margin-top: 8px; }
.btns .btn { flex: 1; }
.actions { position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 75%, transparent); padding: 10px 0 4px; }

.analysis { background: var(--warm); color: var(--warm-ink); border-radius: var(--radius); padding: 11px 13px; margin-bottom: 10px; font-size: 14px; }
.analysis .verdict { font-weight: 700; margin-right: 4px; }
.variant { background: var(--card); border-radius: var(--radius); padding: 11px 12px; margin-bottom: 10px; }
.variant .vtag { font-size: 12.5px; color: var(--accent); font-weight: 600; }
.variant .why { font-size: 12.5px; color: var(--muted); margin: 1px 0 6px; }
.variant textarea { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 10px; padding: 9px 10px;
  font-size: 15px; line-height: 1.4; font-family: inherit; resize: none; overflow: hidden; min-height: 70px; }
.variant .count { font-size: 11.5px; color: var(--muted); text-align: right; margin: 2px 0 6px; }
.variant .count.over { color: var(--bad); font-weight: 600; }
.loading { text-align: center; padding: 34px 10px; color: var(--muted); }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); margin: 0 auto 10px; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.cost { font-size: 12px; color: var(--muted); text-align: center; margin: 4px 0 10px; }

.nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.num { background: var(--card); border-radius: 12px; padding: 9px 6px; text-align: center; }
.num b { display: block; font-size: 20px; }
.num span { font-size: 11.5px; color: var(--muted); }
.bar-row { margin: 7px 0; font-size: 13.5px; }
.bar-row .l { display: flex; justify-content: space-between; }
.bar { height: 6px; border-radius: 3px; background: var(--soft); margin-top: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: right; font-weight: 500; color: var(--muted); font-size: 11.5px; padding: 4px 3px; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t td { text-align: right; padding: 6px 3px; border-top: 1px solid var(--line); }
table.t td.zero { color: var(--muted); }

.list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 2px; border-top: 1px solid var(--line); cursor: pointer; }
.list-item:first-of-type { border-top: 0; }
.list-item .sub { font-size: 12.5px; color: var(--muted); }
.chev { color: var(--muted); font-size: 18px; }
.kw-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.kw-row .sub { font-size: 12px; color: var(--muted); }
.kw-row .x { border: 0; background: var(--soft); border-radius: 50%; width: 30px; height: 30px; font-size: 15px; color: var(--muted); cursor: pointer; flex: none; }
.add-row { display: flex; gap: 8px; }
input.in, textarea.in, select.in { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 10px; padding: 10px; font: inherit; }
textarea.in { min-height: 90px; resize: vertical; }
label.f { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.prod { padding: 10px 2px; border-top: 1px solid var(--line); cursor: pointer; }
.prod:first-of-type { border-top: 0; }
.prod .sub { font-size: 12.5px; color: var(--muted); }
.prod.off { opacity: .5; }
.mine-item .reply { font-size: 13.5px; background: var(--soft); border-radius: 10px; padding: 8px 10px; margin-top: 6px; white-space: pre-wrap; }

#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; box-shadow: 0 -4px 20px rgba(0,0,0,.15); }
#sheet h2 { margin: 0 0 10px; font-size: 17px; }
#sheet .chips { flex-wrap: wrap; }
#sheet .chip { background: var(--soft); }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  background: rgba(20,20,24,.92); color: #fff; padding: 9px 14px; border-radius: 12px; font-size: 14px; max-width: 90vw; text-align: center; }
.box .chip { background: var(--soft); }
.box .chip.on { background: var(--accent); }
