:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --ink: #2a211c;
  --muted: #7a6c62;
  --line: #eadfd2;
  --accent: #c4532d;
  --accent-ink: #fff8ee;
  --teal: #1f7a74;
  --good: #2e7d4f;
  --good-bg: #e7f4ec;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --s0: #d9cfc4;
  --s1: #e9a23b;
  --s2: #3b8fd9;
  --s3: #2e9d62;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 4px 16px rgb(60 40 20 / 6%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714;
    --surface: #26201c;
    --ink: #f3ebe2;
    --muted: #a8998d;
    --line: #3a312b;
    --accent: #e0714a;
    --accent-ink: #1b1714;
    --teal: #4fb3ab;
    --good: #6fcf97;
    --good-bg: #1f3328;
    --bad: #f28b82;
    --bad-bg: #3a2220;
    --s0: #4a4038;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { font-size: 17px; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--teal); }
h1 { font-size: 1.8rem; margin: 0.2em 0 0.3em; font-family: Georgia, "Times New Roman", serif; }
h2 { font-size: 1.1rem; margin: 1.6em 0 0.6em; display: flex; align-items: center; gap: 0.5em; flex-wrap: wrap; }
h3 { margin: 1.4em 0 0.4em; font-size: 1rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.warn { background: var(--bad-bg); padding: 0.6em 0.9em; border-radius: var(--radius); }
[hidden] { display: none !important; }

/* Navigation: bottom tab bar on phones, top bar on wide screens. */
nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav a {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center;
  text-decoration: none; color: var(--muted); font-size: 0.7rem; padding: 4px 0; border-radius: 10px;
}
nav a .icon { font-size: 1.3rem; line-height: 1.2; }
nav a.active { color: var(--accent); font-weight: 600; }
nav .brand { display: none; }
.badge {
  position: absolute; top: 0; right: calc(50% - 22px);
  background: var(--accent); color: var(--accent-ink); font-size: 0.7rem; border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center;
}
body.focus-mode nav { display: none; }
body.focus-mode { padding-bottom: 0; }

@media (min-width: 700px) {
  body { padding-bottom: 0; padding-top: 64px; }
  body.focus-mode { padding-top: 0; }
  nav { inset: 0 0 auto 0; border-top: 0; border-bottom: 1px solid var(--line); justify-content: center; gap: 4px; padding: 10px; }
  nav a { flex: 0 0 auto; flex-direction: row; gap: 6px; font-size: 0.95rem; padding: 6px 12px; }
  nav a .icon { font-size: 1rem; }
  nav a.active { background: var(--bg); }
  nav .brand { display: flex; margin-right: auto; color: var(--ink); font-weight: 700; font-family: Georgia, serif; font-size: 1.15rem; }
  nav .brand + a { margin-left: 0; }
  .badge { position: static; }
}

main { max-width: 720px; margin: 0 auto; padding: 16px; }
.page section { margin-top: 0.5em; }

/* Buttons */
button, .button {
  font: inherit; font-size: 0.95rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  padding: 0.6em 1.1em; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); text-decoration: none;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.danger { color: var(--bad); }
.small, button.small, .button.small { font-size: 0.8rem; padding: 0.35em 0.8em; }
button.link { border: 0; background: none; padding: 0; color: var(--teal); text-decoration: underline; font-size: 0.85rem; }
.speak { padding: 0.15em 0.45em; font-size: 0.9em; border-radius: 8px; vertical-align: middle; }
.actions { display: flex; gap: 0.6em; flex-wrap: wrap; margin-top: 1em; }

/* Home */
.hero { background: linear-gradient(135deg, var(--accent), #d9822b); color: #fff8ee; border-radius: 20px; padding: 18px 20px; box-shadow: var(--shadow); }
.hero h1 { color: #fff8ee; margin: 0 0 0.4em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 10px; }
.stats div { flex: 1; background: rgb(255 255 255 / 16%); border-radius: 12px; padding: 8px 10px; }
.stats b { display: block; font-size: 1.5rem; line-height: 1.1; }
.stats span { font-size: 0.8rem; opacity: 0.9; }
.task {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
}
.task .num { flex: 0 0 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--bg); }
.task.todo .num { background: var(--accent); color: var(--accent-ink); }
.task.done .num { background: var(--good-bg); color: var(--good); }
.task.locked { opacity: 0.6; }
.task > div { flex: 1; }
.task .go { font-size: 1.4rem; color: var(--accent); }
a.task:hover { border-color: var(--accent); }
.pod { background: var(--surface); border-radius: var(--radius); padding: 4px 16px 14px; border: 1px solid var(--line); }
.units-strip { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 1.5em; }
.chip { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; text-decoration: none; font-size: 1.3rem; background: var(--surface); border: 2px solid var(--line); }
.chip.passed { border-color: var(--s3); }
.chip.open { border-color: var(--accent); }
.chip.locked { filter: grayscale(1); opacity: 0.5; }

/* Competence bar */
.competence .bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--s0); }
.competence .seg { min-width: 4px; }
.competence .legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: baseline; flex: 0 0 auto; }
.s0 { background: var(--s0); } .s1 { background: var(--s1); } .s2 { background: var(--s2); } .s3 { background: var(--s3); }

/* Units */
.unit-list { display: grid; gap: 10px; }
.unit-card { display: flex; gap: 14px; align-items: center; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; box-shadow: var(--shadow); }
.unit-card .emoji { font-size: 2rem; }
.unit-card.locked { opacity: 0.55; }
.unit-card.passed { border-color: var(--s3); }
a.unit-card:hover { border-color: var(--accent); }
.back { display: inline-block; margin-bottom: 0.4em; text-decoration: none; font-size: 0.9rem; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row.done > span:first-child { color: var(--muted); }
.row.quiz { font-weight: 600; }
details.grammar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px; }
details.grammar summary { cursor: pointer; font-weight: 600; }
details.grammar table { border-collapse: collapse; margin: 0.6em 0; font-size: 0.92rem; }
details.grammar td, details.grammar th { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
label.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
label.check input { margin-top: 0.3em; width: 18px; height: 18px; accent-color: var(--accent); }

/* Phrase list */
.phrase-list { display: grid; gap: 6px; }
details.phrase { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
details.phrase summary { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; list-style: none; }
details.phrase summary::-webkit-details-marker { display: none; }
details.phrase .es { font-weight: 600; }
details.phrase .en { color: var(--muted); flex: 1; font-size: 0.92rem; }
.phrase-body { padding: 0 14px 10px; font-size: 0.95rem; }
.phrase-body p { margin: 0.4em 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.filters .search { flex: 1 1 220px; }
input[type="search"], input[type="text"], input[type="password"], input[type="number"], select, textarea {
  font: inherit; padding: 0.55em 0.8em; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
textarea { width: 100%; resize: vertical; }

/* Sessions */
.session { max-width: 640px; margin: 0 auto; }
.session-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.quit { text-decoration: none; color: var(--muted); font-size: 1.3rem; }
.progress { flex: 1; height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--s3); transition: width 0.3s; }
.session-label { font-size: 0.8rem; color: var(--muted); max-width: 40%; text-align: right; }
.card { background: var(--surface); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card .tag { display: inline-block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); font-weight: 700; margin-bottom: 0.4em; }
.big { font-size: 1.6rem; font-weight: 650; line-height: 1.3; margin: 0.2em 0; }
.big.cloze { font-size: 1.3rem; font-weight: 500; }
.blank { display: inline-block; min-width: 3em; border-bottom: 2px solid var(--accent); color: transparent; }
.meaning { font-size: 1.1rem; color: var(--muted); margin-bottom: 0.6em; }
.instruction { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.prompt { margin-bottom: 16px; }
.note { font-size: 0.95rem; }
.mnemonic { background: color-mix(in srgb, var(--s1) 14%, transparent); border-radius: 10px; padding: 8px 12px; font-size: 0.95rem; }
.accent-notes p { margin: 0.35em 0; font-size: 0.95rem; }
.example { font-size: 0.95rem; border-left: 3px solid var(--line); padding-left: 10px; }
.continue { width: 100%; margin-top: 14px; padding: 0.8em; font-size: 1.05rem; }
.options { display: grid; gap: 8px; }
.option { justify-content: flex-start; text-align: left; border-radius: 12px; padding: 0.8em 1em; font-size: 1.02rem; border-width: 2px; }
.option kbd { font: 0.75rem ui-monospace, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
.option.right { border-color: var(--good); background: var(--good-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.input-wrap { margin-bottom: 10px; }
.input-row { display: flex; gap: 8px; }
.answer { flex: 1; font-size: 1.15rem !important; padding: 0.7em 0.9em !important; width: 100%; }
.mic { border-radius: 12px; font-size: 1.2rem; }
.mic.live { background: var(--bad-bg); border-color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.accent-keys { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.input-wrap:has(input:disabled) .accent-keys { display: none; }
.accent-keys button { padding: 0.2em 0.65em; border-radius: 8px; font-size: 1rem; }
.shake { animation: shake 0.35s; border-color: var(--bad) !important; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.feedback { margin-top: 16px; border-radius: 14px; padding: 14px 16px; }
.feedback.good { background: var(--good-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback .verdict { font-weight: 700; font-size: 1.1rem; }
.feedback.good .verdict { color: var(--good); }
.feedback.bad .verdict { color: var(--bad); }
.feedback .expected { font-size: 1.25rem; font-weight: 650; margin: 0.2em 0; }
.feedback .meaning { margin-bottom: 0.2em; }
.you-said { font-size: 0.9rem; color: var(--muted); margin: 0.4em 0; }
.done-card { text-align: center; }
.done-card .actions { justify-content: center; }
.done-card .phrase-list { text-align: left; margin-top: 10px; }

/* Dialogues */
.setting { background: var(--surface); border: 1px dashed var(--line); border-radius: 12px; padding: 8px 12px; }
.chat { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 18px; }
.bubble.them { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.you { align-self: flex-end; background: color-mix(in srgb, var(--teal) 16%, var(--surface)); border-bottom-right-radius: 4px; }
.bubble.you.meh { background: var(--bad-bg); }
.bubble .es { font-weight: 600; }
.bubble .en { font-size: 0.88rem; color: var(--muted); }
.bubble .en.hidden { display: none; }
.chat-footer { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }
.chat-footer.finished { position: static; }
.your-turn > div:first-child { margin-bottom: 8px; }
.self-grade .model { font-weight: 600; margin: 4px 0; }

/* Ask */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin-bottom: 10px; background: var(--surface); }
.segmented .seg { border: 0; background: none; padding: 0.45em 1em; }
.segmented .seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ask-box .status, .status { color: var(--muted); font-size: 0.9rem; margin-top: 8px; min-height: 1.2em; }
.qa-list { display: grid; gap: 8px; }
details.qa { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
details.qa summary { cursor: pointer; font-weight: 600; }
.answer-body { font-size: 0.97rem; }
.answer-body h4 { margin: 0.8em 0 0.2em; }

.settings label { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }

/* Pacing */
.stop { margin-top: 16px; border-color: var(--s3); }
.stop .actions { justify-content: center; }
.card.break { margin-top: 16px; padding: 14px 18px; }
.card.break p { margin: 0.3em 0 0; }
pre.report { white-space: pre-wrap; font: 0.8rem/1.45 ui-monospace, monospace; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }

/* Screen profiles. The learner moves between four screens (see the teaching-the-user skill):
   Fold folded (~412 px, phone), Fold unfolded (~750-880 px, near-square), MacBook Pro (~1512 px),
   and a 1440p desktop (~2560 px). Phone-first rules above; each step below uses the extra room. */
@media (min-width: 700px) {
  main { max-width: 900px; padding: 20px 24px; }
  .home-cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 28px; align-items: start; }
  .col-side > section:first-child h2 { margin-top: 1.6em; }
  .unit-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .session { max-width: 720px; }
}
@media (min-width: 1200px) {
  html { font-size: 18px; }
  main { max-width: 1120px; padding: 28px 32px; }
  .home-cols { gap: 40px; }
  .phrase-list { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .done-card .phrase-list { grid-template-columns: 1fr; }
  .session { max-width: 760px; padding-top: 12px; }
}
@media (min-width: 2000px) {
  html { font-size: 20px; }
  main { max-width: 1400px; }
  .unit-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .session { max-width: 860px; }
}
