/* =====================================================================
   Единая стилевая таблица «Решателя уравнений».
   Темы реализуются через data-bs-theme + CSS-переменные.
   Цель — академический, чистый, современный вид.
===================================================================== */

/* ---------- Палитра и токены ---------- */
:root {
  --brand: #4f46e5;          /* индиго */
  --brand-2: #6366f1;
  --brand-soft: #eef2ff;
  --accent: #06b6d4;         /* бирюза для акцентов */
  --accent-2: #0ea5e9;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;

  --code-bg: #f1f5f9;
  --code-fg: #1e293b;

  --hero-grad: linear-gradient(135deg, #eef2ff 0%, #e0f2fe 50%, #ecfeff 100%);

  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow: 0 6px 20px -4px rgba(15,23,42,.10), 0 2px 6px -2px rgba(15,23,42,.06);
  --shadow-lg: 0 18px 40px -16px rgba(15,23,42,.18), 0 4px 10px -4px rgba(15,23,42,.08);

  --radius-sm: 0.5rem;
  --radius: 0.85rem;
  --radius-lg: 1.25rem;

  --tx: 220ms cubic-bezier(.4,0,.2,1);
}

[data-bs-theme="dark"] {
  --brand: #818cf8;
  --brand-2: #6366f1;
  --brand-soft: #1e1b4b;
  --accent: #22d3ee;
  --accent-2: #38bdf8;

  --bg: #0b1220;
  --surface: #111a2e;
  --surface-2: #0f172a;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #1e293b;

  --code-bg: #0f172a;
  --code-fg: #e5e7eb;

  --hero-grad: linear-gradient(135deg, #0b1220 0%, #14233f 50%, #0e1f33 100%);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.40);
  --shadow: 0 6px 24px -6px rgba(0,0,0,.55), 0 2px 6px -2px rgba(0,0,0,.40);
  --shadow-lg: 0 20px 44px -16px rgba(0,0,0,.70), 0 4px 12px -4px rgba(0,0,0,.45);
}

/* ---------- Базовый каркас ---------- */
html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-feature-settings: "ss01", "cv11";
}

main { flex: 1 0 auto; }
footer { flex-shrink: 0; }

.site-footer {
  position: relative;
  background:
    radial-gradient(700px 200px at 100% 0%,
      color-mix(in srgb, var(--brand) 8%, transparent) 0%, transparent 60%),
    radial-gradient(700px 200px at 0% 100%,
      color-mix(in srgb, var(--accent) 8%, transparent) 0%, transparent 60%),
    var(--surface);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
}
.site-footer::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: -1px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    color-mix(in srgb, var(--brand) 35%, transparent) 30%,
    color-mix(in srgb, var(--accent) 35%, transparent) 70%,
    transparent 100%);
  opacity: .8;
}
.footer-heading {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text);
  margin-bottom: 1rem;
  font-weight: 600;
}
.footer-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: .4rem;
}
.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: .92rem;
  transition: color var(--tx);
}
.footer-links a:hover { color: var(--brand); }
.footer-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.footer-tags span {
  font-size: .78rem;
  padding: .25rem .55rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
}
.footer-bottom {
  border-top: 1px solid var(--border);
}

::selection { background: var(--brand); color: #fff; }

a { transition: color var(--tx); }

/* ---------- Navbar ---------- */
.navbar {
  background: color-mix(in srgb, var(--surface) 85%, transparent) !important;
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border) !important;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.navbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    color-mix(in srgb, var(--brand) 35%, transparent) 30%,
    color-mix(in srgb, var(--accent) 35%, transparent) 70%,
    transparent 100%);
  opacity: .8;
  pointer-events: none;
}
.navbar-brand { letter-spacing: -0.015em; font-weight: 600; }
.navbar-brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  letter-spacing: -0.01em;
}
.navbar-brand .brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  font-family: "Cambria Math", "Latin Modern Math", Georgia, serif;
  font-style: italic;
  font-size: 1.05rem;
  box-shadow: 0 4px 14px -2px rgba(79,70,229,.45);
}
.navbar .nav-link {
  position: relative;
  color: var(--text-muted);
  font-weight: 500;
  padding-inline: .75rem !important;
  transition: color var(--tx);
}
.navbar .nav-link:hover,
.navbar .nav-link.active {
  color: var(--text);
}
.navbar .nav-link.active::after {
  content: "";
  position: absolute;
  left: .75rem; right: .75rem; bottom: -2px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

/* ---------- Карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--tx), transform var(--tx),
              border-color var(--tx);
}
.card.hover-lift:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--brand) 30%, var(--border));
}
.card-title { font-weight: 600; letter-spacing: -0.01em; }
.card .card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: inline-grid; place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
  margin-bottom: .85rem;
  transition: transform var(--tx);
}
.card:hover .card-icon { transform: rotate(-6deg) scale(1.05); }
.card .card-icon svg { width: 22px; height: 22px; }

/* ---------- Hero ---------- */
.hero {
  position: relative;
  padding: 3.25rem 2.25rem;
  border-radius: var(--radius-lg);
  background: var(--hero-grad);
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.hero::before, .hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: .55;
  z-index: -1;
}
.hero::before {
  width: 280px; height: 280px;
  right: -60px; top: -80px;
  background: radial-gradient(circle, var(--brand) 0%, transparent 70%);
}
.hero::after {
  width: 320px; height: 320px;
  left: -90px; bottom: -120px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
}
.hero h1 {
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text) 0%, var(--brand) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
[data-bs-theme="dark"] .hero h1 {
  background: linear-gradient(135deg, #fff 0%, var(--brand) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .lead { color: var(--text-muted); max-width: 56ch; }

.hero-watermark {
  position: absolute;
  right: -2rem; bottom: -3rem;
  font-family: "Cambria Math", "Latin Modern Math", Georgia, serif;
  font-style: italic;
  font-size: clamp(8rem, 20vw, 18rem);
  font-weight: 700;
  color: var(--brand);
  opacity: .06;
  z-index: -1;
  user-select: none;
  pointer-events: none;
}

/* ---------- Кнопки ---------- */
.btn {
  --bs-btn-padding-x: 1.05rem;
  --bs-btn-padding-y: .55rem;
  border-radius: 0.65rem;
  font-weight: 500;
  letter-spacing: .005em;
  transition: transform var(--tx), box-shadow var(--tx),
              background var(--tx), color var(--tx);
}
.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-2);
  --bs-btn-hover-border-color: var(--brand-2);
  --bs-btn-active-bg: var(--brand-2);
  --bs-btn-active-border-color: var(--brand-2);
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--brand) 75%, transparent);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-success {
  --bs-btn-bg: var(--success);
  --bs-btn-border-color: var(--success);
}
.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-border-color: var(--brand);
}
.btn-outline-success {
  --bs-btn-color: var(--success);
  --bs-btn-border-color: var(--success);
  --bs-btn-hover-bg: var(--success);
  --bs-btn-hover-border-color: var(--success);
}

/* ---------- Формы ---------- */
.form-control,
.form-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  transition: border-color var(--tx), box-shadow var(--tx);
}
.form-control:focus,
.form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 20%, transparent);
}
.form-control.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 18%, transparent);
}
.form-label { font-weight: 500; color: var(--text); }
.form-control[type="text"] {
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.98rem;
}

/* ---------- Палитра ввода математики ---------- */
.math-palette { gap: .35rem; }
.math-palette .btn {
  --bs-btn-padding-x: .65rem;
  --bs-btn-padding-y: .3rem;
  font-family: "Cambria Math", Georgia, serif;
  font-size: 1.02rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0.5rem;
  min-width: 2.4rem;
  flex: 0 0 auto;
  transition: background var(--tx), color var(--tx),
              border-color var(--tx), transform var(--tx);
}
.math-palette .btn:hover {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: var(--brand);
  transform: translateY(-1px);
}
@media (max-width: 575.98px) {
  .math-palette {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    padding-bottom: .25rem;
    margin-inline: -0.25rem;
    padding-inline: .25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .math-palette::-webkit-scrollbar { height: 4px; }
  .math-palette::-webkit-scrollbar-thumb {
    background: var(--border); border-radius: 4px;
  }
  .math-palette .btn {
    min-width: 2.2rem;
    padding: .25rem .55rem;
    font-size: .95rem;
  }
}

/* ---------- Code ---------- */
code, kbd, samp {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: .12rem .4rem;
  border-radius: 6px;
  font-size: 0.9em;
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
}
pre code { background: transparent; padding: 0; }

/* ---------- Шаги решения ---------- */
ol#qSteps, ol#odeSteps {
  list-style: none;
  padding-left: 0;
  counter-reset: step;
}
ol#qSteps li, ol#odeSteps li {
  counter-increment: step;
  position: relative;
  padding: .65rem .85rem .65rem 2.6rem;
  margin-bottom: .45rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .94rem;
  line-height: 1.5;
}
ol#qSteps li::before, ol#odeSteps li::before {
  content: counter(step);
  position: absolute;
  left: .65rem;
  top: .55rem;
  width: 1.55rem; height: 1.55rem;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  font-weight: 600;
  font-size: .82rem;
  box-shadow: 0 2px 6px -2px color-mix(in srgb, var(--brand) 60%, transparent);
}

/* ---------- Графики ---------- */
#qPlotWrap img,
#odePlotWrap img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface);
}

/* ---------- Блок ответа ИИ ---------- */
.alert {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.ai-answer {
  position: relative;
  margin-top: 1rem;
  padding: 1.1rem 1.25rem;
  background:
    radial-gradient(800px 200px at 0% 0%,
      color-mix(in srgb, var(--brand) 10%, transparent) 0%, transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.ai-answer::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--brand), var(--accent));
}

/* Заголовок блока «Пояснение от ИИ-помощника» */
.ai-answer .ai-header {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 600;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--brand);
  padding-bottom: .65rem;
  margin-bottom: .85rem;
  border-bottom: 1px solid var(--border);
}
.ai-answer .ai-spark {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  font-size: .9rem;
  box-shadow: 0 4px 12px -2px color-mix(in srgb, var(--brand) 55%, transparent);
}

/* Лид-абзац (бывшее «Введение») */
.ai-answer .ai-lead {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 1rem;
  line-height: 1.55;
}
.ai-answer .ai-lead p:last-child { margin-bottom: 0; }

/* Секции «Метод/Шаги/Ответ» */
.ai-answer .ai-section {
  margin-top: 1rem;
  padding: .9rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.ai-answer .ai-section-head {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .55rem;
}
.ai-answer .ai-section-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: inline-grid; place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
  flex-shrink: 0;
}
.ai-answer .ai-section-icon svg { width: 16px; height: 16px; }
.ai-answer .ai-section-title {
  margin: 0;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.005em;
}
.ai-answer .ai-section-body { color: var(--text); }
.ai-answer .ai-section-body p:last-child { margin-bottom: 0; }
.ai-answer .ai-section-body ol,
.ai-answer .ai-section-body ul {
  padding-left: 1.25rem;
  margin-bottom: 0;
}
.ai-answer .ai-section-body li { margin-bottom: .35rem; line-height: 1.55; }
.ai-answer .ai-section-body li::marker { color: var(--brand); font-weight: 600; }

/* Уникальные акценты для каждой из трёх секций */
.ai-answer .ai-section:nth-of-type(2) .ai-section-icon {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}
.ai-answer .ai-section:nth-of-type(3) .ai-section-icon {
  background: color-mix(in srgb, var(--success) 18%, transparent);
  color: var(--success);
}

.ai-answer code {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 500;
}
.ai-answer .ai-footer {
  margin-top: 1rem;
  padding-top: .65rem;
  border-top: 1px dashed var(--border);
}

/* Стриминг: моноширинный текст с мигающим курсором */
.ai-answer .ai-stream {
  white-space: pre-wrap;
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: .92rem;
  line-height: 1.55;
  color: var(--text);
}
.ai-answer .ai-stream-active::after {
  content: "▍";
  display: inline-block;
  margin-left: 1px;
  color: var(--brand);
  animation: blink 1s steps(2, jump-none) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Иконки внутри карточек */
.icon-tile {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: inline-grid; place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
}
.icon-tile.icon-accent {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}
.icon-tile.icon-success {
  background: color-mix(in srgb, var(--success) 18%, transparent);
  color: var(--success);
}
.icon-tile svg { width: 22px; height: 22px; }

/* Таблицы */
.table {
  --bs-table-bg: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.table thead th {
  background: var(--surface-2);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

/* Бейджи */
.badge {
  font-weight: 500;
  letter-spacing: .02em;
  border-radius: 6px;
  padding: .35em .55em;
}
.badge.bg-primary { background: var(--brand) !important; }
.badge.bg-success { background: var(--success) !important; }

/* Спиннер «Решаем уравнение…» */
#qSpinner, #odeSpinner {
  display: flex; flex-direction: column;
  align-items: center; gap: .75rem;
  padding: 2rem !important;
}
.solve-spinner {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Анимация появления результата */
#qResult, #odeResult {
  animation: fadeUp .35s var(--tx) both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Адаптация */
@media (max-width: 575.98px) {
  .display-1 { font-size: 4rem; }
  .display-5 { font-size: 1.8rem; }
  .display-6 { font-size: 1.5rem; }
  .hero { padding: 1.75rem 1.25rem; }
  .math-palette .btn { font-size: .9rem; min-width: 2.1rem; }
}

/* Скроллбар (на dark) */
[data-bs-theme="dark"] ::-webkit-scrollbar { width: 10px; height: 10px; }
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 8px;
}
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
