﻿:root {
  color-scheme: light;
  --bg: #f7f6f1;
  --surface: #ffffff;
  --surface-2: #f0f4ed;
  --ink: #20231f;
  --muted: #697064;
  --line: #d8ded2;
  --accent: #2f7d5a;
  --accent-dark: #215d43;
  --bad: #b13f3f;
  --good: #24724f;
  --focus: #d89232;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button, select, input, textarea { font: inherit; }

button, select, input, textarea,
#question-title, .question-text, .result-panel,
.tags span, .unit-row-header {
  overflow-wrap: anywhere;
}

button, select, textarea, input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 8px;
}

button {
  min-height: 44px;
  padding: 0 16px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(16px, 4vw, 44px) 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.84rem;
  font-weight: 700;
}

h1, h2, p, dl, dd { margin: 0; }

h1 {
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  line-height: 1.2;
  letter-spacing: 0;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 8px;
  min-width: min(360px, 100%);
}

.quick-stats div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.quick-stats dt {
  color: var(--muted);
  font-size: 0.75rem;
}

.quick-stats dd {
  margin-top: 3px;
  font-size: 1.35rem;
  font-weight: 800;
}

.control-band {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.85fr) auto minmax(320px, auto);
  align-items: end;
  gap: 12px;
  padding: 16px clamp(16px, 4vw, 44px);
  background: #fbfaf7;
  border-bottom: 1px solid var(--line);
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

select, input[type="text"], textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
}

textarea {
  min-height: 132px;
  resize: vertical;
  line-height: 1.7;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 700;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.control-actions, .nav-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
  font-weight: 700;
}

.danger:hover:not(:disabled) {
  background: #8f3030;
  border-color: #8f3030;
}

.reset-confirm-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #ddb1a1;
  border-radius: 8px;
  background: #fff0e9;
}

.reset-confirm-panel[hidden] {
  display: none;
}

.reset-confirm-panel p {
  font-weight: 800;
  line-height: 1.6;
}

.reset-confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.study-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 18px auto 32px;
}

.question-panel, .side-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.question-panel {
  padding: clamp(18px, 3vw, 28px);
  min-height: 520px;
}

.side-panel {
  padding: 18px;
  align-self: start;
}

.side-panel h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.question-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.count-label, .tags span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent-dark);
  font-size: 0.8rem;
  font-weight: 800;
}

.tags {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.progress-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7e3d8;
  margin-bottom: 22px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

#question-title {
  font-size: clamp(1.1rem, 2.2vw, 1.45rem);
  line-height: 1.35;
  margin-bottom: 14px;
}

.question-text {
  font-size: clamp(1.02rem, 1.8vw, 1.2rem);
  line-height: 1.8;
  margin-bottom: 20px;
  white-space: pre-line;
}

.answer-area {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.option-grid {
  display: grid;
  gap: 10px;
}

.option-btn, .order-btn {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  text-align: left;
  line-height: 1.5;
}

.option-btn.selected, .order-btn.selected {
  border-color: var(--accent);
  background: #e8f3ed;
  color: var(--accent-dark);
  font-weight: 700;
}

.order-layout { display: grid; gap: 14px; }

.order-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.order-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e8f3ed;
  color: var(--accent-dark);
  font-size: 0.9rem;
  font-weight: 700;
}

.order-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.result-panel {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 14px 0;
  line-height: 1.7;
}

.result-panel.correct {
  border-color: #9ac7af;
  background: #ecf7f1;
}

.result-panel.wrong {
  border-color: #ddb1a1;
  background: #fff0e9;
}

.result-label {
  font-weight: 800;
  margin-bottom: 6px;
}

.result-panel.correct .result-label { color: var(--good); }
.result-panel.wrong .result-label { color: var(--bad); }
.answer-line { font-weight: 700; }

.nav-actions {
  justify-content: space-between;
  margin-top: 18px;
}

.unit-progress {
  display: grid;
  gap: 10px;
}

.unit-row { display: grid; gap: 5px; }

.unit-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.mini-track {
  height: 7px;
  border-radius: 999px;
  background: #e7e3d8;
  overflow: hidden;
}

.mini-track span {
  display: block;
  height: 100%;
  background: var(--focus);
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfaf7;
  line-height: 1.7;
}

@media (max-width: 920px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .control-band { grid-template-columns: 1fr 1fr; }
  .control-actions { grid-column: 1 / -1; }
  .study-layout { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .topbar { padding: 20px 16px 14px; }

  .quick-stats {
    grid-template-columns: repeat(3, 1fr);
    min-width: 0;
  }

  .quick-stats div { padding: 8px; }
  .quick-stats dd { font-size: 1.15rem; }

  .control-band {
    grid-template-columns: 1fr;
    padding: 14px 16px;
  }

  .control-actions, .nav-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .reset-confirm-panel {
    grid-template-columns: 1fr;
  }

  .reset-confirm-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .study-layout {
    width: calc(100% - 24px);
    margin-top: 12px;
  }

  .question-panel, .side-panel { padding: 16px; }
  .question-panel { min-height: auto; }

  .question-topline {
    align-items: flex-start;
    flex-direction: column;
  }

  .tags { justify-content: flex-start; }
}
