/* ── Tokens ─────────────────────────────────────────── */
:root {
  --bg:        #fdf6ee;
  --surface:   #fffaf4;
  --surface-2: #f5ede0;
  --border:    #e8d9c8;
  --text:      #2b1a08;
  --muted:     #9c7f62;
  --accent:    oklch(0.58 0.16 44);   /* terracotta-amber */
  --accent-lt: oklch(0.93 0.05 44);  /* tinted bg */
  --accent-dk: oklch(0.46 0.17 44);  /* hover */
  --good:      oklch(0.55 0.14 155);
  --warn:      oklch(0.62 0.15 60);
  --bad:       oklch(0.55 0.17 25);
  --radius:    14px;
  --shadow:    0 2px 12px 0 rgba(80,40,10,.08);
  --shadow-md: 0 4px 24px 0 rgba(80,40,10,.12);
}

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Shell ──────────────────────────────────────────── */
#app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Top bar ────────────────────────────────────────── */
#top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(253,246,238,.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  gap: 20px;
}

.brand { display: flex; flex-direction: column; gap: 1px; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.brand-sub  { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

/* ── Level 3-way switch ─────────────────────────────── */
.level-switch { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }

.level-slider-track {
  position: relative;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 0;
}

.level-slider-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  height: calc(100% - 6px);
  border-radius: 999px;
  background: var(--accent);
  transition: transform 0.22s cubic-bezier(.4,0,.2,1), width 0.22s cubic-bezier(.4,0,.2,1);
  pointer-events: none;
  z-index: 0;
  box-shadow: 0 1px 4px rgba(80,40,10,.18);
}

.level-btn {
  position: relative;
  z-index: 1;
  background: none;
  border: none;
  border-radius: 999px;
  padding: 5px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.18s;
  white-space: nowrap;
  user-select: none;
}
.level-btn.active { color: #fff; }
.level-btn:not(.active):hover { color: var(--text); }

.level-hint {
  font-size: 11px;
  color: var(--muted);
  padding-right: 4px;
  height: 14px;
  transition: opacity 0.15s;
}

/* ── Main ───────────────────────────────────────────── */
#app { max-width: 960px; margin: 0 auto; padding: 36px 24px 100px; width: 100%; }

/* ── Screens ────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Typography helpers ─────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.section-desc { font-size: 13px; color: var(--muted); margin-bottom: 12px; margin-top: -4px; }

/* ── Category chips ─────────────────────────────────── */
#categories { margin-bottom: 28px; }

.cat-group-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 20px 0 10px;
}
.cat-group-label:first-child { margin-top: 4px; }

.cat-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cat-chip-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  font-weight: 400;
  user-select: none;
}
.cat-chip-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.cat-chip-btn.selected {
  background: var(--accent-lt);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

.cat-actions-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

/* ── Settings row ───────────────────────────────────── */
.row-settings { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 8px; }

.setting-block { display: flex; flex-direction: column; gap: 10px; }

.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  width: fit-content;
}
.step-btn {
  background: none;
  border: none;
  padding: 7px 18px;
  font-size: 18px;
  font-weight: 300;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
}
.step-btn:hover { background: var(--surface-2); color: var(--text); }
#num-display {
  font-size: 16px;
  font-weight: 600;
  min-width: 36px;
  text-align: center;
  color: var(--text);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 7px 4px;
  line-height: 1;
}

/* ── Mode cards ─────────────────────────────────────── */
.mode-cards { display: flex; flex-direction: column; gap: 12px; }

.mode-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s;
}
.mode-card:hover { box-shadow: var(--shadow-md); }

.mode-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
}
.mode-icon { font-size: 20px; flex-shrink: 0; color: var(--accent); }
.mode-title { font-size: 15px; font-weight: 600; }
.mode-desc  { font-size: 13px; color: var(--muted); }
.mode-toggle-btn {
  margin-left: auto;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  transition: border-color 0.12s, color 0.12s;
  white-space: nowrap;
  flex-shrink: 0;
}
.mode-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }

.mode-card-body {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.03em;
}
.field-label input,
.field-label select {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.12s;
}
.field-label input:focus,
.field-label select:focus { border-color: var(--accent); }

.fine-print { font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.fine-print code { font-size: 11px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

/* ── Buttons ────────────────────────────────────────── */
.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 24px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(160,70,20,.22);
  white-space: nowrap;
}
.primary-btn:hover { background: var(--accent-dk); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(160,70,20,.28); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.primary-btn.small { padding: 7px 16px; font-size: 13px; margin-left: auto; flex-shrink: 0; }

.ghost-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 6px 16px;
  font-family: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  font-weight: 400;
}
.ghost-btn:hover { border-color: var(--muted); color: var(--text); background: var(--surface-2); }

/* ── Quiz screen ────────────────────────────────────── */
.progress-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.progress-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.progress-track {
  flex: 1;
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0;
  border-radius: 999px;
  transition: width 0.3s cubic-bezier(.4,0,.2,1);
}

.quiz-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 28px 22px;
  box-shadow: var(--shadow-md);
}
.q-meta { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.q-cat-chip, .q-level-chip {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 10px;
}
.q-cat-chip  { background: var(--accent-lt); color: var(--accent); }
.q-level-chip{ background: var(--surface-2); color: var(--muted); }

.q-text {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.45;
  margin-bottom: 20px;
  color: var(--text);
  text-wrap: pretty;
}

textarea#q-answer {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  resize: vertical;
  line-height: 1.6;
  outline: none;
  transition: border-color 0.15s;
}
textarea#q-answer:focus { border-color: var(--accent); }
textarea#q-answer::placeholder { color: var(--muted); }

.quiz-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  align-items: center;
}
.quiz-actions .primary-btn { margin-left: auto; }
.status-msg { font-size: 13px; color: var(--muted); margin-top: 10px; min-height: 18px; }

/* ── Results ────────────────────────────────────────── */
.results-header { margin-bottom: 20px; }
.results-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }

.results-summary-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.summary-score {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}
.summary-score .pct { color: var(--accent); }
.summary-score .muted { color: var(--muted); font-size: 26px; font-weight: 400; }

.verdict-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 20px;
}
.verdict-badge.at_level    { background: oklch(0.93 0.05 155); color: var(--good); }
.verdict-badge.above_level { background: var(--accent-lt); color: var(--accent); }
.verdict-badge.below_level { background: oklch(0.95 0.04 60); color: var(--warn); }

.results-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin: 16px 0 8px;
}

.tight-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.tight-list li {
  font-size: 13.5px;
  padding-left: 16px;
  position: relative;
  color: var(--text);
  line-height: 1.5;
}
.tight-list li::before {
  content: "·";
  position: absolute;
  left: 4px;
  color: var(--accent);
  font-weight: 700;
}

/* ── Per-question result cards ──────────────────────── */
.qresult {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin: 10px 0;
  box-shadow: var(--shadow);
}
.qresult-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.qresult-question { font-size: 15px; font-weight: 600; margin-bottom: 14px; line-height: 1.4; }
.qresult-answer-label, .qresult-outline-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 6px;
}
.qresult-answer {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 13px;
  font-size: 13px;
  white-space: pre-wrap;
  color: var(--text);
  margin-bottom: 14px;
  line-height: 1.55;
}

.scores-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin: 10px 0;
}
.score-pill {
  background: var(--accent-lt);
  color: var(--accent-dk);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 500;
}
.score-pill.total {
  background: var(--accent);
  color: #fff;
}

.verdict-inline {
  font-size: 13px;
  font-weight: 600;
  margin: 8px 0 12px;
}
.verdict-inline.at_level    { color: var(--good); }
.verdict-inline.above_level { color: var(--accent); }
.verdict-inline.below_level { color: var(--warn); }

.qresult-fb-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin: 12px 0 6px;
}

/* ── Error ──────────────────────────────────────────── */
.error-msg {
  color: var(--bad);
  font-size: 13px;
  margin-top: 14px;
  min-height: 18px;
}

/* ── Quiz layout (card + notes aside) ───────────────── */
.quiz-layout {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 168px;
  gap: 18px;
  align-items: start;
}

.quiz-notes {
  background: rgba(245,237,224,.5);
  border: 1px solid rgba(232,217,200,.5);
  border-radius: var(--radius);
  padding: 10px 11px;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 80px;
  opacity: 0.68;
  transition: opacity 0.2s;
}
.quiz-notes:focus-within { opacity: 1; }

.notes-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}
.notes-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(156,127,98,.7);
}
.notes-label > span { color: var(--accent); text-transform: none; letter-spacing: 0; font-weight: 500; }
.notes-status {
  font-size: 10px;
  color: rgba(156,127,98,.65);
  font-style: italic;
}

#q-notes {
  background: rgba(253,246,238,.6);
  border: 1px solid rgba(232,217,200,.5);
  border-radius: 7px;
  padding: 8px 9px;
  font-family: inherit;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 160px;
  width: 100%;
  transition: border-color 0.12s, background 0.12s;
}
#q-notes:focus {
  border-color: rgba(160,80,30,.35);
  background: var(--bg);
}
#q-notes::placeholder { color: rgba(156,127,98,.5); }

.notes-footer {
  display: flex;
  justify-content: flex-end;
}

.ghost-btn.small {
  padding: 4px 10px;
  font-size: 11px;
}

/* ── Expandable notes panel (setup screen) ─────────── */
.notes-panel {
  margin-top: 32px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.notes-panel[open] { box-shadow: var(--shadow-md); }

.notes-panel-summary {
  cursor: pointer;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  list-style: none;
}
.notes-panel-summary::-webkit-details-marker { display: none; }
.notes-panel-summary::marker { content: ""; }
.notes-expand-caret {
  font-size: 14px;
  color: var(--muted);
  transition: transform 0.18s ease;
  flex-shrink: 0;
}
.notes-panel[open] .notes-expand-caret { transform: rotate(180deg); }

.notes-panel-body {
  padding: 4px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.notes-panel-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0;
  overflow: hidden;
}
.notes-panel-item > summary {
  cursor: pointer;
  padding: 10px 14px;
  list-style: none;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.notes-panel-item > summary::-webkit-details-marker { display: none; }

.notes-item-group {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 999px;
}
.notes-item-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.notes-item-preview {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 180px;
  min-width: 0;
}

.notes-item-textarea {
  display: block;
  width: calc(100% - 28px);
  margin: 0 14px 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 120px;
  transition: border-color 0.12s;
}
.notes-item-textarea:focus { border-color: var(--accent); }
.notes-item-status {
  padding: 0 14px 10px;
  font-style: italic;
}

.notes-panel-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px 14px;
  border-top: 1px solid var(--border);
}

/* ── Results action row ─────────────────────────────── */
.results-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 480px) {
  .quiz-layout { grid-template-columns: 1fr !important; }
  .quiz-notes { position: static; opacity: 1; }
  #q-notes { min-height: 100px; }
}

@media (max-width: 520px) {
  #top-bar { padding: 12px 16px; flex-wrap: wrap; gap: 12px; }
  #app { padding: 24px 14px 80px; }
  .quiz-card { padding: 20px 16px 16px; }
  .level-btn { padding: 5px 12px; font-size: 12px; }
  .notes-export-strip { flex-direction: column; align-items: flex-start; }
}
