:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --text: #171a2b;
  --muted: #646a85;
  --border: #e1e4ef;
  --accent: #4f46e5;
  --accent-soft: #e8e7fd;
  --on-accent: #ffffff;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgb(20 24 50 / 6%), 0 4px 16px rgb(20 24 50 / 6%);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --surface: #181b2e;
    --surface-2: #22263d;
    --text: #eceefa;
    --muted: #9ba1bf;
    --border: #2c3150;
    --accent: #818cf8;
    --accent-soft: #2a2d55;
    --on-accent: #0f1120;
    --good: #4ade80;
    --good-soft: #143322;
    --bad: #f87171;
    --bad-soft: #3d1a1d;
    --warn: #fbbf24;
    --warn-soft: #3a2c0d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.6rem; margin: 4px 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 24px 0 10px; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

button, .btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  transition: transform 0.06s, background 0.15s;
}
button:active, .btn:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.ghost { background: transparent; border-color: transparent; }
.danger { color: var(--bad); }
.block { width: 100%; }
.big { min-height: 56px; font-size: 1.1rem; }
.icon-btn { min-width: 44px; padding: 8px; border-radius: 50%; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}
textarea { resize: vertical; min-height: 120px; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; }
label.field > span { display: block; font-size: 0.875rem; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }

nav#nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
nav#nav a {
  flex: 1;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
}
nav#nav a span { font-size: 1.35rem; line-height: 1.2; filter: grayscale(1); opacity: 0.7; }
nav#nav a.active { color: var(--accent); font-weight: 600; }
nav#nav a.active span { filter: none; opacity: 1; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
  max-width: calc(100% - 32px);
  z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* home */
.hero { display: flex; gap: 12px; }
.hero .card { flex: 1; text-align: center; padding: 14px 8px; }
.hero .num { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.deck {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}
.deck .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}
.pill.due { background: var(--accent-soft); color: var(--accent); }
.pill.new { background: var(--good-soft); color: var(--good); }

/* tabs */
.tabs { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: transparent; min-height: 38px; padding: 6px; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }

/* word preview list */
.wlist { list-style: none; padding: 0; margin: 0; }
.wlist li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.wlist li:last-child { border-bottom: 0; }
.wlist .en { font-weight: 600; }
.wlist input[type=checkbox] { width: 22px; height: 22px; min-height: 0; margin-top: 2px; accent-color: var(--accent); flex: none; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.edit-grid .full { grid-column: 1 / -1; }

/* study */
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.3s; }
.study-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.prompt { text-align: center; padding: 24px 12px 20px; }
.prompt .word { font-size: 2rem; font-weight: 700; line-height: 1.2; word-break: break-word; }
.prompt .sub { color: var(--muted); margin-top: 6px; }
.mode-tag { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.options { display: grid; gap: 10px; }
.options button { justify-content: flex-start; text-align: left; min-height: 54px; padding: 12px 16px; }
.options button.right { background: var(--good-soft); border-color: var(--good); color: var(--good); font-weight: 600; }
.options button.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate button { flex-direction: column; gap: 0; padding: 8px 4px; font-size: 0.9rem; }
.rate small { font-size: 0.7rem; color: var(--muted); font-weight: 400; }
.rate .r1 { color: var(--bad); }
.rate .r2 { color: var(--warn); }
.rate .r3 { color: var(--good); }
.rate .r4 { color: var(--accent); }
.verdict { border-radius: 12px; padding: 10px 14px; font-weight: 600; margin-bottom: 12px; }
.verdict.ok { background: var(--good-soft); color: var(--good); }
.verdict.no { background: var(--bad-soft); color: var(--bad); }
.verdict.meh { background: var(--warn-soft); color: var(--warn); }
.listen-btn { width: 96px; height: 96px; border-radius: 50%; font-size: 2.4rem; margin: 8px auto; display: flex; }

/* full card details */
.full-card .img {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 1;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--surface-2);
  display: block;
  object-fit: cover;
}
.full-card .img.loading { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
.full-card .head { display: flex; align-items: center; gap: 8px; justify-content: center; flex-wrap: wrap; }
.full-card .w { font-size: 1.7rem; font-weight: 700; }
.full-card .tr { color: var(--muted); text-align: center; }
.full-card .ru { font-size: 1.2rem; text-align: center; margin: 6px 0 2px; }
.full-card .forms { text-align: center; color: var(--muted); font-size: 0.9rem; }
.full-card .ex { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-top: 12px; display: flex; gap: 8px; align-items: flex-start; }
.full-card .ex .t { flex: 1; }
.full-card .ex .t div + div { color: var(--muted); font-size: 0.92rem; }
.full-card .hint { margin-top: 10px; font-size: 0.95rem; }
.speak-box { margin-top: 12px; }
.score { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.score > div { height: 100%; }
.rec { color: var(--bad); animation: pulse 1s infinite; }

/* deck view */
.clist .citem { padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.clist .citem:last-child { border-bottom: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips .btn, .chips button { flex: 1 1 calc(50% - 8px); }

/* stats */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: 0.85; }
.bars div.zero { background: var(--surface-2); opacity: 1; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kv .card { text-align: center; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth { max-width: 380px; margin: 8vh auto 0; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 12px; }
.chips .btn { white-space: nowrap; padding: 10px 8px; }

/* AI chat */
.chat-log { display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; }
.bubble.model { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.chat-words { margin-top: 10px; white-space: normal; }
.chips-wrap { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; min-height: 0; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.85rem; color: var(--text); }
button.chip { cursor: pointer; }
textarea.chat-input { min-height: 48px; resize: none; }
span.chip { display: inline-block; line-height: 1.35; }
