/* LingoLeap — one hand-written stylesheet, no build step, no framework.
   Layout is flex/grid, colours are custom properties, dark mode follows the OS. */

:root {
  --bg: #f4efe3;
  --surface: #fffdf8;
  --surface-sunken: #ece4d2;
  --border: #e8e0cd;
  --text: #2a2621;
  --text-muted: #6e6555;
  --accent: #2f8a76;
  --accent-contrast: #ffffff;
  --accent-soft: #e2efe9;
  --correct: #2f8a76;
  --correct-soft: #e2efe9;
  --wrong: #b8442f;
  --wrong-soft: #f7e2da;
  --typo: #a87a22;
  --typo-soft: #f3e9cf;
  --focus: #2f8a76;
  --memory-new: color-mix(in srgb, var(--accent-soft) 55%, var(--accent));
  --memory-learning: color-mix(in srgb, var(--accent-soft) 35%, var(--accent));
  --memory-familiar: color-mix(in srgb, var(--accent-soft) 15%, var(--accent));
  --memory-strong: var(--accent);

  /* Flat lip instead of a soft shadow -- a keycap-style ledge that visually presses
     down on :active. Hand-authored per mode (not derived from --border/--accent via
     color-mix) because the blend ratio that reads right differs sharply between
     light and dark, not just the base colour. */
  --lip: #d9cdb2;
  --accent-lip: #23685a;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 20px 40px -12px rgb(30 28 26 / 20%), 0 8px 16px rgb(30 28 26 / 10%);
  --measure: 62ch;
  --font: ui-rounded, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-reading: ui-serif, Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18140f;
    --surface: #221d16;
    --surface-sunken: #1c1712;
    --border: #362f22;
    --text: #ece5d6;
    --text-muted: #a89b83;
    --accent: #54ab92;
    /* Near-black, not white: #54ab92 against white text is ~2.9:1 (fails AA); against
       near-black it's ~7.3:1. Keep the flip. */
    --accent-contrast: #0f2019;
    --accent-soft: #22352c;
    --correct: #54ab92;
    --correct-soft: #22352c;
    --wrong: #e2897a;
    --wrong-soft: #3a2419;
    --typo: #e0c069;
    --typo-soft: #3a3319;
    --focus: #54ab92;
    --lip: #0f0c07;
    --accent-lip: #1e4337;
    --shadow: 0 20px 40px -12px rgb(0 0 0 / 55%), 0 8px 16px rgb(0 0 0 / 35%);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
}

h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.3rem); margin: 0 0 0.5rem; }
h2 { font-size: 1.2rem; margin: 0 0 0.4rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ---------------------------------------------------------------- chrome */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--text);
  margin-right: auto;
}
.brand span { color: var(--accent); }

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.1rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

.site-nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.site-nav a { color: var(--text-muted); text-decoration: none; font-weight: 500; }
.site-nav a:hover, .site-nav a:focus-visible { color: var(--text); }
.site-nav .button { color: var(--accent-contrast); }
.logout-form { margin: 0; }

.link-button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}
.link-button:hover { color: var(--text); }

@media (max-width: 640px) {
  .nav-toggle { display: block; }
  .site-nav { display: none; width: 100%; flex-direction: column; align-items: flex-start; }
  .site-nav--open { display: flex; }
}

.page {
  flex: 1;
  width: 100%;
  max-width: 68rem;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 2.5rem);
}

.messages { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; gap: 0.5rem; }
.message {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid var(--border);
}

/* ---------------------------------------------------------------- buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--accent-lip);
  transition: box-shadow 100ms ease, transform 100ms ease;
}
.button:hover { filter: brightness(1.05); }
.button:active { box-shadow: 0 1px 0 var(--accent-lip); transform: translateY(2px); }
.button:disabled { opacity: 0.55; cursor: progress; box-shadow: none; }

.button--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 3px 0 var(--lip);
}
.button--ghost:hover { background: var(--surface-sunken); filter: none; }
.button--ghost:active { box-shadow: 0 1px 0 var(--lip); transform: translateY(2px); }

.button--small { padding: 0.35rem 0.75rem; font-size: 0.9rem; box-shadow: 0 2px 0 var(--accent-lip); }
.button--small:active { box-shadow: 0 1px 0 var(--accent-lip); }
.button--large { padding: 0.7rem 1.4rem; font-size: 1.05rem; }

/* ---------------------------------------------------------------- forms */

.form { display: grid; gap: 1rem; max-width: 26rem; }
.field { display: grid; gap: 0.3rem; }
.field label { font-weight: 600; font-size: 0.9rem; }

.field input,
.field select,
.filters input,
.filters select {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.field__help { margin: 0; font-size: 0.82rem; color: var(--text-muted); }
.field__errors, .form__errors {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--wrong);
  font-size: 0.85rem;
}
.field--invalid input, .field--invalid select { border-color: var(--wrong); }
.field--inline { grid-template-columns: auto 1fr; align-items: center; gap: 0.5rem; }

.auth { max-width: 26rem; }
.auth__alt { margin-top: 1.25rem; color: var(--text-muted); font-size: 0.9rem; }

/* ---------------------------------------------------------------- study screen */

.study { max-width: var(--measure); margin: 0 auto; }

.progress { margin-bottom: 1.75rem; }
.progress__bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-sunken);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 240ms ease;
}
.progress__label {
  display: flex;
  justify-content: space-between;
  margin: 0.4rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.card, .feedback, .complete, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 4px solid var(--lip);
  border-radius: var(--radius);
  padding: clamp(1.1rem, 3vw, 1.9rem);
}

.badge {
  display: inline-block;
  margin: 0 0 0.75rem;
  padding: 0.15rem 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* -------------------------------------------------------------- memory meter */

.memory-meter { display: block; margin: 0 0 0.75rem; }
.memory-meter__summary {
  display: inline-flex;
  width: fit-content;
  padding: 0.2rem;
  margin: -0.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  list-style: none;
}
.memory-meter__summary::-webkit-details-marker { display: none; }
.memory-meter__summary:hover, .memory-meter__summary:focus-visible { background: var(--surface-sunken); }

.memory { display: inline-flex; gap: 0.2rem; }
.memory__dash { width: 1.1rem; height: 0.3rem; border-radius: 999px; background: var(--border); }
.memory--new .memory__dash:nth-child(1) { background: var(--memory-new); }
.memory--learning .memory__dash:nth-child(-n+3) { background: var(--memory-learning); }
.memory--familiar .memory__dash:nth-child(-n+4) { background: var(--memory-familiar); }
.memory--strong .memory__dash { background: var(--memory-strong); }

.memory-meter__legend {
  max-width: 24rem;
  margin-top: 0.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}
.memory-meter__lead {
  margin: 0 0 0.6rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.memory-meter__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.memory-meter__list li { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; }

.sentence {
  font-family: var(--font-reading);
  font-size: clamp(1.2rem, 1.05rem + 0.9vw, 1.55rem);
  font-weight: 600;
  line-height: 1.85;
  margin: 0 0 0.6rem;
}

.gap { display: inline-block; }

.gap__input {
  /* Sized for the hidden word, but free to grow: a guess can be longer than the
     answer, and `ch` under-measures wide letters in a proportional serif. Browsers
     without `field-sizing` fall back to the `size` attribute plus this min-width. */
  field-sizing: content;
  min-width: max(6ch, calc(var(--gap-width, 6ch) * 1.15 + 1.5ch));
  max-width: 100%;
  padding: 0.1rem 0.4rem;
  border: 0;
  border-bottom: 3px solid var(--accent);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--accent-soft);
  color: var(--text);
  font: inherit;
  font-family: var(--font-reading);
  text-align: center;
}
.gap__input:focus { outline: none; background: var(--surface-sunken); border-bottom-width: 3px; }
.gap__input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.sentence-translation {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0 0 1.25rem;
}

.meaning {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  margin-bottom: 1.25rem;
}
.meaning__title {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.meaning__translations { margin: 0 0 0.2rem; font-size: 1.05rem; font-weight: 600; }
.meaning__gloss { margin: 0 0 0.2rem; font-size: 0.9rem; color: var(--text-muted); }
.meaning__pos { margin: 0; font-size: 0.8rem; font-style: italic; color: var(--text-muted); }
.meaning__tense { margin: 0; font-size: 0.8rem; font-style: italic; color: var(--text-muted); }

.card__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.card__note { margin: 0.8rem 0 0; font-size: 0.85rem; color: var(--text-muted); }

/* ---------------------------------------------------------------- feedback */

.feedback { margin-bottom: 1rem; border-left: 4px solid var(--border); }
.feedback--correct { border-left-color: var(--correct); background: var(--correct-soft); }
.feedback--typo { border-left-color: var(--typo); background: var(--typo-soft); }
.feedback--wrong { border-left-color: var(--wrong); background: var(--wrong-soft); }
/* Given up, not guessed wrong: still a miss for scheduling, but framed neutrally
   rather than as a red "you failed" -- the learner asked to be shown the word. */
.feedback--revealed { border-left-color: var(--border); background: var(--surface-sunken); }

.feedback__verdict { font-weight: 700; margin: 0 0 0.75rem; }
.feedback--correct .feedback__verdict { color: var(--correct); }
.feedback--typo .feedback__verdict { color: var(--typo); }
.feedback--wrong .feedback__verdict { color: var(--wrong); }
.feedback--revealed .feedback__verdict { color: var(--text-muted); }

.answer {
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.05em 0.35em;
  border-radius: 4px;
  font-weight: 700;
}

.word-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem 1.25rem;
  margin: 1.1rem 0 0;
}
.word-facts dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.word-facts dd { margin: 0.1rem 0 0; font-weight: 600; }
.given-answer { text-decoration: line-through; color: var(--text-muted); }
.pos { font-weight: 400; font-style: italic; color: var(--text-muted); font-size: 0.85em; }

.continue-hint { margin: 1.1rem 0 0; font-size: 0.88rem; color: var(--text-muted); }
kbd {
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
}

.complete { text-align: center; }
.complete__title { margin-bottom: 0.4rem; }
.complete__body { color: var(--text-muted); }
.complete__actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; margin-top: 1.2rem; }

/* The goal-reached-with-more-due state only: a real popup (see learn.js), not the
   plain page section the other two completion states render as. */
dialog.complete {
  margin: auto;
  width: calc(100% - 2rem);
  max-width: 26rem;
  /* Overlay, not a card on the page -- a real shadow instead of the shared rule's
     lip, and cancel the lip it would otherwise inherit. */
  border-bottom: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow);
}
dialog.complete::backdrop { background: rgb(0 0 0 / 45%); }

/* ---------------------------------------------------------------- landing */

.hero { max-width: var(--measure); margin: clamp(1rem, 5vw, 3rem) auto; text-align: center; }
.hero__lead { font-size: 1.1rem; color: var(--text-muted); }
.hero__actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1.25rem;
  margin-top: clamp(2rem, 6vw, 4rem);
}
.feature {
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.feature p { margin: 0; color: var(--text-muted); }

/* ---------------------------------------------------------------- dashboard */

.dashboard__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.dashboard__header h1 { margin: 0; }

.stats {
  list-style: none;
  margin: 0 0 1.75rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 1rem;
}
.stat {
  display: grid;
  gap: 0.15rem;
  padding: 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.stat__value { font-size: 2rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stat__label { font-size: 0.85rem; color: var(--text-muted); }

.panel { margin-bottom: 1.25rem; }
.panel__title { margin-bottom: 0.2rem; }
.panel__lead { color: var(--text-muted); font-size: 0.9rem; }

.forecast {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.5rem;
  margin: 1rem 0 0;
  padding: 0;
}
.forecast__day { display: grid; justify-items: center; gap: 0.3rem; }
.forecast__bar-track {
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: 5rem;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.forecast__bar { width: 100%; min-height: 2px; background: var(--accent); border-radius: var(--radius-sm); }
.forecast__count { font-weight: 700; font-variant-numeric: tabular-nums; }
.forecast__label { font-size: 0.78rem; color: var(--text-muted); }

/* ---------------------------------------------------------------- vocabulary */

.vocabulary__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.vocabulary__count { color: var(--text-muted); }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.75rem;
  margin: 1rem 0 1.5rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* Wide content scrolls inside its own box; the page itself never scrolls sideways. */
.table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.table th, .table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.table tbody tr:hover { background: var(--surface-sunken); }

/* Named ".pill" but drawn as a rounded rectangle, not a capsule -- a status label
   reads as a small tile here, not a pill; renaming the class would mean touching
   the templates that select it, which this reskin deliberately leaves alone. */
.pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-size: 0.78rem;
  font-weight: 700;
}
.pill--review { background: var(--correct-soft); color: var(--correct); }
.pill--relearning { background: var(--wrong-soft); color: var(--wrong); }
.pill--learning { background: var(--accent-soft); color: var(--accent); }

.pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1.25rem; }
.pagination__link { text-decoration: none; font-weight: 600; }
.pagination__link--disabled { color: var(--text-muted); font-weight: 400; }
.pagination__status { color: var(--text-muted); font-size: 0.9rem; }

.empty { color: var(--text-muted); }

/* ---------------------------------------------------------------- statistics */

.statistics__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.statistics__header h1 { margin: 0; }
.statistics__lead { color: var(--text-muted); font-size: 0.9rem; }
.statistics__note { margin-top: 0.5rem; font-size: 0.82rem; color: var(--text-muted); }
.statistics__totals { margin-bottom: 0.75rem; }

/* A native <dialog>: showModal() gives the centering and the Escape key for free,
   ::backdrop the dimming, and the close button works through a plain
   <form method="dialog"> with no JS at all. */
.day-detail {
  margin: auto;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  color: var(--text);
  width: calc(100% - 2rem);
  max-width: 22rem;
  box-shadow: var(--shadow);
}
.day-detail::backdrop { background: rgb(0 0 0 / 45%); }
.day-detail__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.day-detail__date { margin: 0; font-size: 1rem; }
.day-detail__close {
  border: none;
  background: none;
  padding: 0.25rem;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}
.day-detail__close:hover { color: var(--text); }

.year-nav { display: flex; align-items: center; gap: 0.75rem; font-weight: 600; }
.year-nav__link { text-decoration: none; }
.year-nav__link--disabled { color: var(--text-muted); font-weight: 400; }
.year-nav__current { font-variant-numeric: tabular-nums; }

/* One checkmark box. Shared by the dashboard's current-week strip and every week row
   of the year calendar, via components/goal_week.html -- a green box always means the
   same thing wherever it is drawn. */
.goal-week {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
  margin: 0 0 3px;
  padding: 0;
  max-width: 18rem;
}
.goal-day {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: none;
}
.goal-day--before, .goal-day--future { background: var(--surface-sunken); border-color: transparent; }
.goal-day--outside { background: none; border-color: transparent; }
.goal-day--today { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Goal-relative heat, like GitHub's contribution graph -- the more cards reviewed
   that day, the darker the cell. Level 0 has no rule and keeps the plain border
   above; BEFORE/FUTURE/OUTSIDE days always compute level 0, so there is nothing
   here to fight their own background. */
.goal-day--level-1 { background: var(--accent-soft); border-color: var(--accent); }
.goal-day--level-2 { background: color-mix(in srgb, var(--accent-soft) 35%, var(--accent)); border-color: var(--accent); }
.goal-day--level-3 { background: color-mix(in srgb, var(--accent-soft) 10%, var(--accent)); border-color: var(--accent); }
.goal-day--level-4 { background: var(--accent); border-color: var(--accent); }

.goal-day[data-date] { cursor: pointer; }
.goal-day[data-date]:hover, .goal-day[data-date]:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

.calendar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0 2rem;
}
.calendar__month-name {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

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