:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #f0ece3;
  --text: #22201c;
  --muted: #6e685e;
  --faint: #9b9488;
  --border: #e3ddd0;
  --accent: #2a4d80;
  --accent-soft: #e6ecf5;
  --mark: #fbeeb8;
  --gloss: #a89f8d;
  --wrong: #a23b2a;
  --right: #2e6b40;
  --diamond: #3a9fc2;
  --gold: #c4961c;
  --silver: #8c949d;
  --bronze: #ad6d3b;

  --serif: "Literata", Georgia, "Iowan Old Style", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.55 var(--sans);
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-underline-offset: 0.15em; }

button {
  font: 500 0.92rem/1.2 var(--sans);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 1.05rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #213e68; }
button.link { border: none; background: none; color: var(--muted); padding: 0.25rem 0.4rem; border-radius: 6px; }
button.link:hover { color: var(--text); background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: default; }
input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  max-width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(246, 243, 236, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.75rem;
  padding: 0.8rem 1rem;
  flex-wrap: wrap;
}
.brand {
  font: 600 1.2rem/1 var(--serif);
  font-style: italic;
  text-decoration: none;
  color: var(--text);
}
nav { display: flex; gap: 1.25rem; flex-wrap: wrap; }
nav a { text-decoration: none; color: var(--muted); font-size: 0.92rem; padding: 0.2rem 0; border-bottom: 2px solid transparent; }
nav a:hover { color: var(--text); }
nav a.active { color: var(--text); border-bottom-color: var(--accent); }
.pill {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
}
.pill:empty { display: none; }

main { max-width: 720px; margin: 0 auto; padding: 2.5rem 1rem 5rem; }
main.wide { max-width: 1180px; }

h1 {
  font: 600 2rem/1.2 var(--serif);
  letter-spacing: -0.01em;
  margin: 0 0 0.4rem;
}
h2 {
  font: 600 1.25rem/1.3 var(--serif);
  margin: 2.5rem 0 0.75rem;
}
.lede { color: var(--muted); margin: 0 0 1.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--faint);
}

.status {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  margin: 1rem 0;
  font-size: 0.9rem;
}
.status.error { background: #f8e9e5; color: var(--wrong); }

/* ---------- cards ---------- */

.cards { display: grid; gap: 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem 1.4rem 1.1rem;
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover { box-shadow: 0 8px 28px rgba(60, 45, 20, 0.08); transform: translateY(-1px); }
.card h3 { font: 600 1.3rem/1.3 var(--serif); margin: 0.35rem 0 0.4rem; }
.card h3 a { color: var(--text); text-decoration: none; }
.card h3 a:hover { color: var(--accent); }
.card p { font-family: var(--serif); color: #3d3933; margin: 0 0 0.9rem; line-height: 1.55; }
.meta { font-size: 0.82rem; color: var(--faint); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.1rem 1.3rem;
  margin-top: 1.5rem;
}
.panel-title { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.4rem; }

/* ---------- reading ---------- */

.reader-head { margin-bottom: 1.75rem; }
.reader-head h1 { font-size: 2.2rem; }
.source { font-size: 0.85rem; color: var(--faint); }
.reading {
  font-family: var(--serif);
  font-size: 1.24rem;
  line-height: 1.75;
  font-variant-numeric: oldstyle-nums;
  hyphens: auto;
  max-width: 66ch;
}
.reading p { margin: 0 0 1.15em; }
.toolbar { font-size: 0.85rem; color: var(--muted); margin-bottom: 1.25rem; }
.toolbar label { display: inline-flex; gap: 0.4rem; align-items: center; cursor: pointer; }

.w { cursor: pointer; border-radius: 3px; transition: background 0.1s; }
.w:hover { background: var(--accent-soft); }
.w.g { text-decoration: underline dotted var(--gloss); text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
.w.looked { background: var(--accent-soft); }
mark { background: none; color: inherit; }
.grammar-on mark { background: var(--mark); border-radius: 3px; box-shadow: 0 0 0 2px var(--mark); }

.focus-list { list-style: none; padding: 0; margin: 0.4rem 0 0; }
.focus-list li { margin: 0.55rem 0; font-size: 0.9rem; }
.focus-list .quotes { color: var(--muted); font: italic 0.95rem/1.4 var(--serif); margin-left: 1rem; }
.tier { display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 50%; margin-right: 0.45rem; vertical-align: 0.05em; }
.tier.diamond { background: var(--diamond); }
.tier.gold { background: var(--gold); }
.tier.silver { background: var(--silver); }
.tier.bronze { background: var(--bronze); }

.next-step { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

/* ---------- popup ---------- */

.popup {
  position: absolute;
  z-index: 20;
  max-width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 10px 30px rgba(60, 45, 20, 0.14);
  font-size: 0.9rem;
}
.popup .lemma { font: 600 1.05rem var(--serif); }
.popup .pos { color: var(--faint); font-size: 0.78rem; margin-left: 0.35rem; }
.popup .note { color: var(--muted); font-size: 0.82rem; margin-top: 0.25rem; }
.popup button { margin-top: 0.6rem; font-size: 0.8rem; padding: 0.3rem 0.7rem; }

/* ---------- chat ---------- */

.chat-layout { display: grid; gap: 2rem; grid-template-columns: 1fr; }
@media (min-width: 1000px) {
  .chat-layout { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
  .chat-text { position: sticky; top: 5rem; max-height: calc(100vh - 6.5rem); overflow-y: auto; padding-right: 0.5rem; }
  .chat-text summary { display: none; }
}
.chat-text .reading { font-size: 1.08rem; line-height: 1.7; }
.chat-text summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; margin-bottom: 0.5rem; }
.chat-text h2 { margin-top: 0; }

.thread { display: flex; flex-direction: column; gap: 0.9rem; }
.msg { max-width: 88%; }
.msg.assistant { align-self: flex-start; }
.msg.user { align-self: flex-end; }
.bubble {
  font: 1.06rem/1.6 var(--serif);
  padding: 0.75rem 1rem;
  border-radius: 18px;
  white-space: pre-wrap;
}
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.user .bubble { background: var(--accent-soft); border-bottom-right-radius: 6px; }
.typing .bubble { color: var(--faint); font-style: italic; }

.corrections { margin-top: 0.4rem; display: grid; gap: 0.35rem; }
.fix {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.86rem;
}
.fix.hidden-fix { border-left-color: var(--border); opacity: 0.85; }
.fix .was { color: var(--wrong); text-decoration: line-through; text-decoration-thickness: 1px; font-family: var(--serif); }
.fix .now { color: var(--right); font-weight: 600; font-family: var(--serif); }
.fix .why { color: var(--muted); margin-top: 0.15rem; }
.fix .tag { font-size: 0.72rem; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }
.more-fixes { justify-self: end; font-size: 0.8rem; }
.corrected-text { font: italic 0.95rem/1.5 var(--serif); color: var(--muted); padding: 0.2rem 0.5rem; }

.composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to bottom, rgba(246, 243, 236, 0), var(--bg) 25%);
  padding: 1.25rem 0 1rem;
  margin-top: 1rem;
}
.composer textarea {
  width: 100%;
  min-height: 3.4rem;
  max-height: 12rem;
  resize: vertical;
  font: 1.05rem/1.5 var(--serif);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
}
.composer .row { margin-top: 0.5rem; }

.review-group { margin-bottom: 1.25rem; }
.review-group h3 { font: 600 1rem var(--sans); margin: 0 0 0.4rem; }

/* ---------- tables & misc ---------- */

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
th { overflow-wrap: normal; white-space: nowrap; color: var(--faint); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
td .title-link { font-family: var(--serif); font-size: 1rem; }
textarea.html-input { width: 100%; min-height: 7rem; font: 0.78rem/1.4 ui-monospace, Consolas, monospace; }
input[type=range] { width: 240px; padding: 0; accent-color: var(--accent); }
select { min-width: 0; flex: 1 1 220px; }
.tier-counts { display: flex; gap: 1.1rem; flex-wrap: wrap; margin: 1rem 0 0.5rem; font-size: 0.85rem; color: var(--muted); }
.stat-row { display: flex; gap: 2.5rem; flex-wrap: wrap; margin: 1rem 0 0.5rem; }
.stat .n { font: 600 1.8rem/1 var(--serif); }
.stat .l { font-size: 0.8rem; color: var(--faint); }
.trend-down { color: var(--right); font-weight: 600; }
.trend-up { color: var(--wrong); font-weight: 600; }
details.examples summary { cursor: pointer; color: var(--muted); font-size: 0.82rem; }
details.examples div { font-size: 0.85rem; margin: 0.25rem 0 0 0.5rem; }

@media (max-width: 560px) {
  h1 { font-size: 1.65rem; }
  .reader-head h1 { font-size: 1.8rem; }
  .reading { font-size: 1.14rem; }
  .pill { margin-left: 0; }
  input[type=range] { width: 100%; }
  .topbar-inner { gap: 0.8rem 1.25rem; }
}

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

.badge {
  display: inline-block;
  min-width: 1.3em;
  padding: 0 0.35em;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  vertical-align: 0.15em;
}

/* Words under review, woven into the reading. */
.w.rw, .rw-sample {
  text-decoration: underline solid var(--gold);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.22em;
}

.word-check { margin-top: 1.25rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.6rem; }
.chip {
  font: 1rem/1.2 var(--serif);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
}
.chip .chip-en { display: none; font: 0.78rem var(--sans); color: var(--muted); margin-left: 0.4rem; }
.chip.on { background: var(--mark); border-color: var(--gold); }
.chip.on .chip-en { display: inline; }

.review-card { text-align: center; padding: 2.5rem 1.5rem; }
.review-word { font: 600 2.2rem/1.2 var(--serif); }
.review-context { font: 1.15rem/1.6 var(--serif); color: var(--muted); margin-top: 1rem; }
.review-context strong { color: var(--text); }
.review-meaning { font: 1.3rem/1.4 var(--serif); margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.review-actions { justify-content: center; margin-top: 1.25rem; }

.feeds { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.feed { display: flex; gap: 0.45rem; align-items: baseline; flex-wrap: wrap; font-size: 0.92rem; margin: 0.35rem 0; cursor: pointer; }

/* ---------- login & setup ---------- */

main.auth { max-width: 440px; padding-top: 3.5rem; }
.auth-brand { display: block; text-align: center; font-size: 1.8rem; margin-bottom: 1.5rem; }
.auth .panel { display: grid; gap: 0.9rem; }
.auth h1 { font-size: 1.6rem; margin: 0; }
.auth label { display: grid; gap: 0.3rem; font-size: 0.9rem; font-weight: 500; }
.auth input { width: 100%; font-size: 1rem; }
.auth input[name=code] { font: 600 1.3rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: 0.15em; }
.auth .panel-title { margin-top: 0.5rem; }
.qr { display: flex; justify-content: center; background: #fff; border-radius: 12px; padding: 0.75rem; }
.qr svg { max-width: 100%; height: auto; }
.auth code { font-size: 0.85rem; word-break: break-all; }
.sessions td { font-size: 0.85rem; }

/* ---------- "Comment dit-on… ?" ---------- */

.howto {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
}
.howto input { flex: 1 1 240px; }
.howto-card { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.howto-fr { font: 600 1.2rem/1.4 var(--serif); color: var(--right); }
.howto-card button { font-size: 0.85rem; padding: 0.35rem 0.8rem; }
.fix.howto-fix { border-left-color: var(--accent); }
@media (max-width: 560px) { .hide-narrow { display: none; } }
