/* ============================================================================
   Agent Hub — дизайн-система.

   Естетика: тепла редакційна сторінка. Кремовий папір, приглушений беж як
   єдиний акцент, серифні заголовки. Орієнтир — власна айдентика Anthropic: у неї
   немає нічого від «технологічного синього», вона паперова й книжкова,
   і курсу про їхні матеріали це личить більше, ніж інтерфейс приладу.

   Чому сериф. Це найпомітніша відмінність від споріднених проєктів і
   водночас функціональне рішення: уроки тут — суцільний текст на 700–1300
   слів, і серифний заголовок сам собою каже «це стаття, її читають», а не
   «це панель, з неї знімають показники».
   ============================================================================ */

/* ─────────────────────────────────────────────────────────────── токени */

:root {
  color-scheme: light;

  --bg:          #F4F1EA;
  --surface:     #FFFDFA;
  --surface-2:   #FAF7F1;
  --surface-3:   #EFEAE0;
  --border:      #E3DCCF;
  --border-2:    #D0C6B5;

  --ink:         #1C1A17;
  --ink-2:       #4C463E;
  --muted:       #857C6F;

  --accent:      #7D6248;
  --accent-ink:  #FFFFFF;
  --accent-soft: #F0E7D8;
  --accent-line: #D6C3A4;

  --warn:        #8A6420;
  --warn-soft:   #F7EEDC;
  --danger:      #A0332A;
  --danger-soft: #F9E6E2;
  --info:        #3A6B78;
  --info-soft:   #E5EFF1;

  --code-bg:     #FBF8F2;
  --code-border: #E9E1D3;

  --radius:      14px;
  --radius-sm:   10px;
  --radius-lg:   20px;

  --shadow-sm: 0 1px 2px rgba(60, 45, 30, .05), 0 1px 3px rgba(60, 45, 30, .04);
  --shadow:    0 2px 4px rgba(60, 45, 30, .04), 0 8px 24px rgba(60, 45, 30, .07);
  --shadow-lg: 0 4px 8px rgba(60, 45, 30, .05), 0 24px 56px rgba(60, 45, 30, .12);

  --serif: 'Literata', Georgia, 'Times New Roman', serif;
  --font:  'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono:  'IBM Plex Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  --sidebar-w: 268px;
  --maxw: 1160px;

  /* підсвітка коду: відтінки підібрані під теплий папір, а не під білий */
  --syn-kw:      #4A4FA8;
  --syn-fn:      #7B4397;
  --syn-str:     #4A7A3C;
  --syn-num:     #9A5B23;
  --syn-comment: #9A9184;
  --syn-punct:   #7A7267;
}

/*
 * Темна тема тепла, а не графітова: холодний сірий поруч із теракотою
 * дає брудний контраст, і вечірнє читання стає неприємним.
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg:          #16140F;
    --surface:     #1E1B16;
    --surface-2:   #25211B;
    --surface-3:   #2F2A22;
    --border:      #322C24;
    --border-2:    #453E33;

    --ink:         #EDE7DC;
    --ink-2:       #B5AC9D;
    --muted:       #857C6E;

    --accent:      #D2B48C;
    --accent-ink:  #1A1408;
    --accent-soft: #2F2818;
    --accent-line: #5E4E35;

    --warn:        #D9A440;
    --warn-soft:   #35290F;
    --danger:      #E38073;
    --danger-soft: #3A1D18;
    --info:        #7FB3C0;
    --info-soft:   #172B30;

    --code-bg:     #121009;
    --code-border: #2B261E;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow:    0 2px 6px rgba(0, 0, 0, .38), 0 12px 32px rgba(0, 0, 0, .34);
    --shadow-lg: 0 8px 20px rgba(0, 0, 0, .45), 0 32px 64px rgba(0, 0, 0, .45);

    --syn-kw:      #8C9BF0;
    --syn-fn:      #C9A2E8;
    --syn-str:     #8FC978;
    --syn-num:     #E0A868;
    --syn-comment: #6E6558;
    --syn-punct:   #948B7C;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:          #16140F;
  --surface:     #1E1B16;
  --surface-2:   #25211B;
  --surface-3:   #2F2A22;
  --border:      #322C24;
  --border-2:    #453E33;

  --ink:         #EDE7DC;
  --ink-2:       #B5AC9D;
  --muted:       #857C6E;

  --accent:      #D2B48C;
  --accent-ink:  #1A1408;
  --accent-soft: #2F2818;
  --accent-line: #5E4E35;

  --warn:        #D9A440;
  --warn-soft:   #35290F;
  --danger:      #E38073;
  --danger-soft: #3A1D18;
  --info:        #7FB3C0;
  --info-soft:   #172B30;

  --code-bg:     #121009;
  --code-border: #2B261E;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow:    0 2px 6px rgba(0, 0, 0, .38), 0 12px 32px rgba(0, 0, 0, .34);
  --shadow-lg: 0 8px 20px rgba(0, 0, 0, .45), 0 32px 64px rgba(0, 0, 0, .45);

  --syn-kw:      #8C9BF0;
  --syn-fn:      #C9A2E8;
  --syn-str:     #8FC978;
  --syn-num:     #E0A868;
  --syn-comment: #6E6558;
  --syn-punct:   #948B7C;
}

/* ────────────────────────────────────────────────────────────── база */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body[data-font="large"] { font-size: 17px; }

/*
 * Заголовки серифні, текст — ні. Сериф тут працює як сигнал жанру:
 * він каже «це стаття», і людина читає уважніше, ніж читала б підписи
 * на панелі. У самому тексті сериф на 15px програв би Inter у чіткості,
 * особливо на кирилиці, тому межа проходить рівно по заголовках.
 */
h1, h2, h3, h4 {
  font-family: var(--serif);
  font-optical-sizing: auto;
  margin: 0 0 .5em;
  line-height: 1.22;
  font-weight: 600;
  letter-spacing: -.01em;
}
h1 { font-size: 1.9rem; line-height: 1.15; letter-spacing: -.02em; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.12rem; }
h4 { font-size: .98rem; }

p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

ul, ol { margin: 0 0 1em; padding-left: 1.35em; }
li { margin-bottom: .35em; }
li:last-child { margin-bottom: 0; }

hr { border: 0; border-top: 1px solid var(--border); margin: 1.75rem 0; }

strong { font-weight: 640; }

code, kbd, pre, .mono, .editor, table.data {
  font-family: var(--mono);
  /* Лігатури вимкнено навмисно: із ними >= показується як ≥, != як ≠,
     і людина бачить у коді символи, яких там насправді немає. */
  font-variant-ligatures: none;
  font-feature-settings: 'liga' 0, 'calt' 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-soft); color: var(--ink); }

/* ─────────────────────────────────────────────────────────── каркас */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1.1rem 1.15rem .9rem;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-family: var(--serif);
  font-weight: 600;
  font-size: .88rem;
  letter-spacing: .01em;
  flex-shrink: 0;
}
.brand-name {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -.01em;
  font-size: 1.08rem;
}
.brand-sub { font-size: .72rem; color: var(--muted); line-height: 1.2; }

.nav { padding: .7rem .6rem; flex: 1; }
.nav-group + .nav-group { margin-top: 1.1rem; }
.nav-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  padding: 0 .55rem .4rem;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  width: 100%;
  padding: .5rem .55rem;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: .9rem;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-icon { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.nav-badge {
  margin-left: auto;
  font-size: .7rem;
  font-family: var(--mono);
  background: var(--surface-3);
  color: var(--ink-2);
  padding: .05rem .38rem;
  border-radius: 20px;
  font-weight: 500;
}
.nav-item[aria-current="page"] .nav-badge { background: var(--accent); color: var(--accent-ink); }
/* Лічильник карток на сьогодні — єдиний заклик до дії в меню,
   тому він акцентний, а не службово-сірий. */
.nav-badge.hot { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.sidebar-foot {
  padding: .8rem 1rem 1rem;
  border-top: 1px solid var(--border);
  font-size: .76rem;
  color: var(--muted);
}

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: none;
  align-items: center;
  gap: .6rem;
  padding: .55rem .85rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 40;
}

.view {
  padding: 1.7rem 1.9rem 5rem;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  flex: 1;
  min-width: 0;
  /* clip, а не hidden: не створює власного контексту прокрутки,
     тому sticky-заголовки таблиць і бічна панель працюють як були.
     Потрібно, бо блоки коду мають власний горизонтальний скрол,
     і без цього сторінка все одно вміла зсуватись убік на телефоні. */
  overflow-x: clip;
}

/* ────────────────────────────────────────────────────── елементи */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-tight { padding: .85rem 1rem; }

.page-head { margin-bottom: 1.7rem; }
.page-head h1 { margin-bottom: .45rem; }
/* Підзаголовок сторінки — це лід статті, а не підпис. Звідси сериф,
   більший кегль і колір тексту, а не сірий службовий. */
.page-sub {
  font-family: var(--serif);
  font-optical-sizing: auto;
  color: var(--ink-2);
  font-size: 1.14rem;
  line-height: 1.52;
  margin: 0;
  max-width: 74ch;
}

.eyebrow {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: .4rem;
}

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: .8rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.spacer { flex: 1; }

/* кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .5rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
  font-weight: 550;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .05s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-lg { padding: .68rem 1.3rem; font-size: .95rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }

/* поля */
.input, .textarea, .select {
  width: 100%;
  padding: .5rem .7rem;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
}
.textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
.input:focus, .textarea:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field-label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .3rem; color: var(--ink-2); }
.field + .field { margin-top: .85rem; }
.hint { font-size: .79rem; color: var(--muted); margin-top: .3rem; }

/* значки */
.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .74rem;
  font-weight: 600;
  padding: .16rem .5rem;
  border-radius: 20px;
  background: var(--surface-3);
  color: var(--ink-2);
  white-space: nowrap;
}
.chip-accent { background: var(--accent-soft); color: var(--accent); }
.chip-warn   { background: var(--warn-soft);   color: var(--warn); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.chip-info   { background: var(--info-soft);   color: var(--info); }
.chip-basic        { background: var(--accent-soft); color: var(--accent); }
.chip-intermediate { background: var(--info-soft);   color: var(--info); }
.chip-advanced     { background: var(--warn-soft);   color: var(--warn); }

/* прогрес */
.bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 20px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 20px;
  transition: width .35s cubic-bezier(.4, 0, .2, 1);
}
.bar-lg { height: 9px; }

.stat { text-align: left; }
/* Цифри серифні: великий серифний numeral виглядає як показник у звіті,
   а не як лічильник у консолі — і це той регістр, який тут потрібен. */
.stat-num {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -.02em;
  color: var(--ink);
}
.stat-label { font-size: .78rem; color: var(--muted); margin-top: .2rem; }

/* ───────────────────────────────────────────────────────────── код */

pre.code, .code-block {
  max-width: 100%;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: .82rem;
  line-height: 1.62;
  margin: 0 0 1rem;
  -webkit-overflow-scrolling: touch;
}
pre.code:last-child { margin-bottom: 0; }
pre.code code { font-size: inherit; background: none; padding: 0; }

code.inline {
  font-size: .86em;
  background: var(--surface-3);
  padding: .1em .38em;
  border-radius: 5px;
  color: var(--ink);
  /* Довгий фрагмент коду всередині абзацу не має розпирати сторінку:
     на вузькому екрані він переноситься, зокрема всередині ідентифікатора. */
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.tok-kw      { color: var(--syn-kw); font-weight: 600; }
.tok-fn      { color: var(--syn-fn); }
.tok-str     { color: var(--syn-str); }
.tok-num     { color: var(--syn-num); }
.tok-comment { color: var(--syn-comment); font-style: italic; }
.tok-punct   { color: var(--syn-punct); }

/* редактор */
.editor-wrap {
  position: relative;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  overflow: hidden;
}
.editor-wrap:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.editor {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: .84rem;
  line-height: 1.62;
  padding: .8rem .9rem;
  resize: vertical;
  min-height: 130px;
  display: block;
  tab-size: 2;
}
.editor:focus { outline: none; }
.editor-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .6rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}

/* таблиця результатів */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}
table.data {
  border-collapse: collapse;
  width: 100%;
  font-size: .81rem;
  font-family: var(--mono);
}
table.data th, table.data td {
  padding: .4rem .65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data th {
  background: var(--surface-2);
  font-weight: 600;
  position: sticky;
  top: 0;
  font-size: .76rem;
  color: var(--ink-2);
  border-bottom: 1px solid var(--border-2);
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data td.null { color: var(--muted); font-style: italic; }
table.data td.num { text-align: right; }

/* повідомлення */
.note {
  border-radius: var(--radius-sm);
  padding: .75rem .9rem;
  font-size: .87rem;
  border: 1px solid;
  margin-bottom: 1rem;
}
.note:last-child { margin-bottom: 0; }
.note-title { font-weight: 640; margin-bottom: .2rem; display: block; }
.note p:last-child { margin-bottom: 0; }
.note-ok   { background: var(--accent-soft); border-color: var(--accent-line); color: var(--ink); }
.note-warn { background: var(--warn-soft);   border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--ink); }
.note-err  { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--ink); }
.note-info { background: var(--info-soft);   border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--ink); }
.note-plain{ background: var(--surface-2);   border-color: var(--border); color: var(--ink-2); }

/*
 * Врізки — окремий візуальний жанр.
 *
 * Тут вони не «кольорові смужки збоку», а вставки на кшталт журнальних:
 * власна рамка, повне скруглення, підпис маленькими літерами з крапкою-
 * маркером. Сенс у тому, щоб врізку було видно як інший регістр мовлення,
 * а не як попередження системи.
 */
.defense, .pitfall, .analogy, .spec {
  padding: .9rem 1.1rem;
  border-radius: var(--radius-sm);
  margin: 1.3rem 0;
  font-size: .9rem;
  border: 1px solid;
}
.defense .eyebrow, .pitfall .eyebrow,
.analogy .eyebrow, .spec .eyebrow {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .4rem;
}
.defense .eyebrow::before, .pitfall .eyebrow::before,
.analogy .eyebrow::before, .spec .eyebrow::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.defense { background: var(--warn-soft);   border-color: color-mix(in srgb, var(--warn) 28%, transparent); }
.defense .eyebrow { color: var(--warn); }

.pitfall { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.pitfall .eyebrow { color: var(--danger); }

.analogy { background: var(--info-soft);   border-color: color-mix(in srgb, var(--info) 28%, transparent); }
.analogy .eyebrow { color: var(--info); }

/* списки уроків */
.lesson-row {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .68rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
  transition: border-color .12s, background .12s;
}
.lesson-row:hover { border-color: var(--accent-line); background: var(--surface-2); }
.lesson-row + .lesson-row { margin-top: .4rem; }
.lesson-num {
  font-family: var(--mono);
  font-size: .75rem;
  color: var(--muted);
  width: 2.2rem;
  flex-shrink: 0;
}
.lesson-title { font-weight: 550; font-size: .92rem; }
.lesson-meta { font-size: .76rem; color: var(--muted); margin-top: .1rem; }
.lesson-state {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--border-2);
  flex-shrink: 0;
  display: grid; place-items: center;
}
.lesson-state.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lesson-state.started { border-color: var(--accent); border-style: dashed; }

/* модулі */
.module-head {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-bottom: .7rem;
}
/* Номер модуля — велика серифна цифра в колі: у списку з дванадцяти
   розділів саме вона дає ритм і робить програму схожою на зміст книги. */
.module-idx {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-2);
  background: transparent;
  color: var(--ink-2);
  display: grid; place-items: center;
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: 1rem;
  flex-shrink: 0;
}
.module-idx.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.module + .module { margin-top: 1.6rem; }

/* картки повторення */
.flashcard {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.6rem 1.4rem;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.flashcard-q { font-size: 1.14rem; font-weight: 600; line-height: 1.4; }
.flashcard-a { margin-top: 1rem; font-size: .94rem; color: var(--ink-2); text-align: left; }

/* вкладки */
.tabs {
  display: flex;
  gap: .15rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: .5rem .8rem;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: .87rem;
  font-weight: 550;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* розгортання */
.disclosure { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); margin-bottom: .5rem; }
.disclosure > summary {
  padding: .6rem .85rem;
  cursor: pointer;
  font-weight: 550;
  font-size: .89rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before {
  content: '';
  width: 6px; height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .15s;
  flex-shrink: 0;
}
.disclosure[open] > summary::before { transform: rotate(45deg); }
.disclosure > div { padding: 0 .85rem .85rem; }

/* CTE-розбір в'юхи */
.cte-step {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface);
  margin-bottom: .7rem;
}
.cte-head {
  padding: .6rem .85rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
  flex-wrap: wrap;
}
.cte-name { font-family: var(--mono); font-weight: 600; font-size: .85rem; color: var(--accent); }
.cte-body { padding: 0 .85rem .85rem; }

/* завантаження */
.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.boot {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 200;
  text-align: center;
  padding: 2rem;
}
.boot-inner { max-width: 320px; }

/* тости */
.toasts {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  box-shadow: var(--shadow);
  font-size: .87rem;
  max-width: 320px;
  animation: slidein .2s ease;
  pointer-events: auto;
}
.toast.err { border-left-color: var(--danger); }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } }

/* модальні */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 15, .5);
  display: grid;
  place-items: center;
  z-index: 250;
  padding: 1rem;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.4rem;
}

/* сітка активності */
.heat { display: flex; gap: 2px; flex-wrap: wrap; }
.heat-cell {
  width: 11px; height: 11px;
  border-radius: 2px;
  background: var(--surface-3);
}
.heat-cell[data-level="1"] { background: color-mix(in srgb, var(--accent) 28%, var(--surface-3)); }
.heat-cell[data-level="2"] { background: color-mix(in srgb, var(--accent) 55%, var(--surface-3)); }
.heat-cell[data-level="3"] { background: color-mix(in srgb, var(--accent) 80%, var(--surface-3)); }
.heat-cell[data-level="4"] { background: var(--accent); }

/* довідник схеми */
.schema-table + .schema-table { margin-top: .8rem; }
.schema-cols {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .2rem .8rem;
  font-family: var(--mono);
  font-size: .78rem;
}
.schema-col { display: flex; gap: .4rem; padding: .1rem 0; }
.schema-col b { font-weight: 550; color: var(--ink); }
.schema-col span { color: var(--muted); }

/* дрібне */
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.xs { font-size: .76rem; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.mt0 { margin-top: 0; } .mt1 { margin-top: .5rem; } .mt2 { margin-top: 1rem; } .mt3 { margin-top: 1.6rem; }
.mb0 { margin-bottom: 0; } .mb1 { margin-bottom: .5rem; } .mb2 { margin-bottom: 1rem; } .mb3 { margin-bottom: 1.6rem; }
.nowrap { white-space: nowrap; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

/* ─────────────────────────────────────────────────────── адаптив */

.mobile-only { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 270px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.4, 0, .2, 1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .topbar { display: flex; }
  .mobile-only { display: initial; }
  .view { padding: 1.1rem 1rem 6rem; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scrim {
    position: fixed;
    inset: 0;
    background: rgba(10, 13, 15, .45);
    z-index: 90;
  }
}

@media (max-width: 560px) {
  body { font-size: 15px; }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
  .view { padding: 1rem .85rem 6rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .card { padding: .95rem 1rem; border-radius: 10px; }
  .stat-num { font-size: 1.45rem; }
  pre.code, .editor { font-size: .78rem; }
  .toasts { left: .75rem; right: .75rem; bottom: .75rem; }
  .toast { max-width: none; }
  .modal { padding: 1.1rem; border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  .sidebar, .topbar, .btn, .toasts { display: none !important; }
  .app { display: block; }
  .view { padding: 0; max-width: none; }
  .card { break-inside: avoid; border-color: #ccc; }
}

/* ═══════════════════════════════════════════════ Карта SQL */

.map-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-3);
  border-radius: 10px;
  margin-bottom: .35rem;
}
.map-switch button {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: .85rem;
  font-weight: 550;
  padding: .38rem .85rem;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.map-switch button:hover { color: var(--ink); }
.map-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.map-group { margin-bottom: 1.5rem; }
.map-group-head {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  margin-bottom: .55rem;
  flex-wrap: wrap;
}
.map-group-head h3 { margin: 0; font-size: 1rem; }
.map-group-note { font-size: .8rem; color: var(--muted); flex: 1; min-width: 12ch; }

.map-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.map-tile {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: var(--ink);
  transition: border-color .12s, transform .06s, background .12s;
  position: relative;
  min-width: 0;
}
.map-tile:hover { border-color: var(--accent-line); transform: translateY(-1px); }
.map-tile:active { transform: none; }

.map-tile-label {
  font-family: var(--mono);
  font-size: .8rem;
  font-weight: 550;
  line-height: 1.3;
}
.map-tile-freq {
  font-size: .68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* вага плитки = як часто конструкція зустрічається у справжньому коді */
.map-tile[data-weight="3"] { border-color: var(--accent); background: var(--accent-soft); }
.map-tile[data-weight="3"] .map-tile-label { font-size: .92rem; font-weight: 650; }
.map-tile[data-weight="2"] { border-color: var(--accent-line); }
.map-tile[data-weight="2"] .map-tile-label { font-size: .85rem; }
.map-tile[data-weight="0"] { opacity: .62; border-style: dashed; }

/* пройдено */
.map-tile[data-done="1"]::after {
  content: '';
  position: absolute;
  top: 6px; right: 6px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.map-tile[data-done="1"] { background: var(--accent-soft); }

.map-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: .76rem;
  color: var(--muted);
  align-items: center;
  margin-bottom: 1.2rem;
}
.map-legend i {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 2px;
  margin-right: .3rem;
  vertical-align: -1px;
}

@media (max-width: 560px) {
  .map-tiles { gap: .3rem; }
  .map-tile { padding: .42rem .55rem; flex: 1 1 calc(50% - .3rem); }
  .map-tile-label { font-size: .76rem !important; }
  .map-switch { width: 100%; }
  .map-switch button { flex: 1; padding: .45rem .5rem; font-size: .8rem; }
}


/* Захист від горизонтального скролу: жоден блок тексту не має бути
   ширшим за екран. Скролитись усередині себе дозволено лише коду,
   таблицям і діаграмам — у них для цього є власний контейнер. */
.view, .card, .note, .defense, .pitfall, .analogy,
.lesson-row, .flashcard, .disclosure, .cte-step {
  max-width: 100%;
  min-width: 0;
}
.card, .note, .defense, .pitfall, .analogy, .flashcard {
  overflow-wrap: anywhere;
}
.disclosure > summary { flex-wrap: wrap; min-width: 0; }
.disclosure > summary > * { min-width: 0; }

/* ═══════════════════════════════════ Швидкий пошук (Cmd/Ctrl + K) */

.palette-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 15, .45);
  z-index: 260;
  display: flex;
  justify-content: center;
  padding: 8vh 1rem 1rem;
  animation: fade .12s ease;
}
.palette {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 620px;
  max-height: 74vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.palette-input {
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: .95rem 1.1rem;
  font: inherit;
  font-size: 1rem;
  background: transparent;
  color: var(--ink);
  outline: none;
  flex-shrink: 0;
}
.palette-list { overflow-y: auto; padding: .35rem; }
.palette-item {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: .5rem .7rem;
  border-radius: 8px;
  cursor: pointer;
}
.palette-item:hover, .palette-item[aria-selected="true"] { background: var(--surface-3); }
.palette-item[aria-selected="true"] { outline: 1px solid var(--accent-line); }
.palette-title { font-weight: 550; font-size: .92rem; }
.palette-sub { font-size: .78rem; color: var(--muted); flex: 1; min-width: 0;
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-kind {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  flex-shrink: 0;
}
.palette-foot {
  border-top: 1px solid var(--border);
  padding: .5rem .9rem;
  font-size: .74rem;
  color: var(--muted);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
kbd {
  font-size: .72rem;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: .05em .35em;
  font-family: var(--mono);
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .45rem .6rem;
  margin-bottom: .5rem;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: .84rem;
  cursor: pointer;
  text-align: left;
}
.search-trigger:hover { background: var(--surface-3); color: var(--ink-2); }
.search-trigger kbd { margin-left: auto; }

@media (max-width: 560px) {
  .palette-backdrop { padding: 0; }
  .palette { max-width: none; max-height: 100dvh; height: 100dvh; border-radius: 0; }
}

/* ═══════════════════════════════════════════ Перекладач SQL */

.explain {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.explain.compact { grid-template-columns: minmax(0, 1fr); }

.explain-pane { min-width: 0; }
.explain-pane:first-child { position: sticky; top: 1rem; }

pre.code.explain-code {
  max-height: 72vh;
  overflow: auto;
  margin: 0;
  line-height: 1.65;
}
.explain-seg { border-radius: 3px; transition: background .12s; }
.explain-seg.lit {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

.explain-step {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface);
  padding: .75rem .9rem;
  margin-bottom: .6rem;
}
.explain-step-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .5rem;
}
.explain-step-name {
  font-family: var(--mono);
  font-weight: 600;
  font-size: .85rem;
  color: var(--accent);
}

.explain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: explain;
}
.explain-item {
  position: relative;
  padding: .4rem .5rem .4rem 2rem;
  margin: 0 0 .15rem;
  border-radius: 6px;
  font-size: .89rem;
  line-height: 1.55;
  cursor: default;
  counter-increment: explain;
  transition: background .12s;
}
.explain-item::before {
  content: counter(explain);
  position: absolute;
  left: .45rem;
  top: .45rem;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .68rem;
  display: grid;
  place-items: center;
  font-weight: 600;
}
.explain-item:hover { background: var(--surface-2); }
.explain-item:hover::before { background: var(--accent); color: var(--accent-ink); }

.explain-tag {
  display: inline-block;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 650;
  margin-right: .4rem;
}

.explain-warn {
  margin-top: .35rem;
  font-size: .8rem;
  color: var(--warn);
  border-left: 2px solid var(--warn);
  padding-left: .5rem;
}

.explain-grain {
  margin-top: .5rem;
  padding: .45rem .6rem;
  background: var(--accent-soft);
  border-radius: 6px;
  font-size: .84rem;
}
.explain-grain .eyebrow { color: var(--accent); margin-bottom: .1rem; }

.explain-cols {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: .3rem .8rem;
  font-size: .8rem;
}
.explain-col { display: flex; gap: .4rem; min-width: 0; }
.explain-col b { font-family: var(--mono); font-weight: 550; flex-shrink: 0; }
.explain-col span { color: var(--muted); overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .explain { grid-template-columns: minmax(0, 1fr); }
  .explain-pane:first-child { position: static; }
  pre.code.explain-code { max-height: 40vh; }
}

.explain-inline {
  border-top: 1px dashed var(--border-2);
  padding-top: .75rem;
}
.explain-inline .explain-step { border-left-width: 2px; padding: .6rem .75rem; }
.explain-inline .note-plain { display: none; }

/* ═══════════════════════════════════════════ Розбори вʼюх */

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.flow-node {
  font-family: var(--mono);
  font-size: .78rem;
  padding: .35rem .6rem;
  border: 1px solid var(--border-2);
  border-radius: 7px;
  background: var(--surface-2);
}
.flow-node.source { border-style: dashed; }
.flow-node.result { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.flow-arrow { color: var(--muted); }

.seg {
  display: grid;
  /* Коду більше місця, ніж опису: рядки SQL довгі й вирівняні пробілами,
     і при рівних колонках половина тексту ховалась би за горизонтальний скрол. */
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.seg:last-of-type { border-bottom: 0; }
.seg-code { position: relative; min-width: 0; }
.seg-num {
  position: absolute;
  left: -.5rem; top: -.5rem;
  width: 1.5rem; height: 1.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-family: var(--mono);
  font-size: .72rem;
  font-weight: 700;
  z-index: 1;
}
.seg-note { min-width: 0; font-size: .9rem; line-height: 1.6; }
.seg-note > :first-child { margin-top: 0; }
.seg-note ul { padding-left: 1.1em; }

@media (max-width: 900px) {
  .seg { grid-template-columns: minmax(0, 1fr); gap: .6rem; }
  .seg-num { left: 0; top: -.4rem; }
}

.explain-used { display: grid; gap: .25rem; }
.explain-used-row { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.explain-used-row code { flex-shrink: 0; }

/* Код у сегментах трохи щільніший — інакше типовий рядок вʼюхи не влазить. */
.seg-code pre.code { font-size: .76rem; line-height: 1.55; max-height: 60vh; }
.seg-code .row { margin-bottom: .2rem; }

/* ═══════════════════════════════════ Мобільне: доторк і навігація */

@media (max-width: 900px) {
  /* Ціль для пальця — не менше 44px. Миша влучає в 30px, палець ні:
     промах коштує зайвого тапа, і на довгому екрані це дратує швидко. */
  .btn, .nav-item, .tab, .map-switch button, .palette-item, .search-trigger {
    min-height: 44px;
  }
  .btn-sm { min-height: 40px; padding-inline: .75rem; }
  .lesson-row { min-height: 56px; }
  .disclosure > summary { min-height: 44px; }

  /* Дрібний службовий текст на телефоні читається гірше — піднімаємо низ шкали. */
  .xs, .map-tile-freq, .lesson-meta, .explain-tag { font-size: .78rem; }
  .stat-label, .nav-label { font-size: .74rem; }

  /* Нижня панель: головні розділи без відкривання шухляди.
     Саме вона перетворює застосунок із «сайту, що відкривається на телефоні»
     на такий, яким справді користуються по дорозі. */
  .tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 80;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .15rem;
    padding: .45rem .2rem .5rem;
    min-height: 52px;
    color: var(--muted);
    text-decoration: none;
    font-size: .66rem;
    line-height: 1.15;
    text-align: center;
  }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .tabbar a[aria-current="page"] .nav-icon { opacity: 1; }
  .tabbar .nav-icon { width: 21px; height: 21px; opacity: .75; }

  /* Місце під панель, щоб вона не накривала кінець сторінки. */
  .view { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(4rem + env(safe-area-inset-bottom)); }
}

@media (min-width: 901px) {
  .tabbar { display: none; }
}

/* Довгий перелік чипів-передумов з'їдав перший екран — ховаємо під розкриття. */
.prereq { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.prereq-more {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: .74rem;
  cursor: pointer;
  padding: .16rem .3rem;
}

/* Підказка про гарячу клавішу на телефоні безглузда — там немає ⌘. */
@media (max-width: 900px) {
  .mobile-hide { display: none !important; }
}

/* ═══════════════════════════════════════════ Словник команд */

.gloss {
  padding: .6rem 0;
  border-bottom: 1px solid var(--border);
}
.gloss:last-child { border-bottom: 0; }
.gloss-head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; margin-bottom: .2rem; }
.gloss-term {
  font-size: .88rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  padding: .12em .45em;
  border-radius: 5px;
  white-space: normal;
}
.gloss-what { font-size: .92rem; line-height: 1.5; }
.gloss-ex {
  display: block;
  margin-top: .35rem;
  font-size: .78rem;
  color: var(--ink-2);
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  padding: .3rem .5rem;
  overflow-x: auto;
  white-space: pre;
}
.gloss-more > summary {
  cursor: pointer;
  font-size: .78rem;
  color: var(--muted);
  margin-top: .35rem;
  list-style: none;
}
.gloss-more > summary::-webkit-details-marker { display: none; }
.gloss-more > summary::after { content: ' ▾'; }
.gloss-more[open] > summary::after { content: ' ▴'; }

/* ═══════════════════════════════════════════ ШІ-помічник */

.fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 70;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .12s, filter .12s;
}
.fab:hover { filter: brightness(1.08); transform: translateY(-1px); }
.fab:active { transform: none; }
.fab .nav-icon { width: 22px; height: 22px; opacity: 1; }

.chat {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 120;
  width: min(420px, calc(100vw - 2.5rem));
  max-height: min(640px, calc(100dvh - 2.5rem));
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.chat.open { display: flex; }

.chat-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .7rem .85rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
.chat-head > div:first-child { flex: 1; min-width: 0; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: .85rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  overscroll-behavior: contain;
}

.chat-intro { font-size: .87rem; color: var(--ink-2); }
.chat-starters { display: grid; gap: .35rem; margin-top: .6rem; }
.chat-starters .btn {
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
  height: auto;
  padding: .45rem .7rem;
}

.chat-msg { max-width: 92%; font-size: .89rem; line-height: 1.55; }
.chat-user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 12px 12px 4px 12px;
  padding: .5rem .7rem;
  white-space: pre-wrap;
}
.chat-assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 4px;
  padding: .55rem .75rem;
  max-width: 100%;
}
.chat-assistant.pending { opacity: .6; font-style: italic; }
.chat-body > :first-child { margin-top: 0; }
.chat-body > :last-child { margin-bottom: 0; }
.chat-body pre.code { font-size: .74rem; margin: .5rem 0; }
.chat-body h2, .chat-body h3, .chat-body h4 { font-size: .95rem; margin-top: .7rem; }

.chat-foot {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
  padding: .6rem .7rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
  padding: .45rem .6rem;
  resize: none;
  max-height: 160px;
}
.chat-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

@media (max-width: 900px) {
  /* Кнопку піднімаємо над нижньою панеллю, щоб вона її не перекривала. */
  .fab { bottom: calc(4.5rem + env(safe-area-inset-bottom)); right: 1rem; width: 48px; height: 48px; }
  .chat {
    inset: 0;
    width: 100%;
    max-height: none;
    border-radius: 0;
    border: 0;
  }
  .chat-foot { padding-bottom: calc(.6rem + env(safe-area-inset-bottom)); }
}

/* ═══════════════════════════════════════════ Трек */

.track-step {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  margin-bottom: .4rem;
  transition: border-color .12s, background .12s;
}
.track-step:hover { border-color: var(--accent-line); background: var(--surface-2); }
.track-step.is-view { border-left: 3px solid var(--accent); }
.track-step.done { opacity: .62; }
.track-step.next { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.track-mark {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border-2);
  display: grid; place-items: center;
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: .74rem;
  font-weight: 700;
  color: var(--muted);
  margin-top: .1rem;
}
.track-step.is-view .track-mark { border-color: var(--accent); color: var(--accent); }
.track-step.done .track-mark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.track-kind {
  font-size: .64rem;
  letter-spacing: .08em;
  font-weight: 700;
  color: var(--muted);
}
.track-step.is-view .track-kind { color: var(--accent); }
.track-title { font-weight: 550; font-size: .92rem; line-height: 1.35; }
.track-why { font-size: .8rem; color: var(--muted); margin-top: .15rem; line-height: 1.45; }

/* ============================================================================
   Agent Hub — компоненти, яких не було в успадкованій системі.
   ============================================================================ */

/* ключ у JSON і YAML: у конфігах його шукають очима найчастіше */
.tok-key { color: var(--syn-fn); font-weight: 600; }

/* мова блоку коду підписом у кутку — щоб не гадати, це Python чи TypeScript */
pre.code { position: relative; }
pre.code[data-lang]:not([data-lang="text"])::after {
  content: attr(data-lang);
  position: absolute;
  top: 0; right: 0;
  padding: .12rem .45rem;
  font-size: .62rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-3);
  border-bottom-left-radius: 6px;
  pointer-events: none;
}

/* ───────────────────────────────────────────── перемикач вкладок */

.switcher {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--surface-3);
  border-radius: 10px;
}
.switcher-btn {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: .85rem;
  font-weight: 550;
  padding: .38rem .85rem;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.switcher-btn:hover { color: var(--ink); }
.switcher-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* ───────────────────────────────── послідовність кроків (цикл агента) */

.flow-steps { display: flex; flex-direction: column; gap: .1rem; margin: 1rem 0; }
.flow-steps .flow-node {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: .6rem .8rem;
}
.flow-who {
  font-family: var(--mono);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: .15rem;
}
.flow-what { font-size: .92rem; line-height: 1.45; }
.flow-steps .flow-arrow {
  color: var(--border-2);
  text-align: center;
  line-height: 1;
  padding: .18rem 0;
  font-size: .9rem;
}

/* ─────────────────────────────────────── результати перевірки завдання */

.checks { list-style: none; padding: 0; margin: .4rem 0 0; }
.checks li {
  display: flex;
  gap: .5rem;
  align-items: flex-start;
  padding: .4rem .55rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  margin-bottom: .25rem;
}
.checks li.ok  { background: var(--accent-soft); color: var(--ink); }
.checks li.bad { background: var(--warn-soft); color: var(--ink); }
.check-mark { font-weight: 700; line-height: 1.5; flex-shrink: 0; }
.checks li.ok  .check-mark { color: var(--accent); }
.checks li.bad .check-mark { color: var(--warn); }

.task .editor-wrap { margin-top: .5rem; }

/* ──────────────────────────────────────────────── знахідки аналізатора */

.findings { list-style: none; padding: 0; margin: 0; }
.finding {
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  margin-bottom: .4rem;
  background: var(--surface);
}
.finding.err  { border-left-color: var(--danger); }
.finding.warn { border-left-color: var(--warn); }
.finding.tip  { border-left-color: var(--info); }
.finding.ok   { border-left-color: var(--accent); opacity: .78; }

.chip-err  { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip-tip  { background: var(--info-soft);   color: var(--info);   border-color: transparent; }
.chip-ok   { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ──────────────────────────────────────── варіанти вибору й вікторина */

.quiz-option, .pick-option {
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
  height: auto;
  padding: .55rem .8rem;
  line-height: 1.45;
}
.pick-option.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.pick-option.right { border-color: var(--accent); background: var(--accent-soft); }
.pick-option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.quiz-option.on    { border-color: var(--accent); background: var(--accent-soft); }

/* ─────────────────────────────────────────── завдання «розстав по порядку» */

.order-list { list-style: none; padding: 0; margin: .6rem 0 0; counter-reset: ord; }
.order-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: .5rem .6rem;
  margin-bottom: .35rem;
  counter-increment: ord;
}
.order-item::before {
  content: counter(ord);
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--muted);
  width: 1.3rem;
  flex-shrink: 0;
  text-align: center;
}
.order-item.good { border-color: var(--accent-line); background: var(--accent-soft); }
.order-item.bad  { border-color: var(--warn); background: var(--warn-soft); }
.order-text { flex: 1; min-width: 0; font-size: .9rem; line-height: 1.4; }
.order-ctl { display: flex; gap: .15rem; flex-shrink: 0; }
.order-ctl .btn { padding: .2rem .45rem; min-height: 0; }

/* ───────────────────────────────────────────────── карта патернів */

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .6rem;
}
.pattern-tile {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: .75rem .8rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  transition: border-color .12s, transform .12s;
}
.pattern-tile:hover { border-color: var(--accent-line); transform: translateY(-1px); }
.pattern-tile:active { transform: none; }
/* Вартість підсвічується рамкою зліва: колонка патернів читається згори вниз
   як шкала «дешево → дорого», і колір робить цю шкалу видимою одразу. */
.pattern-tile[data-cost="1"] { border-left: 3px solid var(--accent); }
.pattern-tile[data-cost="2"] { border-left: 3px solid var(--info); }
.pattern-tile[data-cost="3"] { border-left: 3px solid var(--warn); }
.pattern-tile[data-cost="4"] { border-left: 3px solid var(--danger); }
.pattern-idx {
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--muted);
}
.pattern-name { font-weight: 600; font-size: .95rem; line-height: 1.25; }
.pattern-when { font-size: .78rem; color: var(--muted); line-height: 1.35; flex: 1; }
.pattern-meta { display: flex; gap: .3rem; flex-wrap: wrap; }

/* ─────────────────────────────────────────── дві колонки в пісочниці */

.lab-split { align-items: start; }
.lab-split .editor-wrap { position: sticky; top: 1rem; }

/* ───────────────────────────────────────────────────────── словник */

.gloss-en {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--muted);
}
.gloss-why {
  font-size: .85rem;
  color: var(--ink-2);
  margin-top: .2rem;
}

/* ───────────────────────────────────────────────── джерела й врізки */

.source-card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color .12s;
}
.source-card:hover { border-color: var(--accent-line); }
.source-box { border-left: 3px solid var(--info); }

/* фрагмент зі справжнього коду Anthropic — окремий візуальний статус:
   це не приклад, придуманий для уроку, і це має бути видно */
.realcode { border-left: 3px solid var(--warn); }

.spec {
  border: 1px solid var(--info-soft);
  border-left: 3px solid var(--info);
  background: var(--info-soft);
  border-radius: var(--radius-sm);
  padding: .7rem .85rem;
  margin: 1rem 0;
}
.spec .eyebrow { color: var(--info); }

/* ──────────────────────────────────────────────── програма курсу */

.module-body { padding-left: 2.6rem; }
.module-anchor {
  padding-left: 2.6rem;
  font-style: italic;
}

/* ─────────────────────────────────────────────────────── помічник */

.chat-note {
  padding: .5rem .85rem .7rem;
  border-top: 1px solid var(--border);
  line-height: 1.4;
}

/* ─────────────────────────────────────────────────────── телефон */

@media (max-width: 860px) {
  .lab-split { grid-template-columns: 1fr; }
  .lab-split .editor-wrap { position: static; }
  .module-body, .module-anchor { padding-left: 0; }
  .pattern-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .pattern-grid { grid-template-columns: 1fr; }
  .switcher { width: 100%; }
  .switcher-btn { flex: 1; text-align: center; }
}

/* ============================================================================
   Читання уроку.

   Урок — це 700–1300 слів суцільного тексту, і саме він, а не інтерфейс,
   займає 95% часу людини в застосунку. Тому тіло уроку набирається серифом
   із більшим кеглем і просторішим інтерліньяжем: Literata зроблена для
   тривалого читання, і на кирилиці це помітно вже на другому абзаці.

   Інтерфейсні елементи всередині уроку — кнопки, чипи, списки перевірок,
   редактор — лишаються на Inter: у них інша задача, і сериф там лише
   заважав би сканувати.
   ============================================================================ */

.lesson p,
.lesson li {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-size: 1.04rem;
  line-height: 1.68;
}
.lesson p { margin-bottom: 1.05em; }
.lesson li { margin-bottom: .5em; }

/* межа читабельності: рядок довший за ~75 знаків втомлює око */
.lesson .card > p,
.lesson .card > ul,
.lesson .card > ol { max-width: 74ch; }

.lesson .defense p, .lesson .pitfall p,
.lesson .analogy p, .lesson .spec p,
.lesson .note p { font-size: .98rem; line-height: 1.6; }

/* службові списки й підписи сериф не чіпає */
.lesson .checks li,
.lesson .findings li,
.lesson .order-item,
.lesson .lesson-meta,
.lesson .xs,
.lesson .small {
  font-family: var(--font);
  font-size: .88rem;
  line-height: 1.5;
}
.lesson .checks li { margin-bottom: .25em; }

.lesson table.data { font-size: .86rem; }
.lesson .quiz-option, .lesson .pick-option { font-family: var(--font); font-size: .93rem; }

@media (max-width: 720px) {
  .lesson p, .lesson li { font-size: 1.02rem; line-height: 1.62; }
}
