:root {
  color-scheme: light;
  --bg: #f4efe7;
  --bg-accent: #e6dccf;
  --card: rgba(255, 251, 246, 0.92);
  --card-strong: #fffaf3;
  --text: #1f1c19;
  --muted: #685f57;
  --primary: #9d3c22;
  --primary-dark: #6e2612;
  --success: #1d6b49;
  --danger: #a1262d;
  --border: rgba(63, 43, 30, 0.12);
  --shadow: 0 18px 45px rgba(79, 52, 33, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(157, 60, 34, 0.14), transparent 30%),
    radial-gradient(circle at bottom right, rgba(35, 93, 124, 0.16), transparent 28%),
    linear-gradient(145deg, var(--bg), #f9f5ef 48%, var(--bg-accent));
}

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

.hero {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.page-shell.view-setup .hero,
.page-shell.view-auth .hero,
.page-shell.view-results .hero,
.page-shell.view-history .hero {
  grid-template-columns: 1fr;
}

.page-shell.view-auth .hero {
  margin-bottom: 8px;
}

.page-shell.view-auth .hero-copy {
  display: none;
}

.page-shell.view-setup h1,
.page-shell.view-auth h1,
.page-shell.view-results h1,
.page-shell.view-history h1 {
  max-width: none;
}

.hero-copy,
.exam-panel,
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.hero-copy {
  padding: 24px 26px;
}

.eyebrow,
.section-kicker,
.panel-label,
.result-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

h1,
h2,
h3 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 2.2vw, 2.55rem);
  line-height: 0.98;
  margin-top: 10px;
  max-width: 12ch;
}

.hero-text {
  max-width: 48ch;
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 12px 0 0;
}

.exam-panel {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

.timer-card,
.progress-card {
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--card-strong);
  border: 1px solid var(--border);
}

#timer,
#progress-value,
#score-value,
#correct-value,
#time-used {
  display: block;
  font-size: clamp(1.35rem, 2.2vw, 2rem);
  margin-top: 6px;
}

.progress-bar {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: #ece1d5;
  overflow: hidden;
}

#progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #c66331, #9d3c22);
  transition: width 180ms ease;
}

main {
  display: grid;
  gap: 24px;
}

.app-view {
  display: grid;
  gap: 24px;
}

.auth-card {
  width: min(520px, 100%);
  margin: 0 auto;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
}

.auth-field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(80, 51, 34, 0.15);
  background: #fffdfa;
  font: inherit;
  color: var(--text);
}

.auth-error {
  margin: 0;
  color: var(--danger);
}

.auth-actions {
  justify-content: flex-end;
  margin-top: 4px;
}

.card {
  padding: 28px;
}

.intro-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 18px;
}

.compact-card {
  padding: 20px 22px;
}

#view-setup .compact-card {
  display: flex;
  flex-direction: column;
}

.section-heading {
  margin-bottom: 22px;
}

.section-heading h2 {
  margin-top: 8px;
  font-size: clamp(1.35rem, 1.8vw, 1.8rem);
}

.compact-heading {
  margin-bottom: 14px;
}

.compact-heading h2 {
  margin-top: 6px;
  font-size: clamp(1.1rem, 1.55vw, 1.4rem);
}

.generation-note {
  color: var(--muted);
}

.generation-note {
  margin: 18px 0 0;
  line-height: 1.6;
}

.compact-note {
  margin-top: 12px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.selection-note {
  margin: 10px 0 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted);
}

.file-picker {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid rgba(80, 51, 34, 0.15);
  background: var(--card-strong);
  font-weight: 700;
  color: var(--primary-dark);
  cursor: pointer;
}

.file-picker input {
  font: inherit;
  color: var(--muted);
}

.mode-switch {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.difficulty-picker {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.compact-picker {
  margin-top: 14px;
  padding-top: 14px;
}

.picker-label {
  display: inline-block;
  margin-bottom: 12px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.mode-button {
  border: 1px solid rgba(80, 51, 34, 0.15);
  background: #fffaf3;
  color: var(--text);
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}

.mode-button.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff9f4;
}

.hero-submit {
  align-self: stretch;
  min-height: 100%;
}

.history-details {
  margin-top: 14px;
  border-top: 1px solid rgba(80, 51, 34, 0.08);
  padding-top: 12px;
}

.history-details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--primary-dark);
}

.compact-history-list {
  margin-top: 12px;
  margin-bottom: 0;
}

.compact-actions {
  margin-top: 14px;
}

#view-setup .compact-card .compact-actions:last-child {
  margin-top: auto;
  justify-content: flex-end;
  padding-top: 14px;
}

.setup-actions,
.form-actions {
  gap: 12px;
  flex-wrap: wrap;
}

.setup-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.setup-stat {
  padding: 16px 18px;
  border-radius: 18px;
  background: var(--card-strong);
  border: 1px solid var(--border);
}

.setup-stat strong {
  display: block;
  margin-top: 6px;
  font-size: 1.3rem;
}

.question-list {
  display: grid;
  gap: 18px;
}

.lesson-copy-structured {
  display: grid;
  gap: 12px;
}

.lesson-block h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--primary-dark);
}

.lesson-block p {
  margin: 0;
}

.question-card {
  padding: 20px;
  border-radius: 20px;
  background: var(--card-strong);
  border: 1px solid var(--border);
}

.question-card h3 {
  font-size: 1.15rem;
  margin-bottom: 14px;
}

.question-topic {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f1e5d8;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 0 0 12px;
}

.question-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f0dfd0;
  color: var(--primary-dark);
  font-weight: 700;
  margin-right: 10px;
}

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

.option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(80, 51, 34, 0.12);
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.option:hover {
  border-color: rgba(157, 60, 34, 0.4);
  transform: translateY(-1px);
}

.option input {
  margin-top: 3px;
}

.study-feedback-copy {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(80, 51, 34, 0.12);
  background: #fff8f1;
}

.study-feedback-copy.correct {
  border-color: rgba(29, 107, 73, 0.3);
  background: rgba(29, 107, 73, 0.08);
}

.study-feedback-copy.incorrect {
  border-color: rgba(157, 60, 34, 0.26);
  background: rgba(157, 60, 34, 0.08);
}

.study-feedback-copy p,
.study-feedback-hint {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.6;
}

.study-feedback-copy p:last-child,
.study-feedback-hint:last-child {
  margin-bottom: 0;
}

textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid rgba(80, 51, 34, 0.15);
  background: #fffdfa;
  font: inherit;
  color: var(--text);
  line-height: 1.6;
}

textarea:focus,
input:focus {
  outline: 2px solid rgba(157, 60, 34, 0.18);
  outline-offset: 2px;
}

.sample-answer {
  margin-top: 14px;
  border: 1px solid rgba(80, 51, 34, 0.12);
  border-radius: 16px;
  background: #fcf4ea;
  padding: 12px 14px;
}

.sample-answer summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--primary-dark);
}

.sample-answer p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.lesson-panel {
  margin-top: 14px;
}

.lesson-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.lesson-chip {
  border: 1px solid rgba(80, 51, 34, 0.15);
  background: #fffaf3;
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.lesson-chip:hover {
  background: rgba(157, 60, 34, 0.08);
  transform: translateY(-1px);
}

.lesson-copy p {
  margin: 12px 0 0;
}

.lesson-copy-structured {
  display: grid;
  gap: 12px;
}

.lesson-block h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--primary-dark);
}

.lesson-block p {
  margin: 0;
}

.sample-outline {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.evaluation-grid li::marker {
  color: var(--primary-dark);
}

.review-sample-answer {
  margin-top: 12px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 24px;
}

.submit-button,
.secondary-button {
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
}

.submit-button {
  color: #fff9f4;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

.secondary-button {
  color: var(--primary-dark);
  background: #f3e4d6;
}

.submit-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.results-grid article,
.review-item {
  padding: 18px;
  border-radius: 18px;
  background: var(--card-strong);
  border: 1px solid var(--border);
}

.results-breakdown {
  display: grid;
  gap: 14px;
  margin-bottom: 28px;
}

.breakdown-card {
  padding: 18px;
  border-radius: 18px;
  background: var(--card-strong);
  border: 1px solid var(--border);
}

.breakdown-card h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.breakdown-list {
  display: grid;
  gap: 10px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0;
  border-top: 1px solid rgba(80, 51, 34, 0.08);
  color: var(--muted);
}

.breakdown-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.breakdown-row strong {
  color: var(--text);
}

.history-card {
  padding: 18px;
  border-radius: 18px;
  background: var(--card-strong);
  border: 1px solid var(--border);
}

.history-card h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.history-meta {
  color: var(--muted);
  line-height: 1.6;
}

.review-block {
  display: grid;
  gap: 14px;
}

.review-item.correct {
  border-color: rgba(29, 107, 73, 0.35);
}

.review-item.incorrect {
  border-color: rgba(161, 38, 45, 0.3);
}

.review-item h3 {
  margin-bottom: 10px;
  font-size: 1.05rem;
}

.review-item p {
  margin: 6px 0;
  color: var(--muted);
}

.lesson-modal {
  width: min(760px, calc(100% - 24px));
  border: none;
  padding: 0;
  background: transparent;
}

.lesson-modal::backdrop {
  background: rgba(24, 17, 12, 0.45);
  backdrop-filter: blur(4px);
}

.lesson-modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.lesson-modal-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.lesson-modal-body {
  max-height: min(70vh, 720px);
  overflow: auto;
  padding-right: 6px;
}

.hidden {
  display: none;
}

@media (max-width: 860px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .exam-panel,
  .intro-grid,
  .setup-stats {
    grid-template-columns: 1fr;
  }

  .compact-card {
    padding: 18px;
  }

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

@media (prefers-reduced-motion: no-preference) {
  .card,
  .hero-copy,
  .exam-panel {
    animation: rise-in 500ms ease both;
  }

  .question-card {
    animation: rise-in 420ms ease both;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
