:root {
  --bg: #f4f1ec;
  --surface: #fffdf9;
  --text: #1a1a1f;
  --muted: #5c5c66;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --border: #e4dfd6;
  --selected: #1e40af;
  --shadow: 0 12px 40px rgba(26, 26, 31, 0.08);
  --radius: 14px;
  --font-sans: "DM Sans", system-ui, sans-serif;
  --font-serif: "Literata", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, #dbeafe 0%, transparent 55%),
    var(--bg);
  line-height: 1.55;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem 1.5rem;
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  padding-bottom: 0.75rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.control-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.set-select {
  flex: 1;
  min-width: 10rem;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.btn-toggle-answer {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.btn-toggle-answer:hover {
  border-color: #86efac;
  color: #047857;
}

.btn-toggle-answer.active {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #047857;
}

.btn-ai {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border: 1px solid #c4b5fd;
  border-radius: 8px;
  background: #f5f3ff;
  color: #5b21b6;
  cursor: pointer;
  white-space: nowrap;
}

.btn-ai:hover {
  background: #ede9fe;
  border-color: #a78bfa;
}

.badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  white-space: nowrap;
}

.progress-track {
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #1d4ed8);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.question-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
  max-height: 5.5rem;
  overflow-y: auto;
  padding-bottom: 0.15rem;
}

.nav-dot {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-dot:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.nav-dot.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.nav-dot.answered {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #047857;
}

.main {
  flex: 1;
  padding: 1rem 0;
}

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

.question-meta {
  margin: 0 0 1rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.passage {
  font-family: var(--font-serif);
  font-size: 1.02rem;
  line-height: 1.75;
  color: #2d2d35;
  background: #f8f6f2;
  border-left: 3px solid #93c5fd;
  padding: 1rem 1.1rem;
  border-radius: 0 10px 10px 0;
  margin-bottom: 1.35rem;
}

.passage-p {
  margin: 0 0 0.85em;
  text-indent: 1.5em;
}
.passage-p:last-child {
  margin-bottom: 0;
}
.passage-p.muted {
  color: var(--muted);
  text-indent: 0;
}

.question-text {
  margin: 0 0 1.1rem;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.45;
}

.options {
  border: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: white;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  text-align: left;
}

.option:hover {
  border-color: #93c5fd;
  background: #f8fafc;
}

.option.selected {
  border-color: var(--selected);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--selected);
}

.option-letter {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  background: #f1f5f9;
  border-radius: 6px;
}

.option.selected .option-letter {
  background: var(--accent);
  color: white;
}

.option.correct {
  border-color: #22c55e;
  background: #f0fdf4;
}

.option.correct .option-letter {
  background: #16a34a;
  color: white;
}

.option.wrong {
  border-color: #f87171;
  background: #fef2f2;
}

.option.wrong .option-letter {
  background: #dc2626;
  color: white;
}

.answer-panel {
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  border-radius: 10px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.answer-panel.hidden {
  display: none;
}

.answer-label {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #047857;
}

.answer-value {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #14532d;
}

.answer-value.muted {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--muted);
}

.option-text {
  font-size: 0.98rem;
  padding-top: 0.1rem;
}

.footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
  align-items: center;
  padding-top: 0.5rem;
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary {
  background: var(--accent);
  color: white;
  justify-self: end;
}

.btn-primary:hover:not(:disabled) {
  background: #1e40af;
}

.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  justify-self: start;
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  justify-self: center;
}

.btn-ghost:hover {
  color: var(--text);
}

@media (max-width: 520px) {
  .footer {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .btn-ghost {
    grid-column: 1 / -1;
    order: 3;
  }

  .btn-primary {
    justify-self: stretch;
  }

  .btn-secondary {
    justify-self: stretch;
  }
}

/* French AI panel */
.ai-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 31, 0.35);
  z-index: 100;
}

.ai-backdrop.hidden,
.ai-panel.hidden {
  display: none;
}

.ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(400px, 92vw);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(26, 26, 31, 0.12);
  z-index: 101;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.1rem 1.25rem;
  overflow: hidden;
}

.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.ai-panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.ai-panel-actions {
  display: flex;
  gap: 0.35rem;
}

.btn-ai-icon {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-ai-icon:hover {
  border-color: #a78bfa;
}

.ai-settings {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
  padding: 0.85rem;
  background: #f8fafc;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.ai-settings.hidden {
  display: none;
}

.ai-settings label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.ai-settings input {
  font: inherit;
  font-size: 0.88rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.ai-settings-hint,
.ai-hint-top {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.ai-hint-top {
  margin-bottom: 0.5rem;
}

.ai-input {
  width: 100%;
  font: inherit;
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 1.55;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: vertical;
  margin-bottom: 0.55rem;
}

.btn-block {
  width: 100%;
  justify-self: stretch;
}

.ai-status {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.2em;
}

.ai-result {
  flex: 1;
  overflow-y: auto;
  margin-top: 0.65rem;
  padding: 0.85rem;
  background: #faf9f7;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.ai-result:empty {
  display: none;
}

.ai-h3 {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.92rem;
  color: #5b21b6;
}

.ai-h3:first-child {
  margin-top: 0;
}

.ai-h4 {
  margin: 0.5rem 0 0.25rem;
  font-size: 0.85rem;
}

.ai-p {
  margin: 0.35rem 0;
}

.ai-ul {
  margin: 0.35rem 0 0.5rem;
  padding-left: 1.1rem;
}

.ai-li {
  margin: 0.2rem 0;
}

.ai-loading {
  color: var(--muted);
  font-style: italic;
}

.ai-error {
  color: #b91c1c;
  font-weight: 600;
}

.ai-hint code {
  font-size: 0.82em;
  background: #f1f5f9;
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.passage::selection,
.question-text::selection,
.option-text::selection {
  background: #ddd6fe;
}

.note-panel {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}

.note-panel.hidden {
  display: none;
}

.note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.note-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.note-status {
  font-size: 0.78rem;
  color: #047857;
  min-height: 1em;
  transition: opacity 0.2s ease;
}

.note-input {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.55;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  min-height: 5.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.note-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.top-nav { display: flex; gap: 8px; margin-left: 12px; flex: 1; }
.top-nav-link { padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); text-decoration: none; border: 1px solid var(--border); background: var(--surface); transition: all .15s ease; }
.top-nav-link:hover { color: var(--text); border-color: var(--accent); }
.top-nav-link.active { background: var(--accent); color: #fff; border-color: var(--accent); }
