/* Wordbank — mobile-first, no framework.
   Palette follows the parent site (midnight blue + gold) so the installed app
   and the web page it came from look like the same thing. */

:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --panel-2: #efeee9;
  --text: #23232b;
  --muted: #6d6d78;
  --faint: #9a9aa5;
  --line: rgba(0, 0, 0, .12);
  --accent: #8a6d3b;
  --accent-ink: #ffffff;
  --gold: #c9a14a;
  --good: #2e7d4f;
  --good-bg: rgba(46, 125, 79, .12);
  --bad: #b3403f;
  --bad-bg: rgba(179, 64, 63, .12);
  --warn: #a8761f;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 6px 18px rgba(0, 0, 0, .06);
  --radius: 14px;
  --tab-h: 58px;
  color-scheme: light;
}

:root[data-theme="dark"],
:root:not([data-theme="light"]) {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16161f;
    --panel: #1f1f2c;
    --panel-2: #282838;
    --text: #e6e5e0;
    --muted: #a3a2ae;
    --faint: #75747f;
    --line: rgba(255, 255, 255, .13);
    --accent: #d4a54a;
    --accent-ink: #1a1a2e;
    --gold: #d4a54a;
    --good: #6fce9a;
    --good-bg: rgba(111, 206, 154, .15);
    --bad: #e08a8a;
    --bad-bg: rgba(224, 138, 138, .15);
    --warn: #e0b463;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #16161f;
  --panel: #1f1f2c;
  --panel-2: #282838;
  --text: #e6e5e0;
  --muted: #a3a2ae;
  --faint: #75747f;
  --line: rgba(255, 255, 255, .13);
  --accent: #d4a54a;
  --accent-ink: #1a1a2e;
  --gold: #d4a54a;
  --good: #6fce9a;
  --good-bg: rgba(111, 206, 154, .15);
  --bad: #e08a8a;
  --bad-bg: rgba(224, 138, 138, .15);
  --warn: #e0b463;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); }

.en { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif; }
.ipa { font-family: "Charis SIL", "Doulos SIL", "Lucida Sans Unicode", "Segoe UI", sans-serif; }

/* ---- app frame --------------------------------------------------------- */

#view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 14px calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 -14px 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 650; letter-spacing: .01em; }
.topbar__sub { color: var(--muted); font-size: 12.5px; font-weight: 400; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--faint);
  font-size: 11px;
  transition: color .15s;
}
.tabbar button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-selected="true"] { color: var(--accent); }

/* ---- generic pieces ---------------------------------------------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 650; }
.card h2 .n { color: var(--muted); font-weight: 400; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 11px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  border: 1px solid var(--line);
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn--wide { width: 100%; }
.btn--sm { min-height: 36px; padding: 0 12px; font-size: 13px; font-weight: 500; border-radius: 9px; }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--bad); }
.btn[disabled] { opacity: .6; pointer-events: none; }
.btn--primary[disabled] { background: var(--panel-2); color: var(--muted); }

.row { display: flex; align-items: center; gap: 10px; }
.row--wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.center { text-align: center; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.input, textarea.input, select.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 150px; line-height: 1.55; resize: vertical; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 12.5px;
  color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip--tag { background: transparent; color: var(--muted); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
.switch__label { flex: 1; }
.switch__label b { display: block; font-weight: 550; }
.switch input[type="checkbox"] { width: 44px; height: 26px; appearance: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; position: relative; transition: background .18s; flex: none; }
.switch input[type="checkbox"]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--panel); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .18s; }
.switch input[type="checkbox"]:checked { background: var(--accent); border-color: transparent; }
.switch input[type="checkbox"]:checked::after { transform: translateX(18px); }
.switch select, .switch input[type="number"] { width: 108px; min-height: 38px; padding: 6px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 54px; height: 54px; stroke: var(--faint); fill: none; stroke-width: 1.3; margin-bottom: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%) translateY(12px);
  z-index: 100;
  max-width: min(92vw, 420px);
  padding: 11px 18px;
  border-radius: 11px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.on { opacity: .96; transform: translateX(-50%) translateY(0); }
/* A session covers the tab bar, so the toast has to clear its footer instead. */
#session:not(.is-hidden) ~ .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }

/* ---- study home -------------------------------------------------------- */

.today { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; text-align: center; margin-bottom: 14px; }
.today__n { font-size: 26px; font-weight: 680; line-height: 1.15; font-variant-numeric: tabular-nums; }
.today__k { font-size: 12px; color: var(--muted); }
.today__new .today__n { color: var(--gold); }
.today__due .today__n { color: var(--accent); }

.ring { display: block; margin: 0 auto 4px; }
.ring circle { fill: none; stroke-width: 7; stroke-linecap: round; }
.ring .bg { stroke: var(--panel-2); }
.ring .fg { stroke: var(--accent); transition: stroke-dashoffset .5s; }

.streak { display: flex; gap: 4px; justify-content: center; margin-top: 4px; }
.streak i { width: 8px; height: 8px; border-radius: 2px; background: var(--panel-2); }
.streak i.on { background: var(--good); }

/* ---- session ----------------------------------------------------------- */

.session {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.session__bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.session__x { font-size: 22px; line-height: 1; color: var(--muted); padding: 6px 8px; }
.session__back { display: inline-flex; align-items: center; gap: 1px; padding: 6px 10px 6px 4px; border-radius: 9px; font-size: 13px; color: var(--accent); white-space: nowrap; }
.session__back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.session__back[disabled] { color: var(--faint); opacity: .45; cursor: default; }
.ses-star.on { color: var(--gold); border-color: var(--gold); }
.session__prog { flex: 1; height: 5px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.session__prog i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.session__count { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.session__body { flex: 1; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; }
.session__foot:empty { display: none; }
.session__foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }

/* Centre the card: on a tall phone a top-aligned question leaves the answer
   buttons stranded in the middle of nowhere. */
.q { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.q__kind { font-size: 12px; color: var(--faint); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 14px; }
.q__word { font-size: clamp(30px, 9vw, 42px); font-weight: 600; line-height: 1.2; word-break: break-word; }
.q__phon { color: var(--muted); font-size: 15px; margin-top: 5px; }
.q__prompt { font-size: 20px; line-height: 1.5; margin: 4px 0 8px; }
.q__speak { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; color: var(--accent); font-size: 13px; }
.q__speak svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.q__speak--big svg { width: 46px; height: 46px; stroke-width: 1.4; }

.opts { display: grid; gap: 9px; margin-top: 18px; }
.opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  line-height: 1.45;
  transition: background .15s, border-color .15s;
}
.opt b { flex: none; width: 22px; height: 22px; border-radius: 6px; background: var(--panel-2); color: var(--muted); font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.opt.is-right { background: var(--good-bg); border-color: var(--good); }
.opt.is-right b { background: var(--good); color: var(--panel); }
.opt.is-wrong { background: var(--bad-bg); border-color: var(--bad); }
.opt.is-wrong b { background: var(--bad); color: var(--panel); }
.opt[disabled] { opacity: 1; }

.spell { margin-top: 20px; }
.spell__hint { font-size: 26px; letter-spacing: .30em; color: var(--faint); margin-bottom: 10px; }
.spell input {
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  font-size: 24px;
  letter-spacing: .05em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.spell input:focus { border-color: var(--accent); }
.spell input.is-right { border-color: var(--good); background: var(--good-bg); }
.spell input.is-wrong { border-color: var(--bad); background: var(--bad-bg); }

.cloze { font-size: 19px; line-height: 1.75; margin-top: 8px; }
.cloze u { text-decoration: none; border-bottom: 2px solid var(--accent); padding: 0 22px; }

.reveal { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.reveal__trans { font-size: 17px; line-height: 1.6; }
.reveal__ex { margin-top: 12px; font-size: 14px; color: var(--muted); line-height: 1.65; }
.reveal__ex em { font-style: normal; color: var(--text); }
.reveal__ex b { font-weight: 600; color: var(--accent); }

.grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grade { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; justify-content: center; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 600; }
.grade small { font-weight: 400; font-size: 11px; color: var(--muted); }
.grade--again { color: var(--bad); }
.grade--good { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.grade--good small { color: color-mix(in srgb, var(--accent-ink) 70%, transparent); }

.done { text-align: center; padding: 40px 20px; }
.done__big { font-size: 46px; margin-bottom: 8px; }
.done__stats { display: flex; justify-content: center; gap: 26px; margin: 20px 0 26px; }
.done__stats div { text-align: center; }
.done__stats b { display: block; font-size: 22px; font-weight: 650; }

/* ---- library ----------------------------------------------------------- */

.search { position: relative; margin-bottom: 10px; }
.search input { width: 100%; min-height: 42px; padding: 8px 12px 8px 36px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; outline: none; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; fill: none; stroke: var(--faint); stroke-width: 2; }

.wlist { list-style: none; margin: 0; padding: 0; }
.wli { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.wli__main { flex: 1; min-width: 0; }
.wli__w { font-size: 16px; font-weight: 550; }
.wli__t { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wli__s { flex: none; font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.wli__s[data-s="3"] { background: var(--good-bg); color: var(--good); }
.wli__s[data-s="0"] { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--warn); }
.star { flex: none; font-size: 16px; color: var(--faint); padding: 4px; }
.star.on { color: var(--gold); }

/* ---- sheet (bottom modal) ---------------------------------------------- */

.sheet-bg { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .45); opacity: 0; transition: opacity .2s; }
.sheet-bg.on { opacity: 1; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 71;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform .26s cubic-bezier(.2, .8, .3, 1);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}
.sheet.on { transform: translateY(0); }
.sheet__grip { width: 38px; height: 4px; border-radius: 3px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 12px; font-size: 17px; }

/* ---- import ------------------------------------------------------------ */

.imp__tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.preview { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 11px; }
.preview table { width: 100%; border-collapse: collapse; font-size: 13px; }
.preview th { position: sticky; top: 0; background: var(--panel-2); text-align: left; font-weight: 550; font-size: 12px; color: var(--muted); padding: 7px 9px; }
.preview td { padding: 7px 9px; border-top: 1px solid var(--line); vertical-align: top; }
.preview td:first-child { font-weight: 550; white-space: nowrap; }
.preview tr.dup td { opacity: .5; }
.preview tr.miss td:nth-child(2) { color: var(--warn); }

.bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; margin: 10px 0; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---- stats ------------------------------------------------------------- */

.bars { display: flex; align-items: flex-end; gap: 5px; height: 110px; margin: 6px 0 4px; }
.bars div { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bars div.zero { background: var(--panel-2); }
.axis { display: flex; gap: 5px; font-size: 10px; color: var(--faint); }
.axis span { flex: 1; text-align: center; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal i { aspect-ratio: 1; border-radius: 4px; background: var(--panel-2); }
.cal i[data-l="1"] { background: color-mix(in srgb, var(--good) 32%, var(--panel-2)); }
.cal i[data-l="2"] { background: color-mix(in srgb, var(--good) 60%, var(--panel-2)); }
.cal i[data-l="3"] { background: var(--good); }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 10px; }
.kv div b { display: block; font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kv div span { font-size: 12px; color: var(--muted); }

.is-hidden { display: none !important; }

@media (min-width: 720px) {
  #view { max-width: 620px; margin: 0 auto; }
  .session__body, .session__foot, .session__bar { max-width: 620px; margin-inline: auto; width: 100%; }
}
