:root {
  /* Warm off-white / near-black editorial palette. One restrained accent
     (deep muted green) does double duty for correct answers and primary
     actions; muted brick red is the only other functional color. */
  --bg: #faf9f7;
  --text: #1a1a1a;
  --text-dim: #6e6a63;
  --border: #e3e0d9;
  --surface: #f1efe8;
  --accent: #3f5e4e;
  --accent-dark: #2f4a3c;
  --accent-contrast: #faf9f7;
  --accent-rgb: 63, 94, 78;
  --red: #a14a3f;
  --red-rgb: 161, 74, 63;

  /* Generous 8px spacing rhythm */
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;
  --space-7: 64px;
  --space-8: 96px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

:root[data-theme="dark"] {
  --bg: #141311;
  --text: #f1eee7;
  --text-dim: #99928a;
  --border: #322e27;
  --surface: #1d1b17;
  --accent: #7baf91;
  --accent-dark: #649279;
  --accent-contrast: #141311;
  --accent-rgb: 123, 175, 145;
  --red: #cd8175;
  --red-rgb: 205, 129, 117;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  background: var(--bg);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 200ms var(--ease-out), color 200ms var(--ease-out);
}

h1,
h2,
h3 {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-1);
  line-height: 1.15;
}

h1 {
  font-size: clamp(2.1rem, 1.6rem + 2vw, 3rem);
}

h2 {
  font-size: clamp(1.4rem, 1.15rem + 1vw, 1.85rem);
}

h3 {
  font-size: 1.2rem;
}

p {
  margin: 0 0 var(--space-2);
}

button {
  font-family: inherit;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-3) var(--space-8);
  min-height: 100vh;
}

.loading-state,
.error-state {
  padding: var(--space-7) 0;
  color: var(--text-dim);
  text-align: center;
}

.error-detail {
  font-size: 0.85rem;
  opacity: 0.8;
}

/* Screen transition */

.screen {
  animation: screen-in 260ms var(--ease-out);
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Buttons — minimal, flat, thin-outline. Primary actions are uppercase
   with wide letter-spacing and invert (fill) on hover; everything else
   stays plain-case and quieter. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 var(--space-4);
  border-radius: 0;
  background: transparent;
  font-size: 0.95rem;
  cursor: pointer;
  width: auto;
  transition: background-color 200ms var(--ease-out), color 200ms var(--ease-out), border-color 200ms var(--ease-out),
    opacity 150ms var(--ease-out);
}

.btn:active:not(:disabled) {
  opacity: 0.7;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-primary {
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

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

.btn-secondary {
  border: 1px solid var(--text);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--text);
  color: var(--bg);
}

/* Lighter than .btn-primary/.btn-secondary on purpose — confidence rating
   is an optional add-on to "Next", not a required step. Plain text, no
   outline at all. */
.btn-confidence {
  border: none;
  min-height: auto;
  padding: var(--space-1) 0;
  color: var(--text-dim);
  font-size: 0.9rem;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  transition: color 180ms var(--ease-out), text-decoration-color 180ms var(--ease-out);
}

.btn-confidence:hover:not(:disabled) {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

/* Theme toggle + back arrow — matching minimal icon buttons */

.theme-toggle,
.back-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 150ms var(--ease-out), color 150ms var(--ease-out);
}

.theme-toggle:hover,
.back-btn:hover {
  border-color: var(--border);
  color: var(--text);
}

.theme-toggle svg,
.back-btn svg {
  width: 19px;
  height: 19px;
}

/* Home screen */

.home-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.home-header .subtitle {
  color: var(--text-dim);
  margin: 0;
}

.cert-list {
  display: flex;
  flex-direction: column;
}

.cert-entry {
  padding: var(--space-6) 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  transition: box-shadow 200ms var(--ease-out);
}

/* A cert with an unfinished session — every entry stays equally
   selectable, this inset rule just calls out that one has progress
   waiting. Inset shadow paints inside the box, so it never shifts layout. */
.cert-entry-active {
  box-shadow: inset 3px 0 0 0 var(--accent);
  padding-left: var(--space-3);
}

.cert-count {
  color: var(--text-dim);
  margin: 0;
}

.cert-stats {
  display: flex;
  gap: var(--space-5);
  padding-top: var(--space-2);
  margin-top: var(--space-1);
  border-top: 1px solid var(--border);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.cert-entry-progress {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
}

.link-btn {
  background: none;
  border: none;
  padding: 4px 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  align-self: flex-start;
  transition: color 150ms var(--ease-out);
}

.link-btn:hover {
  color: var(--accent);
}

/* Session screen */

.session-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.session-progress-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.progress-track {
  height: 1px;
  background: var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 280ms var(--ease-out);
}

.session-progress-text {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.question-stem {
  font-size: clamp(1.4rem, 1.15rem + 1vw, 1.75rem);
  line-height: 1.35;
  margin-bottom: var(--space-1);
}

.multi-hint {
  color: var(--accent);
  font-size: 0.9rem;
  margin: var(--space-1) 0 0;
}

.options {
  display: flex;
  flex-direction: column;
  margin: var(--space-5) 0;
  border-top: 1px solid var(--border);
}

.option-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: var(--space-3) var(--space-1);
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--text);
  min-height: 56px;
  cursor: pointer;
  transition: background-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
}

.option-card:hover:not(:disabled) {
  background: var(--surface);
}

.option-card:active:not(:disabled) {
  opacity: 0.8;
}

.option-card:disabled {
  cursor: default;
}

.option-id {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  transition: border-color 180ms var(--ease-out), color 180ms var(--ease-out);
}

.option-text {
  flex: 1 1 auto;
  padding-top: 0.15rem;
}

.option-selected {
  background: rgba(var(--accent-rgb), 0.07);
  box-shadow: inset 3px 0 0 0 var(--accent);
}

.option-selected .option-id {
  border-color: var(--accent);
  color: var(--accent);
}

.option-correct {
  background: rgba(var(--accent-rgb), 0.09);
  box-shadow: inset 3px 0 0 0 var(--accent);
}

.option-correct .option-id {
  border-color: var(--accent);
  color: var(--accent);
}

.option-incorrect {
  background: rgba(var(--red-rgb), 0.09);
  box-shadow: inset 3px 0 0 0 var(--red);
}

.option-incorrect .option-id {
  border-color: var(--red);
  color: var(--red);
}

.explanation-panel {
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
  margin: var(--space-4) 0;
  animation: panel-in 220ms var(--ease-out);
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel-correct {
  border-top-color: var(--accent);
}

.panel-incorrect {
  border-top-color: var(--red);
}

.explanation-result {
  font-family: "Inter", sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 var(--space-2);
}

.panel-correct .explanation-result {
  color: var(--accent);
}

.panel-incorrect .explanation-result {
  color: var(--red);
}

.explanation-text {
  margin: 0;
  color: var(--text);
  font-size: 1.02rem;
  line-height: 1.8;
}

/* Sits below the primary "Next" button — optional, so it's set apart
   rather than competing with it. */
.confidence-optional {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  animation: panel-in 220ms var(--ease-out) 40ms both;
}

.confidence-heading {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 var(--space-2);
}

.confidence-row {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}

/* Modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 19, 17, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  z-index: 100;
  animation: overlay-in 150ms var(--ease-out);
}

.modal-overlay-closing {
  animation: overlay-out 140ms var(--ease-out) forwards;
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes overlay-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.modal-dialog {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: var(--space-5);
  max-width: 420px;
  width: 100%;
  animation: modal-in 200ms var(--ease-out);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-title {
  margin-bottom: var(--space-2);
}

.modal-message {
  color: var(--text-dim);
  margin-bottom: var(--space-4);
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
}

.modal-actions .btn {
  width: auto;
  flex: 1;
}

/* Summary screen */

.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
}

.summary-cert {
  color: var(--text-dim);
  margin: 0;
}

.score-block {
  text-align: center;
  padding: var(--space-6) 0;
  margin: var(--space-5) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.score-value {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: clamp(3.25rem, 2.5rem + 3vw, 4.5rem);
  line-height: 1;
  color: var(--text);
}

.score-detail {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.domain-breakdown {
  margin-top: var(--space-5);
}

.domain-breakdown h3 {
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: var(--space-3);
}

.domain-row {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.domain-row:last-child {
  border-bottom: none;
}

.domain-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
}

.domain-name {
  font-weight: 500;
}

.domain-row .domain-missed {
  color: var(--red);
  font-size: 0.85rem;
  white-space: nowrap;
}

.domain-row .domain-clean {
  color: var(--accent);
  font-size: 0.85rem;
  white-space: nowrap;
}

.domain-bar-track {
  height: 2px;
  background: var(--border);
  display: flex;
}

.domain-bar-correct {
  height: 100%;
  background: var(--accent);
  transition: width 400ms var(--ease-out);
}

.domain-bar-missed {
  height: 100%;
  background: var(--red);
  transition: width 400ms var(--ease-out);
}

.perfect-note {
  text-align: center;
  color: var(--accent);
  margin-top: var(--space-3);
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

@media (min-width: 640px) {
  .summary-actions {
    flex-direction: row;
  }

  .summary-actions .btn {
    flex: 0 0 auto;
  }
}
