/* KmitLab — стилі публічного сайту (T-003, дизайн-система
   ops/marketing/site-design/5_design_system_decision_kmitlab.md).
   «Інтелектуальний мінімалізм», лише світла тема; усі кольори — токени :root,
   щоб темну тему можна було додати через prefers-color-scheme без правок компонентів.
   Тренажер має власні ізольовані стилі в css/trainer.css. */

:root {
  /* Fonts */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Surfaces & Borders */
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #dfe3f0;
  --border-strong: #c7cee3;
  --header-bg: rgba(255, 255, 255, 0.92);

  /* Typography */
  --text: #1f2440;
  --muted: #5c6382;
  --on-accent: #ffffff;

  /* Brand */
  --primary: #435ee8;
  --primary-hover: #354fd4;
  --primary-soft: #eef1fe;
  --focus-ring: rgba(67, 94, 232, 0.35);

  /* Semantic */
  --ok: #1b874b;
  --ok-bg: #eaf6ef;
  --ok-text: #146337;

  --bad: #d13b33;
  --bad-bg: #fdeeee;
  --bad-text: #9e2620;

  --slow: #c2410c;
  --slow-bg: #fff3eb;
  --slow-text: #923008;

  --star: #f5b301;
  --star-bg: #fef7e0;
  --star-text: #855e00;

  /* Elevation & Radii */
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow: 0 2px 8px rgba(31, 36, 64, 0.07);
  --shadow-hover: 0 6px 18px rgba(31, 36, 64, 0.11);
  --shadow-drawer: -8px 0 32px rgba(31, 36, 64, 0.16);
  --backdrop: rgba(31, 36, 64, 0.36);

  /* Layout & Spacing */
  --container: 1040px;
  --measure: 68ch;
  --header-h: 64px;
  --drawer-w: 420px;
  --gutter: 16px;

  /* Z-index layers */
  --z-header: 20;
  --z-backdrop: 90;
  --z-drawer: 100;
  --z-toast: 120;

  /* Subject default */
  --subj-bg: var(--primary-soft);
  --subj-ink: var(--primary-hover);
}

[data-subject="math"]      { --subj-bg: #eef1fe; --subj-ink: #354fd4; }
[data-subject="algebra"]   { --subj-bg: #f3effd; --subj-ink: #633bc4; }
[data-subject="geometry"]  { --subj-bg: #e8f6f7; --subj-ink: #0c6e78; }
[data-subject="physics"]   { --subj-bg: #fdf1e7; --subj-ink: #b34a08; }
[data-subject="chemistry"] { --subj-bg: #eaf6ef; --subj-ink: #167040; }
[data-subject="geography"] { --subj-bg: #faf3e3; --subj-ink: #85570d; }

/* ---------- база й типографіка ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 12px); }

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

img, svg { max-width: 100%; height: auto; }

a { color: var(--primary-hover); text-underline-offset: 0.15em; }
a:hover { color: var(--primary); }

h1, h2, h3 { color: var(--text); margin: 0; }
h1 { font-size: clamp(1.625rem, 3.5vw, 2.25rem); font-weight: 800; line-height: 1.2; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.25rem, 2.5vw, 1.5625rem); font-weight: 700; line-height: 1.3; margin-top: 32px; }
h3 { font-size: 1.125rem; font-weight: 700; line-height: 1.35; }
p { margin: 0 0 1em; }

.lead { font-size: clamp(1.0625rem, 2vw, 1.1875rem); color: var(--muted); max-width: var(--measure); margin: 12px 0 0; }
.meta { font-size: 0.875rem; color: var(--muted); }
.num, .tabular { font-variant-numeric: tabular-nums; }
.prose { max-width: var(--measure); }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--gutter); }
.section { padding: 16px 0; }
.section > h2:first-child { margin-top: 16px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

/* ---------- шапка ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 100%;
}
.site-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-right: auto;
}
.site-logo img, .site-logo svg { width: 32px; height: 32px; flex: none; }
.site-logo-lab { color: var(--primary); }
.site-nav { display: none; align-items: center; gap: 4px; }
.site-nav a {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}
.site-nav a:hover { background: var(--surface-2); color: var(--primary-hover); }
.site-nav a[aria-current="page"] { color: var(--primary-hover); }
.site-header .btn { min-height: 40px; padding: 0 14px; font-size: 0.95rem; }
.menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.menu-toggle-bars, .menu-toggle-bars::before, .menu-toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  position: relative;
}
.menu-toggle-bars::before, .menu-toggle-bars::after { content: ''; position: absolute; left: 0; }
.menu-toggle-bars::before { top: -6px; }
.menu-toggle-bars::after { top: 6px; }

/* Мобільне меню: випадна панель під шапкою (кнопка .menu-toggle + aria-expanded). */
.mobile-menu {
  position: absolute;
  top: var(--header-h);
  left: 0;
  right: 0;
  padding: 8px var(--gutter) 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-hover);
}
.mobile-menu[hidden] { display: none; }
.mobile-menu a {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.mobile-menu a:hover { background: var(--surface-2); }

@media (min-width: 768px) {
  .site-nav { display: flex; }
  .menu-toggle, .mobile-menu { display: none; }
}

/* ---------- хлібні крихти ---------- */

.breadcrumbs { margin: 20px 0 12px; }
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
  color: var(--muted);
}
.breadcrumbs li { display: inline-flex; align-items: center; gap: 6px; }
.breadcrumbs li:not(:last-child)::after { content: '›'; color: var(--muted); }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--primary-hover); text-decoration: underline; }
.breadcrumbs [aria-current="page"] { color: var(--text); font-weight: 600; }

/* ---------- кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-accent); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-soft { background: var(--primary-soft); color: var(--primary-hover); }
.btn-soft:hover { background: var(--border); color: var(--primary-hover); }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: default; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- бейджі ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.badge-nush { background: var(--primary-soft); color: var(--primary-hover); }
.subject-badge { background: var(--subj-bg); color: var(--subj-ink); }
.subject-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--subj-bg);
  color: var(--subj-ink);
  font-size: 1.25rem;
}

/* ---------- картки класів ---------- */

.grade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.grade-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: box-shadow 0.15s, transform 0.15s;
}
a.grade-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); color: var(--text); }
.grade-card-number { font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--primary); font-variant-numeric: tabular-nums; }
.grade-card-title { font-weight: 700; }
.grade-card-meta { font-size: 0.875rem; color: var(--muted); }
.grade-card .badge { align-self: flex-start; }
.grade-card.is-draft {
  border-style: dashed;
  border-color: var(--border-strong);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}
.grade-card.is-draft .grade-card-number { color: var(--border-strong); }

/* ---------- картки тем ---------- */

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.topic-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.topic-card:hover { box-shadow: var(--shadow-hover); }
.topic-card-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.topic-card h3 a { color: var(--text); text-decoration: none; }
.topic-card h3 a:hover { color: var(--primary-hover); }
.topic-card-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.topic-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.topic-card-actions .btn { flex: 1 1 auto; min-height: 44px; padding: 0 14px; font-size: 0.9375rem; }

/* ---------- конспект і приклади ---------- */

.details-note {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.details-note > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 16px;
  background: var(--surface-2);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.details-note > summary::-webkit-details-marker { display: none; }
.details-note > summary::after {
  content: '';
  flex: none;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-3px) rotate(45deg);
  transition: transform 0.2s;
}
.details-note[open] > summary::after { transform: translateY(2px) rotate(225deg); }
.details-note[open] > summary { border-bottom: 1px solid var(--border); }
.details-note-body { padding: 16px; max-width: var(--measure); }
.details-note-body > :last-child { margin-bottom: 0; }

.example-box {
  margin: 16px 0;
  padding: 14px 16px;
  background: var(--surface-2);
  border-left: 4px solid var(--subj-ink);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.example-box > :last-child { margin-bottom: 0; }
.example-box-prompt { font-weight: 700; margin-bottom: 6px; }

/* Дроби без MathJax: <span class="frac"><span>3</span><span>4</span></span>. */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1.1;
  font-size: 0.9em;
  margin: 0 0.2em;
}
.frac > :first-child { border-bottom: 1.5px solid currentColor; padding: 0 0.15em; }
.frac > :last-child { padding: 0 0.15em; }

/* ---------- підвал ---------- */

.site-footer {
  margin-top: 48px;
  padding: 24px 0 calc(24px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.875rem;
}
.site-footer a { color: var(--muted); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 8px; }

/* ---------- сторінки, згенеровані tools/build_site.py ---------- */

.hero { padding: 28px 0 8px; }
.hero h1 { margin-top: 12px; max-width: 22ch; }
.hero-actions { margin-top: 20px; }

.tabs { display: flex; gap: 8px; margin: 24px 0 8px; overflow-x: auto; }
.tab {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-accent); }
[data-tab-panel] > h2:first-child { margin-top: 16px; }
[data-tab-panel] .topic-grid { margin-top: 12px; }

.topic-page .topic-card-badges { margin-top: 4px; margin-bottom: 8px; }
.topic-page .badge-nush { text-decoration: none; }
.cta-row { margin: 20px 0 8px; }
[data-action="toggle-pin"].is-on { background: var(--star-bg); color: var(--star-text); }

.level-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 0; padding: 0; list-style: none; }
.level-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.level-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.level-row .btn { min-height: 44px; padding: 0 16px; }
.btn-link {
  min-height: 44px;
  padding: 0 4px;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}
.btn-link:hover { color: var(--bad-text); }
.btn-link[hidden] { display: none; }

.topic-nav { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin: 32px 0 0; }
.topic-nav .btn { max-width: 100%; white-space: normal; text-align: left; }
.topic-nav [rel="next"] { margin-left: auto; text-align: right; }

.prose h2 { margin-bottom: 8px; }
.prose ul { padding-left: 20px; }
.prose code { font-family: var(--font-mono); font-size: 0.9em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 6px; }

/* ---------- форма /feedback/ (js/app/feedback-page.js) ---------- */
.fb { max-width: var(--measure); margin-top: 24px; }
.fb-kinds { display: flex; flex-wrap: wrap; gap: 10px; }
.fb-kinds .btn { flex: 1 1 220px; }
.fb-form { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.fb-form > .btn { align-self: flex-start; min-width: 180px; }
.fb-form .meta { margin: 0; }
.fb-rules { margin: 0; padding-left: 20px; line-height: 1.5; }
.fb-check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; }
.fb-check input { width: 22px; height: 22px; flex: none; }
.fb-label { font-weight: 600; margin-top: 6px; }
.fb-text { width: 100%; min-height: 140px; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: inherit; color: var(--text); background: var(--surface); resize: vertical; box-sizing: border-box; }
.fb-text:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.fb-image { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.fb-image img { max-width: min(100%, 320px); max-height: 320px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.fb-image-add { cursor: pointer; }
.fb-counter { margin: -4px 0 0; text-align: right; color: var(--bad-text); font-size: 0.875rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.fb-counter[hidden] { display: none; }
.fb-error { margin: 0; color: var(--bad-text); font-weight: 600; }
.fb-error:empty { display: none; }
.fb-turnstile:empty { display: none; }
.fb-hp { position: absolute; left: -10000px; width: 1px; height: 1px; opacity: 0; }
.fb-box { padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); line-height: 1.5; }
.fb-box p { margin: 0 0 8px; }
.fb-box p:last-child { margin-bottom: 0; }
.fb-title { font-weight: 700; }
.fb-thanks { font-weight: 600; font-size: 1.1rem; }

/* ---------- вікно підтвердження (скидання прогресу теми) ---------- */
.confirm-dialog { width: min(360px, calc(100vw - 32px)); padding: 24px 20px 20px; border: none; border-radius: var(--radius-lg); background: var(--surface); color: var(--text); text-align: center; box-shadow: 0 12px 40px rgba(31, 36, 64, 0.2); }
.confirm-dialog::backdrop { background: rgba(31, 36, 64, 0.35); }
.confirm-dialog h2 { margin: 0 0 8px; font-size: 1.25rem; }
.confirm-dialog p { margin: 0 0 20px; color: var(--muted); line-height: 1.45; }
.confirm-icon { font-size: 2.2rem; margin-bottom: 4px; }
.confirm-actions { display: flex; flex-direction: column; gap: 10px; }
.confirm-actions .btn { width: 100%; }
