/* ============ Lingua — design system ============ */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --surface-3: #e4e8f2;
  --text: #14161c;
  --muted: #5c6373;
  --faint: #8b91a1;
  --border: #e2e6ef;
  --primary: #4f6bff;
  --primary-2: #3a55e6;
  --primary-contrast: #ffffff;
  --again: #e5484d;
  --hard: #e09b1a;
  --good: #2f9e6f;
  --easy: #4f6bff;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(20, 22, 28, 0.08);
  --shadow-sm: 0 2px 8px rgba(20, 22, 28, 0.06);
  --tab-h: 62px;
  --bar-h: 52px;
  --maxw: 720px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}
:root[data-theme="dark"], :root[data-theme="auto"] {
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] { color-scheme: light; }
}
:root[data-theme="dark"], html[data-theme="dark"] {
  --bg: #0f1320;
  --surface: #181d2e;
  --surface-2: #20263a;
  --surface-3: #2a3147;
  --text: #eef1f8;
  --muted: #a4abbd;
  --faint: #6f7689;
  --border: #2a3147;
  --primary: #6b86ff;
  --primary-2: #5570ff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0f1320; --surface: #181d2e; --surface-2: #20263a; --surface-3: #2a3147;
    --text: #eef1f8; --muted: #a4abbd; --faint: #6f7689; --border: #2a3147;
    --primary: #6b86ff; --primary-2: #5570ff;
    --shadow: 0 8px 30px rgba(0,0,0,.35); --shadow-sm: 0 2px 10px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font-family: inherit; font-size: 16px; }
a { color: var(--primary); text-decoration: none; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.appbar__title { font-size: 18px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -0.01em; }
.appbar__back {
  border: 0; background: transparent; color: var(--primary);
  font-size: 30px; line-height: 1; width: 32px; height: 38px; cursor: pointer; padding: 0;
}
.appbar__right { display: flex; align-items: center; gap: 6px; }
.iconbtn {
  border: 0; background: var(--surface-2); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer; font-size: 17px;
  display: grid; place-items: center;
}
.offline-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--hard); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hard) 25%, transparent); }

/* ---------- View ---------- */
.view {
  flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding: 16px 14px calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px);
}

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--faint); font-size: 11px; font-weight: 600; cursor: pointer; position: relative;
}
.tab__ico { font-size: 20px; line-height: 1; }
.tab.is-active { color: var(--primary); }
.tab--center { }
.tab__plus {
  background: var(--primary); color: #fff; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; font-size: 26px; margin-top: -10px;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 50%, transparent);
}

/* ---------- Generic components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 16px;
}
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--muted); }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--primary); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.badge--muted { background: var(--surface-3); color: var(--muted); }

.btn {
  appearance: none; border: 0; border-radius: var(--radius-sm); padding: 13px 16px; font-weight: 700;
  background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); color: var(--primary-contrast); box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 40%, transparent); }
.btn--ghost { background: transparent; border: 1px solid var(--border); }
.btn--danger { background: color-mix(in srgb, var(--again) 16%, var(--surface)); color: var(--again); }
.btn--block { width: 100%; }
.btn--sm { padding: 8px 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: block; margin-bottom: 12px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, .textarea, .select {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.textarea { min-height: 90px; resize: vertical; line-height: 1.5; }

/* ---------- Language cards (home) ---------- */
.lang-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.lang-card + .lang-card { margin-top: 10px; }
.lang-flag { font-size: 30px; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); }
.lang-meta { flex: 1; min-width: 0; }
.lang-name { font-weight: 700; font-size: 16px; }
.lang-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.lang-counts { display: flex; gap: 6px; }
.count-chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 9px; }
.count-chip--due { background: color-mix(in srgb, var(--again) 18%, transparent); color: var(--again); }
.count-chip--new { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.count-chip--zero { background: var(--surface-2); color: var(--faint); }

/* ---------- Hero / stats ---------- */
.hero { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 6px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-align: center; box-shadow: var(--shadow-sm); }
.stat__num { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat__lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.streak { color: var(--hard); }

/* ---------- Review / flashcard ---------- */
.session { display: flex; flex-direction: column; min-height: calc(100dvh - var(--bar-h) - var(--tab-h) - 60px); }
.session__progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.session__bar { height: 100%; background: var(--primary); width: 0; transition: width .25s ease; }
.flash {
  flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 22px;
  box-shadow: var(--shadow); padding: 26px 22px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 12px; position: relative;
  min-height: 320px;
}
.flash__tag { position: absolute; top: 14px; left: 16px; }
.flash__audio { position: absolute; top: 10px; right: 12px; }
.flash__prompt { font-size: 13px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }
.flash__target { font-size: 38px; font-weight: 800; line-height: 1.15; letter-spacing: -.01em; }
.flash__translit { font-size: 18px; color: var(--muted); font-style: italic; }
.flash__divider { width: 60%; height: 1px; background: var(--border); margin: 6px 0; }
.flash__answer { font-size: 26px; font-weight: 700; }
.flash__notes { font-size: 14px; color: var(--muted); max-width: 36ch; }
.flash__examples { margin-top: 6px; font-size: 14px; color: var(--muted); text-align: start; width: 100%; max-width: 40ch; }
.flash__examples li { margin: 4px 0; }
.flash[dir="rtl"] .flash__target { font-size: 42px; }

.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.grade { border: 0; border-radius: 14px; padding: 12px 4px; color: #fff; font-weight: 800; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.grade small { font-weight: 600; opacity: .9; font-size: 11px; }
.grade--again { background: var(--again); }
.grade--hard { background: var(--hard); }
.grade--good { background: var(--good); }
.grade--easy { background: var(--easy); }
.reveal-btn { margin-top: 14px; }

/* ---------- List rows ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.item__main { flex: 1; min-width: 0; }
.item__target { font-weight: 700; }
.item__sub { color: var(--muted); font-size: 13px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item__state { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 8px; background: var(--surface-2); color: var(--faint); }
.item__state.is-due { background: color-mix(in srgb, var(--again) 16%, transparent); color: var(--again); }
.item__state.is-new { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }

/* ---------- Empty / loaders ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty__ico { font-size: 44px; margin-bottom: 10px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.search { flex: 1; min-width: 160px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 8px; font-weight: 700; font-size: 13px; cursor: pointer; }
.seg button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px;
  font-weight: 600; font-size: 14px; z-index: 60; transition: all .25s ease; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Misc ---------- */
.hr { height: 1px; background: var(--border); border: 0; margin: 18px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-toggle { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 600; }
.chip-toggle.is-on { background: var(--primary); color: #fff; border-color: var(--primary); }
.link { color: var(--primary); cursor: pointer; font-weight: 600; }
.kbd { font-family: ui-monospace, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
[dir="rtl"] { text-align: right; }
.fadein { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.spin { width: 22px; height: 22px; border: 3px solid var(--surface-3); border-top-color: var(--primary); border-radius: 50%; animation: rot .7s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }
