:root {
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #2b2620;
  --muted: #7a7064;
  --line: #e2d9c8;
  --accent: #2f5d50;
  --accent-ink: #fff;
  --good: #2e7d4f;
  --good-bg: #e6f3ea;
  --bad: #b3412e;
  --bad-bg: #fbe9e5;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
h1 { font-family: Georgia, "Times New Roman", serif; font-size: 1.6rem; margin: 8px 0 16px; }
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 10px; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.brand { font-family: Georgia, serif; font-size: 1.25rem; font-weight: 700; background: none; border: 0; color: var(--accent); padding: 4px 0; }
.icon-btn { font-size: 1.4rem; background: none; border: 0; width: 44px; height: 44px; color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); background: transparent; border-color: transparent; margin-top: 24px; }
.btn.block { display: flex; width: 100%; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; }

.row { display: flex; gap: 10px; margin-top: 16px; }
.row > .btn { flex: 1; }
.sticky-actions { position: sticky; bottom: 0; background: var(--paper); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }

.empty, .hint, .muted { color: var(--muted); }
.small { font-size: .85rem; margin: 0 0 4px; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card, .cards > li {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.cards#lists { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cards > li.list-card { position: relative; padding: 0; display: flex; }
.card-train {
  flex: 1; min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  padding: 14px 40px 12px 14px; text-align: left; font: inherit; color: inherit;
  background: none; border: 0; border-radius: var(--radius); cursor: pointer;
}
.card-train:active { background: var(--line); }
.card-train:focus-visible, .card-edit:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.list-card .name { font-weight: 650; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.list-card .count { margin: 0; }
.card-edit {
  position: absolute; top: 4px; right: 4px; width: 40px; height: 40px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 10px; color: var(--muted); cursor: pointer;
}
.card-edit:active { background: var(--line); color: var(--ink); }

.text {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; font: inherit; font-size: 16px; color: var(--ink);
}
.text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.text.big { font-size: 1.25rem; min-height: 54px; margin: 4px 0 12px; }

fieldset.target { border: 0; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; }
fieldset.target legend { font-weight: 600; margin-bottom: 8px; }
.choice { display: flex; align-items: center; gap: 10px; min-height: 40px; font-weight: 600; }
.choice input { width: 20px; height: 20px; accent-color: var(--accent); }

table.pairs { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.pairs th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 4px; }
table.pairs th:last-child { width: 40px; }
table.pairs td { padding: 3px; vertical-align: top; }
table.pairs .text { min-height: 40px; padding: 8px; font-size: 15px; }
#edit-name { margin-bottom: 4px; }
#edit-add-row { margin-top: 8px; }
.del-row { width: 36px; height: 40px; border: 0; background: none; color: var(--muted); font-size: 1.2rem; }

.train-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pill { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 5px 12px; font-size: .85rem; font-weight: 600; }
.progress { height: 6px; background: var(--line); border-radius: 3px; margin: 12px 0 16px; overflow: hidden; }
#train-bar { height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.question { padding: 20px; }
.prompt { font-family: Georgia, serif; font-size: 1.7rem; margin: 4px 0 20px; overflow-wrap: anywhere; }
.prompt-row { display: flex; align-items: flex-start; gap: 8px; }
.prompt-row .prompt { flex: 1; }
.speak-btn { flex: none; margin-top: 2px; border-radius: 50%; }
.speak-btn:active { background: var(--line); }
.feedback { margin-top: 14px; border-radius: 12px; padding: 12px 14px; }
.feedback.good { background: var(--good-bg); color: var(--good); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.feedback p { margin: 0 0 4px; font-weight: 600; }
#feedback-expected { color: var(--ink); font-weight: 400; }
.interlude { text-align: center; font-size: 1.1rem; padding: 24px 18px; }
.interlude p { margin: 0 0 18px; line-height: 1.5; }

.rounds-explained { color: var(--muted); padding-left: 22px; line-height: 1.7; }
.round-score { display: flex; justify-content: space-between; align-items: baseline; }
.round-score strong { font-size: 1.3rem; }
.wrong-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.wrong-list li { background: var(--bad-bg); border-radius: 10px; padding: 10px 12px; display: flex; justify-content: space-between; gap: 12px; }

@media (prefers-reduced-motion: reduce) { #train-bar { transition: none; } }

.round-score { gap: 12px; }
.round-score strong { flex: none; }
#train-quit { margin-top: 14px; }

.app-error { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 10; background: var(--bad); color: #fff; border-radius: 12px; padding: 12px 14px; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
