/* Learning Tester. Mobile first; phone is the main device. */

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #eeece6;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e0ddd4;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece8;
  --again: #b8432f;
  --hard: #a86b12;
  --good: #2f7d4f;
  --easy: #2b62a8;
  --warn-bg: #fdf1d8;
  --warn-ink: #7a5200;
  --bad-bg: #fbe3df;
  --bad-ink: #8f2f20;
  --ok-ink: #2f7d4f;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  --radius: 14px;
  --tabs-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --card-font: "New York", ui-serif, Georgia, "Times New Roman", serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --surface: #1d1f22;
    --surface-2: #272a2e;
    --text: #ececec;
    --muted: #9a9ca1;
    --border: #33363b;
    --accent: #7cc4ad;
    --accent-ink: #0e1a16;
    --accent-soft: #203530;
    --again: #ee7b68;
    --hard: #e2b45a;
    --good: #6fcf97;
    --easy: #82b3f0;
    --warn-bg: #3a2f17;
    --warn-ink: #f3d28a;
    --bad-bg: #3d2420;
    --bad-ink: #f4a99b;
    --ok-ink: #6fcf97;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
body.focus-mode { padding-bottom: env(safe-area-inset-bottom); }
body.focus-mode #tabs { display: none; }

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.8em; }

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}
.center { text-align: center; }
.center-block { display: block; margin: 12px auto 0; }
.center-row { justify-content: center; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.warn-text { color: var(--warn-ink); }
.grow { flex: 1; min-width: 0; }

/* ---------- Top bar ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.bar h1 { margin: 0; text-align: center; font-size: 1.05rem; }
.home-bar { grid-template-columns: 1fr auto; padding-left: 16px; }
.home-bar h1 { text-align: left; font-size: 1.3rem; }
.bar-back, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  font-size: 1.6rem;
  color: var(--accent);
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
  border-radius: 10px;
}
.review-bar .bar-back { font-size: 1.2rem; color: var(--muted); }
.bar-right { justify-self: end; display: flex; align-items: center; gap: 4px; }

.pill {
  font: inherit;
  font-size: 0.8rem;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.pill-ok { color: var(--ok-ink); }
.pill-busy { color: var(--accent); }
.pill-bad { color: var(--bad-ink); background: var(--bad-bg); border-color: transparent; }

/* ---------- Bottom tabs ---------- */
#tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
#tabs a {
  flex: 1;
  max-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.7rem;
  color: var(--muted);
  text-decoration: none;
}
#tabs a.active { color: var(--accent); }
.tab-icon { font-size: 1.25rem; line-height: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 12px;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled, .btn.disabled { opacity: 0.45; pointer-events: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--surface); color: var(--bad-ink); border-color: var(--border); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn-block { display: flex; width: 100%; margin-top: 12px; }
.btn-grow { flex: 1; }
.btn-hero {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 84px;
  margin: 8px 0 6px;
  font-size: 1.2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero-meta { font-size: 0.9rem; font-weight: 500; opacity: 0.85; }
.link {
  font: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 6px 0;
  cursor: pointer;
  text-align: left;
}
.link.danger { color: var(--bad-ink); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.file-btn { position: relative; }

/* ---------- Lists and sections ---------- */
section { margin: 22px 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--border); }
.theme-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px; }
.theme-name { font-weight: 600; }
.card-row { display: block; padding: 12px 14px; color: inherit; text-decoration: none; }
.card-q { font-weight: 600; }
.card-q.alt { font-weight: 500; }
.card-a { color: var(--muted); white-space: pre-wrap; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.check { width: 24px; height: 24px; accent-color: var(--accent); }

.today { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.today h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.today-stats { font-size: 1.05rem; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 0.78rem; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip-new { background: var(--accent-soft); color: var(--accent); }
.chip-warn { background: var(--warn-bg); color: var(--warn-ink); }

.empty { text-align: center; padding: 28px 8px; }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 12px; border-radius: 10px; font-size: 0.9rem; }
.notice a { color: inherit; font-weight: 600; }
.errors { background: var(--bad-bg); color: var(--bad-ink); padding: 10px 12px; border-radius: 10px; font-size: 0.9rem; margin: 10px 0; }
.card-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.big-number { font-size: 3rem; font-weight: 700; margin: 24px 0 0; line-height: 1; }

/* ---------- Forms ---------- */
label { display: block; margin: 12px 0 0; font-size: 0.9rem; font-weight: 600; }
.field-label { margin: 14px 0 4px; font-size: 0.9rem; font-weight: 600; }
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  font: inherit;
  font-size: 16px; /* stops iPhone zooming in on focus */
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; }
.check-row { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check-row input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); flex-shrink: 0; }
.row input { margin-top: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details { margin-top: 16px; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.9rem; }
.prompt-field { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 6px; }
.prompt-field textarea { margin-top: 0; }
.hints { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; margin-top: 12px; font-size: 0.9rem; }
.hints ul, .hint-list { margin: 4px 0 0; padding-left: 18px; }
.hint-list { color: var(--warn-ink); font-size: 0.85rem; }
.label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.danger-zone { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }

.search { margin-top: 0 !important; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.filters select { width: auto; flex: 1; min-width: 140px; margin: 0; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented.wide { display: flex; margin-top: 14px; }
.segmented.wide .seg { flex: 1; }
.seg { font: inherit; font-size: 0.85rem; padding: 7px 10px; border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- Review ---------- */
.review { padding-top: 4px; }
.prompt {
  font-family: var(--card-font);
  font-size: 1.45rem;
  line-height: 1.35;
  margin: 18px 0 20px;
  overflow-wrap: anywhere;
}
.answer-input { font-size: 17px !important; }
.answer-form textarea { min-height: 88px; }
.verdict { font-weight: 700; margin: 4px 0 10px; }
.verdict.ok { color: var(--ok-ink); }
.verdict.bad { color: var(--bad-ink); }
.compare { display: grid; gap: 10px; }
.compare-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; overflow-wrap: anywhere; }
.compare-box.model { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
@media (min-width: 560px) { .compare { grid-template-columns: 1fr 1fr; } .compare:has(> :only-child) { grid-template-columns: 1fr; } }
.ratings { display: grid; gap: 8px; margin-top: 18px; }
.ratings-4 { grid-template-columns: repeat(4, 1fr); }
.ratings-3 { grid-template-columns: repeat(3, 1fr); }
.ratings-1 { grid-template-columns: 1fr; }
.rate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 60px;
  padding: 8px 4px;
  font: inherit;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  touch-action: manipulation;
}
.rate small { font-weight: 500; font-size: 0.78rem; color: var(--muted); }
.rate-again { color: var(--again); }
.rate-hard { color: var(--hard); }
.rate-good { color: var(--good); }
.rate-easy { color: var(--easy); }
.ratings-1 .rate { flex-direction: row; justify-content: center; gap: 10px; }
.menu {
  position: fixed;
  right: 12px;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.15);
  overflow: hidden;
}
.menu a, .menu button { font: inherit; text-align: left; padding: 13px 16px; color: var(--text); background: none; border: 0; text-decoration: none; cursor: pointer; }
.menu > * + * { border-top: 1px solid var(--border); }

/* ---------- Import ---------- */
.example, .instructions {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.85rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.paste { font-family: ui-monospace, Menlo, monospace; font-size: 14px !important; }
.import-item { display: flex; gap: 10px; padding: 12px 14px; }
.import-item.editing { display: block; }
.import-item.editing label:first-child { margin-top: 0; }
.import-item.excluded .import-body { opacity: 0.5; }
.import-check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); }
.import-body { flex: 1; min-width: 0; }
.locked { background: var(--surface-2); border-radius: var(--radius); padding: 16px; }
.entry-preview { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.entry-preview .check-row { margin-top: 0; }
.sticky-actions {
  position: sticky;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 8px);
  display: flex;
  gap: 10px;
  padding: 10px;
  margin: 20px -10px 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
}

/* ---------- Setup ---------- */
.setup { padding-top: calc(36px + env(safe-area-inset-top)); }
.setup h1 { font-size: 1.8rem; }
.setup h2 { margin-top: 26px; }
.or { text-align: center; color: var(--muted); margin: 14px 0 2px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  font-size: 0.9rem;
  color: var(--bg);
  background: var(--text);
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { font: inherit; font-weight: 700; color: var(--bg); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
body.focus-mode #toast { bottom: calc(env(safe-area-inset-bottom) + 16px); }

/* ---------- Sub-themes and selecting cards ---------- */
.theme-row { gap: 8px; }
.theme-row.sub { padding-left: 46px; background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); min-height: 52px; }
.theme-row.sub .theme-name { font-weight: 500; }
.expander {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  margin-left: -6px;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s;
}
.expander.open { transform: rotate(90deg); color: var(--accent); }
.expander-space { width: 24px; flex-shrink: 0; }
.row.tight { margin-top: 0; gap: 12px; flex-wrap: nowrap; }
.card-row.selectable { display: flex; gap: 12px; align-items: flex-start; margin: 0; font-weight: 400; cursor: pointer; }
.card-row.selectable .check { margin-top: 2px; flex-shrink: 0; }
.card-row.picked { background: var(--accent-soft); }
.selection-bar { display: block; border: 1px solid var(--border); background: var(--surface); box-shadow: 0 6px 24px rgb(0 0 0 / 0.12); }
.selection-bar label:first-of-type { margin-top: 4px; }
.selection-count { font-weight: 700; }
.bar-right .link { padding: 6px 8px; }
.theme-row.admin { flex-wrap: wrap; row-gap: 0; padding-top: 10px; padding-bottom: 8px; }
.theme-row.admin .theme-name { flex: 1 1 100%; }
.theme-row.admin .row.tight { flex-wrap: wrap; }

/* ---------- Language words (v1.2) ---------- */
.prompt.prompt-word { text-align: center; }
.chip-dir { background: var(--accent-soft); color: var(--accent); }
.word-line { font-size: 1.05rem; }
.word-note { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 0.92rem; }
.word-extras { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--border); }
.word-extras p { margin: 0; }
.ok-text { color: var(--ok-ink); font-weight: 700; }
.new-text { color: var(--accent); font-weight: 700; }
.own-results { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.own-results li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; overflow-wrap: anywhere; }
.own-results .row { margin-top: 4px; }
.card-a-inline { font-weight: 400; color: var(--muted); }
.row.wrap .btn { flex: 1 1 auto; }
.direction-row { padding: 0 14px 12px 50px; }
@media (max-width: 420px) { .direction-row { padding-left: 14px; } }
.list > li.direction-row { border-top: 0; }
.segmented.small { display: grid; grid-template-columns: 1fr 1fr auto; width: 100%; }
.segmented.small .seg { font-size: 0.78rem; padding: 6px 8px; white-space: normal; line-height: 1.2; }
fieldset.also-in { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px 10px; margin: 12px 0 0; }
fieldset.also-in legend { font-size: 0.9rem; font-weight: 600; padding: 0 4px; }
fieldset.also-in .check-row { margin-top: 6px; }
.links-list, .link-results { list-style: none; padding: 0; margin: 6px 0; display: grid; gap: 6px; }
.links-list li, .link-results li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow-wrap: anywhere; }
.link-results .row { margin-top: 0; flex-wrap: nowrap; }
.pending { margin-top: 24px; text-align: left; }
.pending .list { margin-top: 8px; }
.pending-item { padding: 12px 14px; }
.pending-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pending-head .icon-btn { margin-left: auto; }
.pending-item .form input { margin-top: 6px; }
.pending-item select { width: auto; }
.fu-effect { margin: 10px 0 0; }
.existing { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; font-size: 0.9rem; }
.existing-diff { margin: 6px 0; display: grid; gap: 2px; }
.existing .check-row { margin-top: 4px; }
