:root {
  --bg: #f7f5ef;
  --panel: #ffffff;
  --text: #161616;
  --muted: #525252;
  --line: #d8d2c4;
  --accent: #0f766e;
  --accent-2: #7c2d12;
  --good: #166534;
  --warn: #9a3412;
  --shadow: 0 10px 30px rgba(20, 20, 20, 0.08);
  --font-scale: 1;
}

[data-theme="dark"] {
  --bg: #111315;
  --panel: #1b1f23;
  --text: #f4f4f5;
  --muted: #c2c7cf;
  --line: #343a40;
  --accent: #5eead4;
  --accent-2: #fdba74;
  --good: #86efac;
  --warn: #fed7aa;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: calc(17px * var(--font-scale));
  line-height: 1.62;
}

a { color: var(--accent); font-weight: 700; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #102522;
  color: #ffffff;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

[data-theme="dark"] .site-header {
  background: #07110f;
}

.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 12px 8px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  font-weight: 900;
  font-size: clamp(1.45rem, 7vw, 2.25rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  overflow: hidden;
  max-height: 104px;
  opacity: 1;
  padding-top: 10px;
  transition: max-height 180ms ease, opacity 180ms ease, padding-top 180ms ease;
}

body.controls-collapsed .controls {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
}

.header-toggle {
  flex: 0 0 auto;
  min-width: 42px;
  min-height: 42px;
}

.tiny {
  min-width: 42px;
  text-align: center;
  padding-left: 10px;
  padding-right: 10px;
}

.theme-toggle {
  min-width: 108px;
}

.scale-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 0.9em;
}

button, .nav a {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 11px;
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
  text-decoration: none;
  box-shadow: none;
}

.site-header button {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.32);
  white-space: nowrap;
}

.site-header button.primary {
  background: #ffffff;
  color: #102522;
  border-color: #ffffff;
}

button:hover, .nav a:hover, .nav a.active {
  border-color: var(--accent);
  color: var(--accent);
}

.nav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 12px 10px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  max-height: 64px;
  opacity: 1;
  transition: max-height 180ms ease, opacity 180ms ease, padding 180ms ease;
}

body.controls-collapsed .nav {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding-top: 0;
  padding-bottom: 0;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 18px 54px;
}

.hero {
  padding: 30px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

h1, h2, h3 {
  line-height: 1.15;
  margin: 0 0 14px;
}

h1 { font-size: clamp(2rem, 4vw, 3.4rem); }
h2 { margin-top: 30px; font-size: 1.55em; }
h3 { margin-top: 22px; font-size: 1.18em; }

.subtitle {
  color: var(--muted);
  font-size: 1.08em;
  max-width: 820px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.card, .answer, .method, .warning, .mini, .flashcard, details, .progress-panel, .exam-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
}

.card strong { font-size: 1.1em; }
.card span, .muted { color: var(--muted); }

.tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--accent-2);
  font-weight: 800;
  font-size: 0.82em;
}

.answer {
  margin: 16px 0;
  border-left: 5px solid var(--accent);
}

.warning {
  border-left: 5px solid var(--warn);
}

.method {
  border-left: 5px solid var(--good);
}

.en {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
}

body.show-en .en { display: block; }

ol, ul { padding-left: 1.25em; }
li { margin: 0.35em 0; }

table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  overflow-wrap: anywhere;
}

th, td {
  border: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
}

th {
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
  text-align: left;
}

.model {
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.flashcards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.flashcard {
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.flashcard strong {
  color: var(--accent);
}

details {
  margin: 12px 0;
}

details.correction {
  border-left: 5px solid var(--accent);
}

body.exam-mode details.correction > *:not(summary) {
  display: none;
}

body.exam-mode .model,
body.exam-mode .good,
body.exam-mode .bad,
body.exam-mode .answer-key {
  display: none;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

.bad {
  border-left: 5px solid var(--warn);
}

.good {
  border-left: 5px solid var(--good);
}

.print-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.progress-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.progress-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.progress-item input {
  margin-top: 0.35em;
  width: 1.1em;
  height: 1.1em;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.sheet-grid section {
  margin: 0;
}

.compact-list li {
  margin: 0.18em 0;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.score-grid .mini strong {
  display: block;
  color: var(--accent);
}

.quote {
  border-left: 4px solid var(--accent-2);
  padding-left: 12px;
  color: var(--muted);
}

.image-frame {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  margin: 14px 0;
}

.image-frame img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.footer-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 34px;
}

.footer-nav a {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  text-decoration: none;
}

@media (max-width: 820px) {
  .title-row { align-items: flex-start; }
  .brand { padding-top: 2px; }
  .grid, .flashcards, .progress-list, .sheet-grid, .score-grid { grid-template-columns: 1fr; }
  .hero { padding: 20px; }
  table, thead, tbody, tr, th, td { display: block; }
  th { border-bottom: 0; }
  .footer-nav { flex-direction: column; }
  .wrap { padding-top: 16px; }
  .nav a { padding: 7px 10px; }
  h1 { font-size: clamp(1.75rem, 8vw, 2.5rem); }
}

@media print {
  .site-header, .footer-nav, .print-actions, .en {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 12px;
  }

  .wrap {
    max-width: none;
    padding: 0;
  }

  .hero, .answer, .method, .warning, .mini, .flashcard, .progress-panel, .exam-block {
    box-shadow: none;
    border-color: #999;
    break-inside: avoid;
    padding: 7px;
    margin: 0 0 7px;
  }

  h1 { font-size: 24px; }
  h2 { font-size: 15px; margin-top: 6px; }
  h3 { font-size: 13px; margin-top: 8px; }
  p, li, td, th { line-height: 1.28; }

  .flashcards, .sheet-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  table { margin: 4px 0; }
  th, td { padding: 4px; }
}
