/* ==========================================================================
   engwords - responsive layout for phone (bottom nav) and desktop (top nav)
   ========================================================================== */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #14161a;
  --text-dim: #626873;
  --text-faint: #8b919c;
  --accent: #1f6feb;
  --accent-soft: #e7f0ff;
  --green: #1a7f45;
  --green-soft: #e3f5ea;
  --amber: #a86400;
  --amber-soft: #fdf1dc;
  --red: #c1352b;
  --red-soft: #fdeceb;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 22, 26, .06), 0 4px 16px rgba(20, 22, 26, .06);
  --nav-height: 60px;
  --content-max: 780px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #24282f;
    --border: #2f343d;
    --text: #e8eaee;
    --text-dim: #a2a9b5;
    --text-faint: #767d89;
    --accent: #5a9bff;
    --accent-soft: #1b2b45;
    --green: #52c98a;
    --green-soft: #16301f;
    --amber: #e0a340;
    --amber-soft: #33270f;
    --red: #f07a70;
    --red-soft: #351a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.boot { padding: 3rem; text-align: center; color: var(--text-dim); }

/* ---------- shell ---------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem max(1rem, env(safe-area-inset-left)) .6rem max(1rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.01em;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: .45rem;
}

.topbar__nav { display: none; gap: .25rem; }

.topbar__user {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--text-dim);
  font-size: .85rem;
}

.main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 1rem max(.9rem, env(safe-area-inset-left)) calc(var(--nav-height) + 1.5rem);
}

.bottomnav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottomnav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--nav-height);
  background: none;
  border: 0;
  color: var(--text-faint);
  font-size: .7rem;
  transition: color .15s;
}

.bottomnav__item[aria-current="page"] { color: var(--accent); }
.bottomnav__icon { font-size: 1.25rem; line-height: 1; }

.navlink {
  border: 0;
  background: none;
  padding: .45rem .8rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: .92rem;
  font-weight: 500;
}
.navlink:hover { background: var(--surface-2); color: var(--text); }
.navlink[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

@media (min-width: 720px) {
  :root { --nav-height: 0px; }
  .topbar__nav { display: flex; }
  .bottomnav { display: none; }
  .main { padding: 1.75rem 1.25rem 3rem; }
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  margin-bottom: 1rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: .6rem 1rem;
  font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { filter: brightness(1.07); background: var(--accent); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn--block { width: 100%; }
.btn--sm { padding: .35rem .7rem; font-size: .85rem; }

.field { display: block; margin-bottom: .9rem; }
.field__label { display: block; font-size: .85rem; color: var(--text-dim); margin-bottom: .3rem; }
.input {
  width: 100%;
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: .5rem; }
.row--wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.stack > * + * { margin-top: .75rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .12rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-dim);
}
.pill--green { background: var(--green-soft); color: var(--green); }
.pill--amber { background: var(--amber-soft); color: var(--amber); }
.pill--blue { background: var(--accent-soft); color: var(--accent); }
.pill--red { background: var(--red-soft); color: var(--red); }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--text-faint); }
.empty__icon { font-size: 2.5rem; display: block; margin-bottom: .5rem; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 1.25rem);
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(90vw, 420px);
  padding: .7rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: .9rem;
  animation: toast-in .2s ease-out;
}
.toast--error { border-color: var(--red); color: var(--red); }
.toast--success { border-color: var(--green); color: var(--green); }
.toast--out { opacity: 0; transition: opacity .5s; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- login ---------- */

.auth { max-width: 380px; margin: 8vh auto 0; }
.auth__title { font-size: 1.5rem; font-weight: 700; margin: 0 0 .25rem; }
.auth__hint { margin: 0 0 1.25rem; color: var(--text-dim); font-size: .9rem; }
.auth__switch { margin-top: 1rem; text-align: center; font-size: .88rem; }

/* ---------- search ---------- */

.searchbar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.searchbar .input { flex: 1; font-size: 1.05rem; }

.entry__head { display: flex; align-items: flex-start; gap: .6rem; flex-wrap: wrap; }
.entry__word {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0;
  word-break: break-word;
}
.entry__phonetic { color: var(--text-dim); font-size: .95rem; }
.entry__gloss { font-size: 1.05rem; margin: .35rem 0 0; }

.speak {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex: none;
  transition: background .15s, transform .1s;
}
.speak:hover { background: var(--accent-soft); }
.speak--playing { background: var(--accent-soft); transform: scale(1.06); }
.speak--sm { width: 26px; height: 26px; font-size: .8rem; }

.section { margin-top: 1.25rem; }
.section__title {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 .5rem;
}

.sense { padding: .55rem 0; border-top: 1px solid var(--border); }
.sense:first-of-type { border-top: 0; padding-top: 0; }
.sense__pos {
  display: inline-block;
  min-width: 2.6rem;
  font-style: italic;
  color: var(--accent);
  font-size: .85rem;
}
.sense__zh { font-weight: 500; }
.sense__en { color: var(--text-dim); font-size: .92rem; margin-top: .15rem; }

.example { padding: .6rem 0; border-top: 1px solid var(--border); }
.example:first-of-type { border-top: 0; padding-top: 0; }
.example__en { display: flex; align-items: flex-start; gap: .5rem; }
.example__en span { flex: 1; }
.example__zh { color: var(--text-dim); font-size: .92rem; margin-top: .2rem; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: .2rem .7rem;
  font-size: .85rem;
  color: var(--text-dim);
}

.history__item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 0;
  border-top: 1px solid var(--border);
}
.history__item:first-child { border-top: 0; }
.history__word { font-weight: 600; }
.history__gloss { color: var(--text-dim); font-size: .88rem; }
.history__main { flex: 1; min-width: 0; cursor: pointer; }
.history__main > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 1rem;
}
.progress__fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .3s ease;
}

.quiz { min-height: 300px; display: flex; flex-direction: column; }
.quiz__prompt { text-align: center; padding: 1.5rem 0 1rem; }
.quiz__word {
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0;
  word-break: break-word;
}
.quiz__sub { color: var(--text-dim); margin-top: .3rem; }
.quiz__hint { color: var(--text-faint); font-size: .85rem; margin-top: .75rem; }

.choices { display: grid; gap: .55rem; margin-top: .5rem; }
.choice {
  text-align: left;
  padding: .8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: background .12s, border-color .12s;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.choice--correct { border-color: var(--green); background: var(--green-soft); color: var(--green); font-weight: 600; }
.choice--wrong { border-color: var(--red); background: var(--red-soft); color: var(--red); }

.reveal { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: 1rem; }

.ratings { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; margin-top: 1rem; }
@media (min-width: 560px) { .ratings { grid-template-columns: repeat(4, 1fr); } }
.rating {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  padding: .65rem .4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.rating__label { font-weight: 600; font-size: .95rem; }
.rating__interval { font-size: .72rem; color: var(--text-faint); }
.rating--again { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); color: var(--red); }
.rating--hard  { border-color: color-mix(in srgb, var(--amber) 45%, var(--border)); color: var(--amber); }
.rating--good  { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); color: var(--accent); }
.rating--easy  { border-color: color-mix(in srgb, var(--green) 45%, var(--border)); color: var(--green); }

.modeswitch { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.modeswitch button {
  border: 0;
  background: none;
  padding: .3rem .85rem;
  border-radius: 999px;
  font-size: .85rem;
  color: var(--text-dim);
}
.modeswitch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

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

.statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
@media (min-width: 560px) { .statgrid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem;
  text-align: center;
}
.stat__value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat__label { font-size: .78rem; color: var(--text-dim); margin-top: .1rem; }
.stat--green .stat__value { color: var(--green); }
.stat--amber .stat__value { color: var(--amber); }
.stat--blue .stat__value { color: var(--accent); }

.donut { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.donut__legend { flex: 1; min-width: 140px; }
.legend__row { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; font-size: .9rem; }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* Columns must stretch to the full track height, otherwise the percentage
   heights inside them resolve against an auto height and collapse. */
.bars { display: flex; align-items: stretch; gap: 3px; height: 110px; margin-top: .5rem; }
.bars__col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 1px; min-width: 0; height: 100%; }
.bars__seg { border-radius: 2px 2px 0 0; min-height: 2px; }
.bars__seg--ok { background: var(--accent); }
.bars__seg--miss { background: var(--red); border-radius: 0 0 2px 2px; }
.bars__axis { display: flex; gap: 3px; margin-top: .3rem; }
.bars__tick { flex: 1; text-align: center; font-size: .62rem; color: var(--text-faint); min-width: 0; overflow: hidden; }

/* ---------- word list ---------- */

.tabs { display: flex; gap: .35rem; overflow-x: auto; padding-bottom: .25rem; margin-bottom: .75rem; }
.tab {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: .35rem .85rem;
  font-size: .88rem;
  color: var(--text-dim);
}
.tab[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.wordrow {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem 0;
  border-top: 1px solid var(--border);
}
.wordrow:first-child { border-top: 0; }
.wordrow__main { flex: 1; min-width: 0; }
.wordrow__word { font-weight: 600; }
.wordrow__gloss { color: var(--text-dim); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wordrow__meta { text-align: right; font-size: .72rem; color: var(--text-faint); flex: none; }

.loadmore { margin-top: 1rem; }
