:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --text: #2a241d;
  --muted: #8a7f72;
  --line: #e8e0d4;
  --accent: #c4552d;
  --accent-ink: #ffffff;
  --radius: 16px;
  --serif: ui-serif, "New York", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1814;
    --surface: #26211b;
    --text: #f2ebe0;
    --muted: #a39887;
    --line: #3a332a;
    --accent: #e07a52;
    --accent-ink: #1c1814;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
}

.top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.top h1 { margin: 0; font: 600 17px var(--sans); letter-spacing: .01em; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: none; border-radius: 12px;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px 20px;
  margin-top: 8px;
}
.meta {
  margin: 0 0 14px; display: flex; gap: 10px; align-items: baseline;
  font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
}
.meta .who { color: var(--accent); }
.prev { margin: -4px 0 16px; font-size: 14px; color: var(--muted); font-family: var(--serif); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.prev[hidden] { display: none; }
.prev::before { content: "Previously  "; font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: .08em; }
.es { margin: 0; font: 400 clamp(23px, 6.4vw, 28px)/1.34 var(--serif); letter-spacing: -.005em; }
.en {
  margin: 14px 0 0; color: var(--muted); font-size: 16px;
  max-height: 0; opacity: 0; overflow: hidden; transition: max-height .25s ease, opacity .25s ease, margin .25s ease;
  margin-top: 0;
}
.en.show { max-height: 200px; opacity: 1; margin-top: 14px; }

.tools { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.chip {
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: none; font-size: 14px;
}
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.chip[hidden] { display: none; }

.words { list-style: none; padding: 0; margin: 20px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.words li { border-top: 1px solid var(--line); }
.words button {
  position: relative; display: block; width: 100%; min-height: 56px; padding: 10px 26px 10px 0;
  border: 0; background: none; text-align: left; font-size: 15px; line-height: 1.3;
}
.words button svg { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.words button:active, .words button.speaking, .words button.speaking svg { color: var(--accent); }
.chip.speaking { border-color: var(--accent); color: var(--accent); }
.words li small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

.primary {
  display: block; width: 100%; min-height: 52px; margin-top: 22px;
  border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: 16px; transition: transform .12s ease, opacity .2s ease;
}
.primary:active { transform: scale(.985); }
.primary[disabled] { background: none; color: var(--muted); border: 1px solid var(--line); cursor: default; }
.note { margin: 12px 0 0; text-align: center; font-size: 14px; color: var(--muted); min-height: 1.5em; }
.note:empty { display: none; }
.link {
  display: block; margin: 8px auto 0; min-height: 44px; padding: 0 12px; border: 0; background: none;
  color: var(--accent); font-size: 15px;
}
.link[hidden] { display: none; }
.link.danger { color: var(--muted); font-size: 14px; margin-top: 18px; }

.welcome h2 { margin: 0 0 8px; font: 400 28px/1.2 var(--serif); }
.welcome p { margin: 0 0 18px; color: var(--muted); }
.welcome[hidden], .card[hidden], .tracker[hidden] { display: none; }
input[type="text"] {
  width: 100%; min-height: 52px; padding: 0 14px; font: inherit; font-size: 17px; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
.seg { border: 0; margin: 16px 0 0; padding: 0; min-width: 0; }
.seg legend { padding: 0; margin-bottom: 10px; color: var(--muted); font-size: 14px; }
.seg-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg label { position: relative; display: block; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span {
  display: block; min-height: 56px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; line-height: 1.25;
}
.seg small { display: block; color: var(--muted); font: 400 15px var(--serif); font-style: italic; }
.seg input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg.in-sheet { margin: 4px 0 8px; }
.voice-row[hidden], .note[hidden] { display: none; }
.note.left { text-align: left; font-size: 13px; margin: 10px 0 4px; }
select {
  font: inherit; font-size: 16px; color: inherit; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; min-height: 44px; max-width: 60%;
}
.name-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; }
.name-row input[type="text"] { width: 55%; min-height: 44px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.tracker { margin-top: 28px; }
.grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.grid button {
  width: 100%; aspect-ratio: 1; border-radius: 50%; border: 1.5px solid var(--line);
  background: none; font-size: 13px; color: var(--muted); padding: 0;
}
.grid button[disabled] { opacity: .45; cursor: default; }
.grid button.open { border-color: var(--muted); color: var(--text); }
.grid button.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.grid button.now { border-color: var(--accent); color: var(--accent); border-width: 2px; font-weight: 600; }
.grid button.done.now { color: var(--accent-ink); }
.grid button.sel { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
.stats { text-align: center; color: var(--muted); font-size: 14px; margin: 16px 0 0; }

dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: 100vw; max-height: 100vh;
  width: 100%; margin: auto auto 0; }
dialog::backdrop { background: rgba(20, 15, 10, .45); }
.sheet {
  background: var(--bg); border-radius: 22px 22px 0 0; max-width: 480px; margin: 0 auto;
  padding: 8px 20px max(24px, env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto;
}
.sheet-top { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-top h2 { margin: 0; font: 600 17px var(--sans); }
.switch-row { display: flex; align-items: center; gap: 12px; min-height: 48px; font-size: 16px; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.times { display: grid; gap: 4px; margin-top: 4px; }
.times label { display: flex; align-items: center; justify-content: space-between; min-height: 48px; border-top: 1px solid var(--line); }
.times input { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.times.off { opacity: .45; pointer-events: none; }
.story { list-style: none; margin: 8px 0 0; padding: 0; }
.story li { padding: 14px 0; border-top: 1px solid var(--line); }
.story .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.story .lbl b { color: var(--accent); font-weight: 600; margin-left: 8px; }
.story .s-es { margin: 4px 0 0; font: 400 18px/1.4 var(--serif); }
.story .s-en { margin: 6px 0 0; color: var(--muted); font-size: 15px; display: none; }
.story.en .s-en { display: block; }
.story .empty { color: var(--muted); border: 0; }

/* chapter label, progress toward 500, review */
.chapter { margin: 0 0 12px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.bar { height: 4px; margin-top: 20px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.primary.slim { margin: 4px 0 12px; }
.rv-count { margin: 0; text-align: center; color: var(--muted); font-size: 14px; min-height: 1.5em; }
.rv-card { text-align: center; padding: 18px 0 8px; min-height: 150px; }
.rv-card[hidden], .rv-two[hidden], .rv-done[hidden], #rv-show[hidden] { display: none; }
.rv-word { border: 0; background: none; font: 400 44px/1.15 var(--serif); padding: 8px 12px; border-radius: 12px; }
.rv-word.speaking { color: var(--accent); }
.rv-en { margin: 8px 0 0; color: var(--muted); font-size: 20px; min-height: 1.5em; }
.rv-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.rv-two .primary { margin-top: 0; }
.chip.big { min-height: 52px; border-radius: 14px; font-size: 16px; }
.rv-done { margin: 24px 0 8px; text-align: center; font-size: 18px; line-height: 1.4; }

/* tabs and the Story / Words panes */
.app { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.pane[hidden], .tabs[hidden] { display: none; }
.pane-title { margin: 12px 0 8px; font: 400 28px/1.2 var(--serif); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center;
  background: var(--bg); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  position: relative; flex: 1; max-width: 160px; min-height: 56px; border: 0; background: none;
  color: var(--muted); font-size: 14px; font-weight: 500;
}
.tabs button[aria-current="page"] { color: var(--accent); }
.tabs button[aria-current="page"]::before {
  content: ""; position: absolute; top: -1px; left: 30%; right: 30%; height: 2px; background: var(--accent); border-radius: 2px;
}
.vocab { list-style: none; margin: 8px 0 0; padding: 0; }
.vocab li { border-top: 1px solid var(--line); }
.vrow {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px;
  padding: 10px 28px 10px 0; border: 0; background: none; text-align: left; font-size: 17px; line-height: 1.3;
}
.vtxt { flex: 1; }
.vtxt small { display: block; color: var(--muted); font-size: 14px; }
.vday { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.vrow svg { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.vrow:active, .vrow.speaking, .vrow.speaking svg { color: var(--accent); }
.vocab .empty { color: var(--muted); border: 0; padding: 16px 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
