/* Нейробюро — оформление мини-аппа по дизайн-системе (кобальт, красный, лен).
   Тема «Лен» по умолчанию, «Ночной кобальт» — когда в Telegram включена темная тема. */
:root {
  --cobalt: #1a6fbf; --cobalt-deep: #0f4e8f; --cobalt-tint: #d7e5f4; --cobalt-text: #1a6fbf;
  --scarlet: #d91a2a; --scarlet-text: #c4141f; --scarlet-tint: #f8dcd8;
  --linen: #f5f0e8; --ground: #f5f0e8; --surface: #fffdf9; --ink: #0f1b33; --ink-muted: #5a6275;
  --line: #dcd3c3; --line-strong: #767c8e; --on-brand: #ffffff; --warning: #8f5500; --focus: #0f1b33;
  --shadow-print: 4px 4px 0 #0f1b33; --shadow-pop: 6px 6px 0 #d91a2a;
  --t1: #d7e5f4; --t2: #f8dcd8; --t3: #e6ddcc; --t4: #bcd5ef; --t5: #f3c3bd; --t6: #d9d0bf;
  --font-display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --font-sans: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --radius-sm: 6px; --radius-md: 16px; --radius-lg: 28px; --radius-pill: 999px;
  --ease: cubic-bezier(.2,.9,.2,1.2);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --cobalt-deep: #9cc4f0; --cobalt-tint: #173a63; --cobalt-text: #6fa9e8;
  --scarlet-text: #ff5a63; --scarlet-tint: #4a1a22;
  --ground: #0d1a2e; --surface: #15273f; --ink: #f5f0e8; --ink-muted: #a9b4c6;
  --line: #2a3e5c; --line-strong: #6c7d99; --warning: #f2b547; --focus: #f5f0e8;
  --shadow-print: 4px 4px 0 #050b16;
  --t1: #173a63; --t2: #4a1a22; --t3: #2a3e5c; --t4: #1f4f86; --t5: #6b2333; --t6: #33465f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--ink); font: 16px/1.5 var(--font-sans); -webkit-font-smoothing: antialiased;
  padding: 12px 12px calc(28px + env(safe-area-inset-bottom, 0px)); }
#app { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-3); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; margin: 0; text-wrap: balance; color: var(--ink); letter-spacing: -.01em; }
h1 { font-size: 30px; font-weight: 800; } h2 { font-size: 21px; font-weight: 700; } h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
img { max-width: 100%; }

/* Карточки и метки */
.card { background: var(--surface); border-radius: var(--radius-lg); padding: var(--space-5) 20px; display: flex; flex-direction: column; gap: var(--space-3);
  min-width: 0; box-shadow: inset 0 0 0 1px var(--line); animation: nb-pop .3s var(--ease) both; }
.card.hero { background: var(--cobalt); color: var(--on-brand); box-shadow: none; overflow: hidden; position: relative; }
.card.hero h1, .card.hero h2, .card.hero p { color: var(--on-brand); }
.eyebrow { font: 600 12px/1.3 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted);
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.eyebrow .ico-l { display: inline-flex; align-items: center; gap: 8px; }
.eyebrow .ico-l img { width: 32px; height: 32px; }
.muted { color: var(--ink-muted); font-size: 14px; }
.accent { color: var(--scarlet-text); font-weight: 600; }
.rich { display: flex; flex-direction: column; gap: 10px; font-size: 16px; }
.rich ul, .rich ol { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.rich dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; }
.rich dt { font: 600 14px var(--font-mono); color: var(--cobalt-text); }
.rich dd { margin: 0; }
.rich blockquote { margin: 0; padding: 12px 14px; border-radius: var(--radius-md); background: var(--scarlet-tint); color: var(--ink); }
.rich h3 { margin-top: 6px; }

body.teacher .card { animation: none; }

/* Кнопки */
.btn { appearance: none; border: 0; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
  min-height: 48px; padding: 0 20px; border-radius: var(--radius-md); background: var(--cobalt); color: var(--on-brand);
  font: 600 15px/1.2 var(--font-sans); transition: transform .18s var(--ease), background .18s; }
.btn:hover { background: var(--cobalt-deep); color: var(--on-brand); }
:root[data-theme="dark"] .btn:hover { background: #2a7fd0; }
.btn:active { transform: translate(2px, 2px); }
.btn.ghost { background: var(--cobalt-tint); color: var(--cobalt-deep); }
.btn.ghost:hover { box-shadow: inset 0 0 0 2px var(--cobalt-deep); background: var(--cobalt-tint); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 12px; }
.btn.accent { background: var(--scarlet); }
.btn.ok { background: var(--cobalt); color: var(--on-brand); }
.btn.no { background: var(--scarlet-tint); color: var(--scarlet-text); box-shadow: inset 0 0 0 2px var(--scarlet-text); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.col > .btn { justify-content: flex-start; text-align: left; min-height: 52px; font-weight: 500; font-size: 16px; }
.col > .btn.ghost { background: var(--ground); color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.col > .btn.ghost:hover { box-shadow: inset 0 0 0 2px var(--cobalt-deep); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; min-width: 120px; }
.col { display: flex; flex-direction: column; gap: 8px; }

/* Пилюли и штамп */
.pill { display: inline-flex; align-items: center; gap: 4px; font: 600 12px/1.4 var(--font-mono); padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--cobalt-tint); color: var(--cobalt-deep); white-space: nowrap; }
.pill.good { background: var(--cobalt); color: var(--on-brand); }
.pill.bad { background: var(--scarlet-tint); color: var(--scarlet-text); }
.pill.stamp { background: var(--cobalt); color: var(--on-brand); text-transform: uppercase; letter-spacing: .06em; transform: rotate(-4deg);
  box-shadow: 2px 2px 0 var(--ink); animation: nb-stamp .36s var(--ease) both; }

/* Поля ввода */
input[type=text], input[type=number], select, textarea { width: 100%; border: 0; box-shadow: inset 0 0 0 2px var(--line-strong); background: var(--surface);
  border-radius: 12px; padding: 12px 14px; resize: vertical; min-width: 0; color: var(--ink); }
input:focus, select:focus, textarea:focus { box-shadow: inset 0 0 0 2px var(--cobalt-text); outline: none; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
label.check input { width: 20px; height: 20px; accent-color: var(--cobalt); margin-top: 2px; }
label.col { font-size: 14px; font-weight: 600; }

/* Профиль, XP, прогресс */
.xpbar { height: 10px; border-radius: var(--radius-pill); background: var(--cobalt-tint); overflow: hidden; }
.xpbar i { display: block; height: 100%; background: var(--cobalt); border-radius: var(--radius-pill); }
.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.profile { display: grid; grid-template-columns: 52px 1fr; gap: 14px; align-items: center; }
.profile > img { width: 52px; height: 52px; }
.profile .num { font: 600 26px/1 var(--font-mono); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big { font: 600 28px/1.1 var(--font-mono); font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--ground); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; box-shadow: inset 0 0 0 1px var(--line); }

/* Шапка эпизода */
.episode { background: var(--cobalt); color: var(--on-brand); border-radius: var(--radius-lg); padding: 16px 20px 18px; display: flex; flex-direction: column; gap: 10px;
  position: relative; overflow: hidden; }
.episode .eyebrow { color: var(--on-brand); opacity: .9; }
.episode__title { font: 800 22px/1.05 var(--font-display); letter-spacing: -.01em; margin: 0; color: var(--on-brand); position: relative; z-index: 1; }
.episode .burst { position: absolute; right: -62px; top: -60px; width: 150px; height: 150px; opacity: .95; animation: nb-spin 22s linear infinite; }
.timer { font: 600 15px var(--font-mono); font-variant-numeric: tabular-nums; color: var(--cobalt-text); }
.episode .timer { color: var(--on-brand); font-size: 22px; position: relative; z-index: 1; }
.timer.late { color: var(--on-brand) !important; background: var(--scarlet); border-radius: var(--radius-sm); padding: 0 8px; }
.progress { display: flex; gap: 4px; position: relative; z-index: 1; }
.progress i { flex: 1; height: 9px; border-radius: 3px; background: rgba(255,255,255,.28); }
.progress i.done { background: var(--linen); }
.progress i.now { background: var(--scarlet); }

/* Плашки контента */
.prompt { font: 13px/1.5 var(--font-mono); background: var(--ground); border-radius: 12px; padding: 12px; white-space: pre-wrap; word-break: break-word; box-shadow: inset 0 0 0 1px var(--line); }
.answer { background: var(--ground); border-radius: 12px; padding: 12px 14px; font-size: 15px; white-space: pre-wrap; word-break: break-word; box-shadow: inset 0 0 0 1px var(--line); }
.mascot { width: 104px; height: auto; align-self: flex-start; }
.mascot.right { align-self: flex-end; }

/* Токенизатор и токенорезка */
.tok { font: 14px/2.1 var(--font-mono); word-break: break-word; }
.tok span { border-radius: 4px; padding: 3px 1px; white-space: pre-wrap; color: var(--ink); }
.tok span:nth-child(6n+1) { background: var(--t1); } .tok span:nth-child(6n+2) { background: var(--t2); }
.tok span:nth-child(6n+3) { background: var(--t3); } .tok span:nth-child(6n+4) { background: var(--t4); }
.tok span:nth-child(6n+5) { background: var(--t5); } .tok span:nth-child(6n+6) { background: var(--t6); }
.cutter { font: 22px/1.4 var(--font-mono); display: flex; flex-wrap: wrap; row-gap: 12px; user-select: none; }
.cutter .ch { padding: 4px 0; }
.cutter .gap { width: 14px; cursor: pointer; position: relative; align-self: stretch; }
.cutter .gap::after { content: ""; position: absolute; left: 6px; top: 2px; bottom: 2px; width: 2px; border-radius: 2px; background: var(--line); }
.cutter .gap.on::after { background: var(--cobalt-text); width: 3px; }
.cutter .gap.hit::after { background: var(--cobalt-text); width: 4px; }
.cutter .gap.miss::after { background: var(--scarlet); width: 4px; }
.cutter .gap.lost::after { background: var(--warning); width: 4px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* Эксперимент, голосование, бары */
.trap { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.seg { display: inline-flex; border-radius: 12px; overflow: hidden; box-shadow: inset 0 0 0 2px var(--line); }
.seg button { border: 0; background: none; padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink); }
.seg button.on.y { background: var(--cobalt); color: var(--on-brand); }
.seg button.on.n { background: var(--scarlet); color: var(--on-brand); }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(0, 1.2fr) 2fr 36px; gap: 8px; align-items: center; font-size: 13px; }
.bar .tr { height: 12px; background: var(--cobalt-tint); border-radius: 99px; overflow: hidden; }
.bar .tr i { display: block; height: 100%; background: var(--cobalt); border-radius: 99px; }
.bar b { font: 600 13px var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }
.stars { display: flex; gap: 4px; }
.stars button { border: 0; box-shadow: inset 0 0 0 2px var(--line); background: var(--surface); width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  font: 600 13px var(--font-mono); color: var(--ink); }
.stars button.on { background: var(--cobalt); color: var(--on-brand); box-shadow: none; }
.crit { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.item { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
td, th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font: 600 11px var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
.scroll { overflow-x: auto; }
.list { display: flex; flex-direction: column; }
.list > div { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.list > div .grow { flex: 1; min-width: 0; }
.clip { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; font-size: 13px; color: var(--ink-muted); }
details summary { cursor: pointer; }

/* Тост */
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--ground);
  padding: 12px 18px; border-radius: 14px; max-width: calc(100% - 32px); font-size: 14px; font-weight: 500; z-index: 20; box-shadow: var(--shadow-pop); animation: nb-pop .3s var(--ease) both; }

/* Шторка между блоками: кобальт, затем красный */
.wipe { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.wipe::before, .wipe::after { content: ""; position: absolute; inset: 0; transform: translateX(-101%); }
.wipe::before { background: var(--cobalt); animation: nb-wipe .42s cubic-bezier(.7,0,.2,1) both; }
.wipe::after { background: var(--scarlet); animation: nb-wipe .42s .08s cubic-bezier(.7,0,.2,1) both; }

@keyframes nb-pop { 0% { transform: scale(.94); } 70% { transform: scale(1.015); } 100% { transform: scale(1); } }
@keyframes nb-stamp { 0% { transform: scale(1.25) rotate(-16deg); } 60% { transform: scale(.94) rotate(-2deg); } 100% { transform: scale(1) rotate(-4deg); } }
@keyframes nb-spin { to { transform: rotate(360deg); } }
@keyframes nb-wipe { 0% { transform: translateX(-101%); } 45% { transform: translateX(0); } 100% { transform: translateX(101%); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .wipe { display: none; }
}
