:root {
  --maroon: #7a1f2b;
  --maroon-dark: #5c1620;
  --gold: #b8892b;
  --cream: #faf6ee;
  --paper: #ffffff;
  --ink: #2a2422;
  --ink-soft: #5a534d;
  --border: #e3dccc;
  --good: #2e7d4f;
  --bad: #b3382c;
  --shadow: 0 2px 8px rgba(60, 40, 20, 0.08);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

.latin {
  font-family: Georgia, "Times New Roman", serif;
}

a { color: var(--maroon); }

header.site-header {
  background: linear-gradient(135deg, var(--maroon), var(--maroon-dark));
  color: #fff;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: var(--shadow);
}

header.site-header h1 {
  margin: 0;
  font-size: 1.3rem;
  font-family: Georgia, serif;
  letter-spacing: 0.02em;
}

header.site-header h1 a { color: #fff; text-decoration: none; }

nav.site-nav { display: flex; gap: 8px; flex-wrap: wrap; }

nav.site-nav a {
  color: #fff;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
  background: rgba(255,255,255,0.08);
  transition: background 0.15s;
}

nav.site-nav a:hover, nav.site-nav a.active {
  background: rgba(255,255,255,0.22);
}

/* Level 1 / Level 2 textbook switch in the header */
.book-switch {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
}
.book-switch-label { font-size: 0.82rem; opacity: 0.85; padding: 0 6px 0 8px; }
.book-switch button {
  background: transparent;
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 0.88rem;
}
.book-switch button:hover { background: rgba(255,255,255,0.16); }
.book-switch button[aria-pressed="true"] { background: #fff; color: var(--maroon-dark); font-weight: 600; }

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}

.card h2 { margin-top: 0; font-family: Georgia, serif; color: var(--maroon-dark); }

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-top: 20px;
}

.section-tile {
  display: block;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  text-decoration: none;
  color: var(--ink);
  transition: transform 0.12s, box-shadow 0.12s;
}

.section-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(60,40,20,0.14); }

.section-tile .icon { font-size: 2rem; }
.section-tile h3 { margin: 10px 0 6px; color: var(--maroon-dark); font-family: Georgia, serif; }
.section-tile p { margin: 0; color: var(--ink-soft); font-size: 0.94rem; }

button, .btn {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--maroon);
  background: var(--maroon);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button:hover, .btn:hover { background: var(--maroon-dark); }
button:active, .btn:active { transform: scale(0.98); }

button.secondary, .btn.secondary {
  background: transparent;
  color: var(--maroon);
}
button.secondary:hover, .btn.secondary:hover { background: rgba(122,31,43,0.08); }

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

select, input[type="text"] {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
}

.chapter-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.chapter-chip {
  border: 1px solid var(--border);
  background: #fff;
  padding: 7px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
}

.chapter-chip.selected {
  background: var(--maroon);
  color: #fff;
  border-color: var(--maroon);
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  background: var(--border);
  color: var(--ink-soft);
}

footer.site-footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 30px 20px 50px;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 20px;
}

/* ---- Flashcards ---- */
.flashcard-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.flashcard {
  width: 100%;
  max-width: 480px;
  height: 280px;
  perspective: 1200px;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  background: var(--paper);
}

.flashcard-face.back { transform: rotateY(180deg); background: #fff7ea; }

.flashcard-face .word { font-size: 2rem; font-family: Georgia, serif; color: var(--maroon-dark); }
.flashcard-face .word.compact { font-size: 1.5rem; max-width: 90%; }
.flashcard-face .word.compact-sm { font-size: 1.15rem; max-width: 95%; line-height: 1.3; }
.flashcard-face .card-emoji { font-size: 3rem; line-height: 1; margin-bottom: 6px; }
.flashcard-face .sub { color: var(--ink-soft); margin-top: 10px; font-size: 1rem; }
.flashcard-face .hint { position: absolute; bottom: 14px; color: var(--ink-soft); font-size: 0.78rem; }

.flashcard-controls { display: flex; gap: 10px; align-items: center; }
.progress-text { color: var(--ink-soft); font-size: 0.9rem; }

.mode-toggle { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.mode-toggle button { background: transparent; color: var(--maroon); }
.mode-toggle button.active { background: var(--maroon); color: #fff; }

/* ---- Learn mode (MC) ---- */
.mc-prompt {
  text-align: center;
  font-size: 1.6rem;
  font-family: Georgia, serif;
  color: var(--maroon-dark);
  margin: 10px 0 22px;
}
.mc-sub { text-align: center; color: var(--ink-soft); margin-top: -14px; margin-bottom: 20px; }
/* Derivative Practice's hint after a wrong answer: the Latin word's meaning,
   under the prompt, and each choice's definition */
.mc-meaning { text-align: center; color: var(--ink-soft); margin-top: -14px; margin-bottom: 22px; }
.mc-option .mc-word { display: block; }
.mc-option .mc-definition { display: block; margin-top: 4px; font-size: 0.85rem; color: var(--ink-soft); }

.mc-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 560px) { .mc-options { grid-template-columns: 1fr; } }

.mc-option {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-size: 1rem;
}
/* Overrides the general button:hover fill, which hid the option's text. */
.mc-option:hover { border-color: var(--maroon); background: #fff; }
.mc-option.correct { background: #e5f4ea; border-color: var(--good); }
.mc-option.incorrect { background: #fbe8e6; border-color: var(--bad); }
.mc-option:disabled { cursor: default; opacity: 1; }
.mc-option:disabled:not(.correct):not(.incorrect) { opacity: 0.5; }

.stat-row { display: flex; gap: 20px; justify-content: center; margin: 14px 0; flex-wrap: wrap; }
.stat { text-align: center; }
.stat .num { font-size: 1.5rem; font-weight: 600; color: var(--maroon-dark); }
.stat .label { font-size: 0.8rem; color: var(--ink-soft); }

/* ---- Grammar charts ---- */
table.chart {
  border-collapse: collapse;
  width: 100%;
  margin-top: 14px;
}
table.chart th, table.chart td {
  border: 1px solid var(--border);
  padding: 6px;
  text-align: center;
}
table.chart th {
  background: #f5efe0;
  color: var(--maroon-dark);
  font-family: Georgia, serif;
}
table.chart td input {
  width: 100%;
  min-width: 70px;
  border: none;
  background: transparent;
  text-align: center;
  font-family: Georgia, serif;
  font-size: 0.95rem;
  padding: 6px 4px;
  border-radius: 5px;
}
table.chart td input:focus { outline: 2px solid var(--gold); background: #fffdf6; }
table.chart td.correct input { background: #e5f4ea; }
table.chart td.incorrect input { background: #fbe8e6; }
table.chart td.case-label { font-weight: 600; background: #faf6ee; }

/* Translating a correctly conjugated verb chart */
.translate-offer { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; color: var(--good); font-weight: 600; }
.translate-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.translate-latin { font-weight: 700; color: var(--maroon-dark); min-width: 5.5em; text-align: left; overflow-wrap: anywhere; }
table.chart td .translate-cell input { flex: 1 1 8em; text-align: left; border-bottom: 1px dashed var(--border); }
table.chart.translate-chart .label-short { display: none; }
@media (max-width: 560px) {
  .translate-latin { font-size: 0.9rem; }
  table.chart.translate-chart td { padding: 5px 4px; }
  table.chart.translate-chart .label-full { display: none; }
  table.chart.translate-chart .label-short { display: inline; }
}

.chart-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
/* A select sizes itself to its longest option (e.g. full principal parts
   plus meaning); keep it inside the card on narrow screens. */
.chart-toolbar select { max-width: 100%; min-width: 0; }

/* ---- Translation section ---- */
.sentence-list { display: flex; flex-direction: column; gap: 10px; }
.sentence-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.sentence-item:hover { border-color: var(--maroon); }
.sentence-item .latin { font-size: 1.05rem; }
.sentence-item .status { font-size: 0.8rem; }
.status.done { color: var(--good); }

.analysis-word {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: top;
  margin: 6px 4px;
  gap: 4px;
}
.analysis-word .word-text {
  font-family: Georgia, serif;
  font-size: 1.15rem;
  padding: 2px 4px;
}
.analysis-word select {
  font-size: 0.72rem;
  padding: 3px 4px;
  max-width: 128px;
}
/* Wraps when a verb has four fields (person / number / tense / mood). */
.analysis-word .field-row { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; max-width: 280px; }
.analysis-sentence {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 18px 10px;
  background: #fffdf6;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
}
.plain-word {
  font-family: Georgia, serif;
  font-size: 1.15rem;
  margin: 6px 4px;
  color: var(--ink-soft);
  align-self: center;
}
.analysis-word.checked-correct .word-text { background: #e5f4ea; border-radius: 5px; }
.analysis-word.checked-incorrect .word-text { background: #fbe8e6; border-radius: 5px; }
select.field-bad { border-color: var(--bad); background: #fbe8e6; }
select.field-good { border-color: var(--good); background: #e5f4ea; }

.legend { font-size: 0.85rem; color: var(--ink-soft); margin-top: 8px; }

.punct-inline {
  font-family: Georgia, serif;
  font-size: 1.15rem;
  margin: 6px 2px 6px -3px;
  color: var(--ink-soft);
  align-self: center;
}

.score-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: #fff7ea;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 14px;
}
.score-banner.all-correct { background: #e5f4ea; border-color: var(--good); }

.translation-box textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 8px 0;
  resize: vertical;
  background: #fff;
  color: var(--ink);
}

.model-translation {
  background: #fff7ea;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 10px 0;
}
