:root {
  --bg: #e2e8f0;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #cbd5e1;
  --code-bg: #f1f5f9;
  --shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 4px 10px -6px rgba(15, 23, 42, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #090e1a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --border: #334155;
    --code-bg: #0f172a;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 40px 16px;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 36px 40px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0 0 8px;
  font-size: 1.85rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

h2 {
  margin: 28px 0 12px;
  font-size: 1.25rem;
}

p {
  margin: 0 0 16px;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Список карточек на главной странице */
.nav-list {
  list-style: none;
  padding: 0;
  margin: 20px 0 0;
  display: grid;
  gap: 12px;
}

.nav-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background-color: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
}

.nav-list a::after {
  content: "→";
  color: var(--muted);
  font-weight: 400;
}

.nav-list a:hover {
  border-color: var(--accent);
  background-color: var(--surface);
  transform: translateX(3px);
}

/* Контентные списки и код */
ul:not(.nav-list), ol {
  margin: 0 0 18px;
  padding-left: 22px;
}

li {
  margin-bottom: 8px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background-color: var(--code-bg);
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
}

/* Блоки математических формул на чистом CSS */
.math-block {
  margin: 16px 0 20px;
  padding: 18px 22px;
  font-family: "Times New Roman", Georgia, Cambria, serif;
  font-size: 1.15rem;
  line-height: 1.9;
  background-color: var(--code-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  overflow-x: auto;
}

.math-inline {
  font-family: "Times New Roman", Georgia, Cambria, serif;
  font-size: 1.08em;
  white-space: nowrap;
}

.math-row {
  margin: 4px 0;
  white-space: nowrap;
}

/* Вертикальная дробь */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 3px;
  font-size: 0.88em;
  line-height: 1.15;
}

.frac > span:first-child {
  border-bottom: 1px solid currentColor;
  padding: 0 4px 2px;
}

.frac > span:last-child {
  padding: 2px 4px 0;
}

/* Знак суммы с пределами */
.sum-op {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 4px;
  line-height: 1;
}

.sum-top, .sum-bottom {
  font-size: 0.65em;
}

.sum-symbol {
  font-size: 1.35em;
  line-height: 1.05;
}

/* Матрицы и определители */
.matrix {
  display: inline-table;
  vertical-align: middle;
  border-collapse: collapse;
  margin: 0 4px;
  padding: 0 6px;
  border-left: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  border-radius: 6px;
}

.det {
  display: inline-table;
  vertical-align: middle;
  border-collapse: collapse;
  margin: 0 4px;
  padding: 0 6px;
  border-left: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
}

.matrix td, .det td {
  padding: 2px 8px;
  text-align: center;
}

/* Кнопки возврата на главную */
.back-top {
  display: inline-block;
  margin-bottom: 14px;
  font-size: 0.92rem;
  font-weight: 500;
}

footer {
  margin-top: 32px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.btn-back {
  display: inline-block;
  padding: 8px 14px;
  background-color: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 500;
  text-decoration: none;
}

.btn-back:hover {
  border-color: var(--accent);
  background-color: var(--surface);
  text-decoration: none;
}

@media (max-width: 600px) {
  .container {
    padding: 24px 20px;
  }

  h1 {
    font-size: 1.5rem;
  }
}
