:root, html[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #e6e8eb;
  --muted: #9aa3b2;
  --accent: #e07b39;
  --accent2: #5b9dd9;
  --code-bg: #1d2129;
  --table-stripe: #1a1d24;
  --btn-text: #1a1a1a;
  --strong-color: #ffffff;
  --shadow: rgba(0, 0, 0, 0.45);
}

html[data-theme="light"] {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #dde1e6;
  --text: #1c1f26;
  --muted: #5c6470;
  --accent: #c2571f;
  --accent2: #1f5c8f;
  --code-bg: #eef0f3;
  --table-stripe: #f2f3f5;
  --btn-text: #ffffff;
  --strong-color: #10131a;
  --shadow: rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.15s ease, color 0.15s ease;
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand, .sidebar .brand a {
  font-weight: 700;
  font-size: 1.1em;
  color: var(--accent);
  text-decoration: none;
  display: block;
  margin-bottom: 16px;
}

.sidebar h3, .nav-section-title {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.75em;
  letter-spacing: 0.08em;
  margin: 18px 0 6px 0;
}

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0 0 10px 0;
}

.sidebar li a {
  display: block;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92em;
}

.sidebar li a:hover {
  background: var(--code-bg);
}

.sidebar li a.active {
  background: var(--accent);
  color: var(--btn-text);
  font-weight: 600;
}

.content {
  flex: 1;
  padding: 40px 56px;
  max-width: 920px;
  min-width: 0;
}

.subtitle {
  color: var(--muted);
  font-size: 1.05em;
  margin-top: -8px;
}

h1 { color: var(--accent); border-bottom: 2px solid var(--border); padding-bottom: 10px; }
h2 { color: var(--accent); margin-top: 2em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
h3 { color: var(--accent2); margin-top: 1.6em; }
h4 { color: var(--text); margin-top: 1.3em; }

a { color: var(--accent2); }

code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  word-break: break-word;
}

pre {
  background: var(--code-bg);
  padding: 14px;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
pre code { background: none; padding: 0; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.2em 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 0;
  font-size: 0.92em;
}

th, td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--code-bg);
  color: var(--accent);
}

tr:nth-child(even) td {
  background: var(--table-stripe);
}

blockquote {
  border-left: 4px solid var(--accent);
  margin: 1em 0;
  padding: 4px 18px;
  color: var(--muted);
  background: var(--panel);
  border-radius: 0 6px 6px 0;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

ul, ol { padding-left: 1.4em; }
li { margin: 4px 0; }

strong { color: var(--strong-color); }

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

/* ---- Theme toggle ---- */

.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--code-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85em;
  margin-bottom: 18px;
  font-family: inherit;
}

.theme-toggle-btn:hover { background: var(--border); }

/* ---- Mobile nav ---- */

.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 101;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  align-items: center;
  justify-content: center;
  font-size: 1.3em;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--shadow);
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 800px) {
  .layout { flex-direction: column; }

  .mobile-nav-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 100;
    box-shadow: 2px 0 24px var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
  }

  .content { padding: 68px 18px 24px 18px; }

  h1 { font-size: 1.5em; }
  h2 { font-size: 1.25em; }
  h3 { font-size: 1.1em; }

  .mode-select { flex-direction: column; }

  .exam-actions { flex-wrap: wrap; }
  .btn-primary { width: 100%; }

  .q-header { flex-wrap: wrap; gap: 6px; }
}

/* ---- Interactive exam ---- */

.exam-header {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

#scoreboard {
  font-weight: 600;
  color: var(--accent);
  margin: 8px 0;
}

.question-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.question-card.card-correct { border-color: #3fae5c; }
.question-card.card-incorrect { border-color: #d9534f; }

.q-header {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85em;
  margin-bottom: 8px;
}

.q-number { color: var(--accent); font-weight: 700; }

.q-text {
  font-weight: 600;
  margin-bottom: 12px;
  font-size: 1.02em;
}

.options { display: flex; flex-direction: column; gap: 6px; }

.option-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

.option-row:hover { background: var(--code-bg); }

.option-row input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.option-letter {
  font-weight: 700;
  color: var(--accent2);
  min-width: 18px;
}

.option-row.correct-option {
  background: rgba(63, 174, 92, 0.15);
  border-color: #3fae5c;
}

.option-row.incorrect-option {
  background: rgba(217, 83, 79, 0.15);
  border-color: #d9534f;
}

.feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--code-bg);
  font-size: 0.92em;
  line-height: 1.5;
}

.card-correct .feedback { border-left: 4px solid #3fae5c; }
.card-incorrect .feedback { border-left: 4px solid #d9534f; }

#page-warning {
  display: none;
  background: rgba(217, 83, 79, 0.15);
  border: 1px solid #d9534f;
  color: #f3b0ae;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
}

.exam-actions {
  display: flex;
  gap: 12px;
  margin: 24px 0 60px 0;
}

.btn-primary {
  background: var(--accent);
  color: var(--btn-text);
  border: none;
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95em;
}

.btn-primary:hover { opacity: 0.9; }

.score-big {
  font-size: 2.4em;
  font-weight: 800;
  color: var(--accent);
  margin: 16px 0;
}

.score-pct { color: var(--muted); font-size: 0.5em; }

.results-note { color: var(--muted); font-size: 0.9em; }

.disclaimer-box {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent2);
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  margin: 18px 0 8px 0;
  font-size: 0.9em;
  color: var(--muted);
  line-height: 1.55;
}

.disclaimer-box strong { color: var(--text); }

.site-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85em;
  line-height: 1.7;
}

.footer-block { margin-bottom: 14px; }
.footer-block:last-child { margin-bottom: 0; }

.footer-block + .footer-block {
  padding: 14px 16px;
  border-top: none;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.footer-block:last-child a { color: var(--accent); font-weight: 600; }

.site-footer p { margin: 4px 0; }
.site-footer a { color: var(--accent2); }

.mode-select {
  display: flex;
  gap: 20px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.mode-card {
  flex: 1;
  min-width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.mode-card h3 { color: var(--accent); margin-top: 0; }
.mode-card p { color: var(--muted); min-height: 70px; }

.q-part {
  font-size: 0.8em;
  color: var(--muted);
  background: var(--code-bg);
  padding: 2px 8px;
  border-radius: 4px;
}
