:root {
  --bg: #f6f1e9;
  --surface: #fffcf7;
  --surface-2: #efe8dc;
  --ink: #26221d;
  --ink-2: #6b6258;
  --line: #e2d9cb;
  --accent: #c2512c;
  --accent-ink: #fff;
  --accent-soft: #f6dfd3;
  --good: #3f7d58;
  --hard: #a87316;
  --again: #b3392f;
  --easy: #2f6c9a;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(40 30 20 / .06), 0 8px 24px rgb(40 30 20 / .06);
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916; --surface: #24211d; --surface-2: #2e2a25; --ink: #efe8dd; --ink-2: #a89e91;
    --line: #3a352f; --accent: #e07450; --accent-ink: #1b1916; --accent-soft: #3b2a22;
    --good: #6fb48a; --hard: #d6a24a; --again: #e06b60; --easy: #6ea8d6;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 650; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-family: var(--serif); font-size: 18px;
}
.section-nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.section-nav a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--ink-2); white-space: nowrap; font-size: 15px;
}
.section-nav a.active { background: var(--surface-2); color: var(--ink); }

main { max-width: 680px; margin: 0 auto; padding: 20px 16px 32px; outline: none; }
h1 { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.2; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 160px; text-align: center; text-decoration: none; padding: 8px 4px; border-radius: 10px;
  color: var(--ink-2); font-size: 14px; font-weight: 550;
}
.tabbar a.active { color: var(--accent); background: var(--accent-soft); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

button, .btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 16px; cursor: pointer;
  font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; transition: transform .06s ease;
}
button:active, .btn:active { transform: scale(.98); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.small { min-height: 34px; padding: 6px 12px; font-size: 14px; }
button.danger { color: var(--again); }
button:disabled { opacity: .5; cursor: default; }
.wide { width: 100%; }

label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
input, textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 11px 12px;
  font-size: 16px; /* 16px avoids iOS zoom */
}
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }
textarea { min-height: 72px; resize: vertical; }
.field + .field { margin-top: 12px; }

/* Home */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tile { text-decoration: none; display: block; }
.tile .card { height: 100%; }
.tile h3 { margin: 6px 0 2px; font-size: 18px; }
.tile .emoji { font-size: 26px; }
.tile.soon { opacity: .55; pointer-events: none; }
.badge {
  display: inline-block; font-size: 13px; font-weight: 650; padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}

/* Review */
.stats-line { display: flex; gap: 14px; font-size: 14px; color: var(--ink-2); margin-bottom: 12px; }
.stats-line b { color: var(--ink); }
.flash { min-height: 300px; display: flex; flex-direction: column; text-align: center; padding: 28px 20px; }
.flash .dir { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.flash .prompt { font-family: var(--serif); font-size: clamp(28px, 7vw, 40px); line-height: 1.2; margin: 26px 0 8px; word-break: break-word; }
.flash .answer { border-top: 1px dashed var(--line); margin-top: 18px; padding-top: 18px; }
.flash .answer .main { font-size: 22px; font-weight: 600; }
.flash .example { font-style: italic; color: var(--ink-2); margin-top: 10px; }
.flash .notes { font-size: 14px; color: var(--ink-2); margin-top: 8px; white-space: pre-wrap; }
.flash .tools { margin-top: auto; padding-top: 18px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.grades button { flex-direction: column; gap: 0; padding: 8px 4px; min-height: 58px; font-size: 15px; }
.grades button span { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.grades .g1 { color: var(--again); } .grades .g2 { color: var(--hard); }
.grades .g3 { color: var(--good); } .grades .g4 { color: var(--easy); }
.lookup a { font-size: 14px; color: var(--ink-2); }
.progress { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
.progress div { height: 100%; background: var(--accent); transition: width .25s ease; }

/* Word list */
.word-list { list-style: none; margin: 0; padding: 0; }
.word-list li { border-bottom: 1px solid var(--line); }
.word-row { display: flex; gap: 10px; align-items: baseline; padding: 12px 2px; cursor: pointer; width: 100%; background: none; border: 0; border-radius: 0; text-align: left; min-height: 0; font-weight: 400; }
.word-row .t { font-weight: 650; }
.word-row .m { color: var(--ink-2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.word-row .d { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.word-edit { padding: 4px 2px 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0;
  pointer-events: none; transition: all .2s ease; z-index: 20; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.login { max-width: 360px; margin: 12vh auto 0; }
.empty { text-align: center; padding: 40px 16px; }
.empty .big { font-size: 40px; }
details summary { cursor: pointer; font-weight: 600; }
