:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1b1f2a;
  --muted: #6b7285;
  --line: #e3e6ee;
  --accent: #3b5bfd;
  --accent-soft: #e8edff;
  --on-accent: #ffffff;
  --ok: #1f9d55;
  --ok-soft: #e3f6ea;
  --bad: #d64545;
  --bad-soft: #fde8e8;
  --radius: 16px;
  --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --card: #1a1d26; --text: #eceef4; --muted: #9aa1b3; --line: #2a2e3a;
    --accent: #8fa2ff; --accent-soft: #232a45; --on-accent: #0f1117; --ok-soft: #173325; --bad-soft: #3a1c1c;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --card: #1a1d26; --text: #eceef4; --muted: #9aa1b3; --line: #2a2e3a;
  --accent: #8fa2ff; --accent-soft: #232a45; --on-accent: #0f1117; --ok-soft: #173325; --bad-soft: #3a1c1c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: .3px; }
.quota {
  border: 0; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 14px;
}
.quota-sep { margin: 0 6px; opacity: .6; }

main { padding: 0 16px; max-width: 640px; margin: 0 auto; }
.hero { padding: 8px 0 16px; }
.hero h1 { margin: 0 0 4px; font-size: 26px; line-height: 1.2; }
.hero p { margin: 0; color: var(--muted); }
.hero.small h1 { font-size: 22px; }

.segment { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.segment button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.segment button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 56px; margin-bottom: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  font-weight: 600; cursor: pointer;
}
.big-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); min-height: 72px; font-size: 18px; }
.big-btn .ico { display: inline-flex; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card textarea, .form input, .form select, .ask input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); outline: none;
}
.card textarea:focus, .form input:focus, .form select:focus, .ask input:focus { border-color: var(--accent); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.thumbs:empty { display: none; }
.thumbs img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.thumb { position: relative; }
.thumb button { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); font-size: 14px; line-height: 1; }

.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.actions.wide > * { flex: 1; }
button.primary, button.ghost {
  border-radius: 12px; padding: 11px 16px; font-weight: 600; border: 1px solid var(--accent); cursor: pointer;
}
button.primary { background: var(--accent); color: var(--on-accent); }
button.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .5; }
button.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 0; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 20px 0 8px; }
.section-head h2, .run-title { margin: 0; font-size: 18px; }
.run-title { margin: 8px 0 12px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
}
.item img { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; }
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .side { flex: none; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }

.label { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.md { overflow-wrap: anywhere; }
.md h2 { font-size: 17px; margin: 14px 0 6px; }
.md h2:first-child { margin-top: 0; }
.md p { margin: 6px 0; }
.md ol, .md ul { padding-left: 22px; margin: 6px 0; }
.md li { margin: 4px 0; }
.md code { background: var(--bg); padding: 1px 5px; border-radius: 6px; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; margin: .5em 0; }
.answer h2:first-child + p, .answer h2:first-child + ul {
  background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; font-weight: 600;
}

.chat { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bubble { padding: 10px 12px; border-radius: 14px; max-width: 92%; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--on-accent); }
.bubble.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.ask { display: flex; gap: 8px; }
.ask button { flex: none; width: 48px; padding: 0; display: flex; align-items: center; justify-content: center; }

.form label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.form label > input, .form label > select { margin-top: 4px; color: var(--text); }
.form button.primary { width: 100%; }
.note { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.center { text-align: center; }

.ptask { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.ptask .n { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.ptask form { display: flex; gap: 8px; margin-top: 10px; }
.ptask form input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: var(--bg); }
.ptask .hint { margin-top: 8px; font-size: 14px; color: var(--muted); }
.verdict { margin-top: 10px; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.verdict.ok { background: var(--ok-soft); }
.verdict.bad { background: var(--bad-soft); }
.verdict b { display: block; margin-bottom: 2px; }

.status { text-align: center; }
.status .big { font-size: 34px; font-weight: 800; line-height: 1.1; }
.offer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.offer-title { font-weight: 700; }
.offer-sub { color: var(--muted); font-size: 14px; }
.price { font-weight: 700; white-space: nowrap; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: 12px;
}
.tabs button.on { color: var(--accent); font-weight: 600; }

.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 12, 20, .55);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: #fff; font-weight: 600;
}
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); z-index: 30;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 14px; text-align: center; font-size: 14px;
}
.toast.error { background: var(--bad); color: #fff; }
.more { width: 100%; margin-top: 12px; }
button.small { padding: 7px 14px; }
.about { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 28px 0 8px; font-size: 14px; }
.about a { color: var(--muted); }
button.link.danger { color: var(--bad); font-weight: 500; }
