:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-muted: #f6f8fa;
  --border: #d4dbe3;
  --text: #1f2933;
  --text-muted: #5b6875;
  --accent: #2f6f94;
  --accent-hover: #285f80;
  --danger: #b13a36;
  --success: #256045;
  --warning: #8b6400;
  --attempts-slice: #6f9db8;
  --correct-slice: #77b295;
  --wrong-slice: #d96f6a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  --radius-small: 8px;
  --max-width: 1080px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161a1f;
  --surface: #1f252c;
  --surface-muted: #252c34;
  --border: #39424d;
  --text: #e6ebf0;
  --text-muted: #aeb8c2;
  --accent: #6f9db8;
  --accent-hover: #82abc3;
  --danger: #e17c78;
  --success: #77b295;
  --warning: #d4ab4f;
  --attempts-slice: #7fb0c9;
  --correct-slice: #77b295;
  --wrong-slice: #d96f6a;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.page {
  width: min(calc(100% - 24px), var(--max-width));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.stack {
  display: grid;
  gap: 16px;
}

.stack.compact {
  gap: 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
}

.muted {
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

.header-row,
.toolbar {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.support-link {
  color: var(--text-muted);
  font-size: 0.95rem;
  text-decoration: none;
}

.support-link:hover {
  color: var(--text);
  text-decoration: underline;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: var(--text-muted);
}

.actions {
  display: grid;
  gap: 12px;
}

.inline-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button,
.button-like {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

button:hover {
  border-color: #b8c2cc;
}

button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.theme-toggle {
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .icon-sun,
:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
}

.segment {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
}

.segment-button {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  background: transparent;
}

.segment-button.active {
  background: var(--surface);
  box-shadow: var(--shadow);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input {
  margin: 0;
}

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

.hint,
.error,
.result-summary {
  padding: 12px 14px;
  border-radius: var(--radius-small);
}

.hint {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.error {
  background: rgba(177, 58, 54, 0.10);
  border: 1px solid rgba(177, 58, 54, 0.28);
  color: var(--danger);
}

.result-summary {
  background: rgba(37, 96, 69, 0.10);
  border: 1px solid rgba(37, 96, 69, 0.28);
  color: var(--success);
}

.question-card {
  padding: 18px;
}

.question-head {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.question-index {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.answers {
  display: grid;
  gap: 10px;
}

.answer-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-muted);
}

.answer-row input {
  margin-top: 3px;
}

.answer-row.correct {
  border-color: rgba(37, 96, 69, 0.45);
  background: rgba(37, 96, 69, 0.10);
}

.answer-row.missed {
  border-color: rgba(139, 100, 0, 0.48);
  background: rgba(139, 100, 0, 0.11);
}

.answer-row.wrong {
  border-color: rgba(177, 58, 54, 0.45);
  background: rgba(177, 58, 54, 0.10);
}

.answer-mark {
  display: block;
  margin-top: 4px;
  font-size: 0.92rem;
}

.answer-mark.correct {
  color: var(--success);
}

.answer-mark.wrong {
  color: var(--danger);
}

.answer-mark.missed {
  color: var(--warning);
}

.question-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.question-status {
  color: var(--text-muted);
}

.chart {
  gap: 10px;
}

.chart-empty {
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-small);
  color: var(--text-muted);
}

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

.summary-card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-muted);
}

.donut {
  position: relative;
  width: 74px;
  height: 74px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: var(--surface);
}

.donut-center {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

.summary-text {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.summary-title {
  font-weight: 600;
}

.summary-value {
  color: var(--text-muted);
}

.summary-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: currentColor;
}

.attempts-slice {
  background: var(--attempts-slice);
}

.correct-slice {
  background: var(--correct-slice);
}

.wrong-slice {
  background: var(--wrong-slice);
}

.bar-row,
.stat-row {
  display: grid;
  gap: 6px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
}

.bar-track {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.attempts-fill {
  background: var(--accent);
}

.correctness-track {
  height: 8px;
  display: flex;
}

.correct-fill {
  background: var(--success);
}

.wrong-fill {
  background: var(--danger);
}

@media (max-width: 720px) {
  .page {
    width: min(calc(100% - 16px), var(--max-width));
    padding-top: 16px;
  }

  .card,
  .question-card {
    padding: 16px;
  }

  .range-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .theme-toggle {
    width: 100%;
  }

  .header-tools {
    width: 100%;
    justify-content: flex-start;
  }

  .support-link {
    width: 100%;
  }
}
