/* Slova — светлая дружелюбная тема, мобильный-first. Цвета — токены на :root, тёмная тема ниже. */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --ink: #1d2433;
  --ink-2: #4b5468;
  --muted: #8a93a6;
  --line: #e3e7f0;
  --primary: #3b5bdb;
  --primary-ink: #ffffff;
  --primary-soft: #e8edff;
  --ok: #2b8a3e;
  --ok-soft: #e3f6e8;
  --bad: #d6336c;
  --bad-soft: #fde8ef;
  --warn: #c76a00;
  --warn-soft: #fff1db;
  --accent: #fcc419;
  --chart-a: #3b5bdb;
  --chart-b: #f4a3bd;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .06);
  --radius: 16px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c; --surface: #1d2029; --surface-2: #262a35; --ink: #e9ecf3; --ink-2: #b8bfcf;
    --muted: #7d869a; --line: #2f3442; --primary: #7b93ff; --primary-ink: #0f1424; --primary-soft: #252d4d;
    --ok: #5cc777; --ok-soft: #1b3324; --bad: #ff7aa2; --bad-soft: #3d1f2a; --warn: #ffb54d; --warn-soft: #3a2c16;
    --chart-a: #7b93ff; --chart-b: #8f4a63;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161c; --surface: #1d2029; --surface-2: #262a35; --ink: #e9ecf3; --ink-2: #b8bfcf;
  --muted: #7d869a; --line: #2f3442; --primary: #7b93ff; --primary-ink: #0f1424; --primary-soft: #252d4d;
  --ok: #5cc777; --ok-soft: #1b3324; --bad: #ff7aa2; --bad-soft: #3d1f2a; --warn: #ffb54d; --warn-soft: #3a2c16;
  --chart-a: #7b93ff; --chart-b: #8f4a63;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
[hidden] { display: none !important; }

#app {
  max-width: 680px; margin: 0 auto;
  padding: calc(12px + var(--safe-t)) 16px calc(var(--tabbar) + 24px + var(--safe-b));
}
body.study #app { padding-bottom: calc(24px + var(--safe-b)); }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ── нижняя панель ── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(12px); backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs a {
  flex: 1; max-width: 170px; height: var(--tabbar);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.tabs a .ti { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--primary); }
.tabs a.on .ti { filter: none; opacity: 1; }

/* ── типографика и блоки ── */
h1 { font-size: 26px; line-height: 1.2; margin: 8px 0 14px; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 22px 0 10px; }
h3 { font-size: 16px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 0 0 12px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* ── кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 0;
  background: var(--surface-2); color: var(--ink); font-weight: 600; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform .08s ease, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.big { min-height: 56px; font-size: 18px; border-radius: 16px; }
.btn.block { display: flex; width: 100%; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: 15px; border-radius: 12px; }
.btn:disabled { opacity: .45; pointer-events: none; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer;
  color: var(--ink-2); flex: none; touch-action: manipulation;
}
.iconbtn:active { background: var(--surface-2); }
.speak { font-size: 22px; }

/* ── шапка экрана ── */
.topbar { display: flex; align-items: center; gap: 6px; margin: 0 -8px 6px; min-height: 48px; }
.topbar .title { flex: 1; font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── главная ── */
.hello { display: flex; align-items: center; gap: 12px; margin: 6px 0 14px; }
.hello h1 { margin: 0; flex: 1; font-size: 24px; }
.streak {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn); font-weight: 700; font-size: 15px; white-space: nowrap;
}
.streak.off { background: var(--surface-2); color: var(--muted); }
.goal { display: flex; align-items: center; gap: 16px; }
.ring { width: 76px; height: 76px; flex: none; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: var(--primary); transition: stroke-dashoffset .6s ease; }
.ring text { fill: var(--ink); font-weight: 700; font-size: 15px; }
.stat-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.tile .n { font-size: 30px; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.tile .l { color: var(--ink-2); font-size: 14px; }
.tile.due .n { color: var(--primary); }
.tile.new .n { color: var(--ok); }

/* ── наборы ── */
.deck {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; color: var(--ink);
}
.deck .dname { font-weight: 700; overflow-wrap: anywhere; }
.deck .dmeta { color: var(--muted); font-size: 14px; }
.deck .body { flex: 1; min-width: 0; }
.pill {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 13px;
  font-weight: 700; background: var(--primary-soft); color: var(--primary); white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.gray { background: var(--surface-2); color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 8px; display: flex; gap: 2px; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.bar i.lrn { background: var(--primary); opacity: .55; }
.desc { white-space: pre-line; font-size: 14px; color: var(--ink-2); background: var(--primary-soft); border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 16px; }
.mode {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 84px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  border: 0; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink); padding: 8px 4px; text-align: center;
}
.mode .mi { font-size: 26px; line-height: 1; }
.mode.main { grid-column: 1 / -1; flex-direction: row; min-height: 60px; background: var(--primary); color: var(--primary-ink); font-size: 18px; }
.mode:active { transform: scale(.97); }

.search {
  width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 14px; font-size: 16px; outline: none;
}
.search:focus { border-color: var(--primary); }

.words { list-style: none; margin: 0; padding: 0; }
.word {
  display: flex; align-items: center; gap: 8px; padding: 10px 6px 10px 14px; background: var(--surface);
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.word:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.word:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: 0; }
.word:only-child { border-radius: var(--radius); }
.word .wb { flex: 1; min-width: 0; }
.word .cz { font-weight: 700; overflow-wrap: anywhere; }
.word .ru { color: var(--ink-2); font-size: 15px; overflow-wrap: anywhere; }
.word .nt { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.lvl { display: inline-flex; gap: 3px; flex: none; }
.lvl i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.lvl i.on { background: var(--ok); }
.gender { display: inline-block; font-size: 12px; font-weight: 700; padding: 0 6px; border-radius: 6px; margin-left: 6px; vertical-align: 2px; }
.g-ma, .g-mi { background: #e3edff; color: #2f5bd1; }
.g-f { background: #ffe3ef; color: #c2255c; }
.g-n { background: #e6f6e6; color: #2b8a3e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .gender { background: var(--surface-2); } }

/* ── формы и шторки ── */
label.f { display: block; margin: 0 0 12px; }
label.f > span { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.input, textarea.input, select.input {
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  padding: 10px 14px; font-size: 17px; outline: none; -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 160px; resize: vertical; line-height: 1.4; font-size: 16px; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; font-size: 15px; cursor: pointer; touch-action: manipulation;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.sheet-back {
  position: fixed; inset: 0; background: rgba(15, 20, 35, .42); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + var(--safe-b));
  animation: up .2s ease;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { margin-top: 4px; }
@media (min-width: 700px) {
  .sheet-back { align-items: center; }
  .sheet { border-radius: 20px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 18px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── учёба ── */
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; flex: 1; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: 4px; transition: width .3s ease; }
.qwrap { min-height: 60vh; display: flex; flex-direction: column; }
.qlabel { color: var(--muted); font-size: 14px; font-weight: 600; margin: 8px 0 6px; text-transform: none; }
.prompt {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 16px;
  display: flex; align-items: center; gap: 8px; margin-bottom: 16px; min-height: 120px;
}
.prompt .txt { flex: 1; font-size: 28px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; text-align: center; }
.prompt .txt.ru { font-size: 24px; font-weight: 600; }
.prompt .sub { display: block; font-size: 14px; font-weight: 500; color: var(--muted); margin-top: 6px; }
.opts { display: grid; gap: 10px; }
.opt {
  min-height: 56px; padding: 10px 14px 10px 44px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow);
  border: 2px solid transparent; text-align: left; font-size: 17px; font-weight: 600; cursor: pointer; position: relative;
  overflow-wrap: anywhere; touch-action: manipulation;
}
.opt .k { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; font-weight: 700; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; }
.opt.dim { opacity: .5; }
.answer-input {
  width: 100%; min-height: 56px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface);
  padding: 0 16px; font-size: 20px; font-weight: 600; outline: none;
}
.answer-input:focus { border-color: var(--primary); }
.answer-input.right { border-color: var(--ok); background: var(--ok-soft); }
.answer-input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.answer-input.almost { border-color: var(--warn); background: var(--warn-soft); }
.dia { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.dia button {
  min-width: 40px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  font-size: 19px; font-weight: 600; cursor: pointer; touch-action: manipulation; flex: 1 0 40px; max-width: 54px;
}
.dia button:active { background: var(--primary-soft); }
.feedback { border-radius: var(--radius); padding: 14px 16px; margin: 14px 0 10px; font-size: 16px; animation: up .15s ease; }
.feedback.right { background: var(--ok-soft); color: var(--ok); }
.feedback.wrong { background: var(--bad-soft); }
.feedback.almost { background: var(--warn-soft); }
.feedback .h { font-weight: 800; font-size: 17px; margin-bottom: 4px; }
.feedback.wrong .h { color: var(--bad); }
.feedback.almost .h { color: var(--warn); }
.feedback .corr { font-size: 22px; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.feedback .yours { color: var(--ink-2); font-size: 15px; margin-top: 4px; overflow-wrap: anywhere; }
.hl { color: var(--warn); background: var(--warn-soft); border-radius: 3px; padding: 0 1px; }
.hl.miss { color: #fff; background: var(--bad); }
.yours .x { text-decoration: underline wavy var(--bad); text-underline-offset: 3px; }
.actions { display: flex; gap: 10px; margin-top: 12px; }
.actions .btn { flex: 1; }
.stage-tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); }
.stage-tag.new { background: var(--ok-soft); color: var(--ok); }

/* ── флеш-карточка ── */
.flip-scene { perspective: 1200px; margin: 8px 0 16px; touch-action: pan-y; }
.flip {
  position: relative; width: 100%; height: min(58vh, 420px); transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2,.7,.3,1); cursor: pointer;
}
.flip.flipped { transform: rotateY(180deg); }
.flip.dragging { transition: none; }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.face.back { transform: rotateY(180deg); }
.face .big { font-size: 32px; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.face .mid { font-size: 24px; font-weight: 600; overflow-wrap: anywhere; }
.face .note { color: var(--muted); font-size: 15px; margin-top: 10px; overflow-wrap: anywhere; }
.face .hint { position: absolute; bottom: 14px; color: var(--muted); font-size: 13px; }
.face .corner { position: absolute; top: 10px; right: 10px; }
.swipe-tag { position: absolute; top: 18px; font-weight: 800; font-size: 18px; padding: 4px 12px; border-radius: 10px; opacity: 0; z-index: 2; pointer-events: none; }
.swipe-tag.yes { right: 18px; color: var(--ok); border: 3px solid var(--ok); }
.swipe-tag.no { left: 18px; color: var(--bad); border: 3px solid var(--bad); }
.intro-card { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 24px 18px; text-align: center; margin: 8px 0 16px; }
.intro-card .big { font-size: 34px; font-weight: 800; overflow-wrap: anywhere; }
.intro-card .mid { font-size: 22px; color: var(--ink-2); margin-top: 8px; overflow-wrap: anywhere; }
.intro-card .note { color: var(--muted); margin-top: 10px; font-size: 15px; overflow-wrap: anywhere; }

/* ── подбор пар ── */
.match-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .match-grid { grid-template-columns: repeat(4, 1fr); } }
.tilebtn {
  min-height: 84px; border-radius: 14px; border: 2px solid transparent; background: var(--surface); box-shadow: var(--shadow);
  padding: 6px; font-size: 15px; font-weight: 600; cursor: pointer; overflow-wrap: anywhere; hyphens: auto;
  touch-action: manipulation; transition: opacity .25s, transform .1s;
}
.tilebtn.cz { font-weight: 800; }
.tilebtn.sel { border-color: var(--primary); background: var(--primary-soft); }
.tilebtn.bad { border-color: var(--bad); background: var(--bad-soft); animation: shake .3s; }
.tilebtn.done { opacity: 0; pointer-events: none; transform: scale(.9); }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ── статистика ── */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 10px; }
.chart .a { fill: var(--chart-a); }
.chart .b { fill: var(--chart-b); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + g rect, .chart .col.on rect { opacity: .8; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); margin: 4px 0 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart-tip { min-height: 22px; font-size: 14px; color: var(--ink-2); }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.kv:last-child { border-bottom: 0; }
.kv b { font-variant-numeric: tabular-nums; }

/* ── импорт ── */
.prev { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.prev li { display: flex; gap: 10px; align-items: baseline; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.prev li .c { font-weight: 700; flex: 1 1 40%; min-width: 0; overflow-wrap: anywhere; }
.prev li .r { flex: 1 1 60%; min-width: 0; color: var(--ink-2); overflow-wrap: anywhere; }
.prev li.skip { opacity: .45; }
.prev li .tag { font-size: 12px; color: var(--warn); font-weight: 700; flex: none; }

/* ── вход ── */
.login { max-width: 360px; margin: 14vh auto 0; text-align: center; }
.login .logo { width: 84px; height: 84px; border-radius: 22px; margin-bottom: 8px; }
.login .input { text-align: center; font-size: 22px; letter-spacing: .08em; }
.err { color: var(--bad); font-weight: 600; min-height: 24px; margin: 8px 0; }

.empty { text-align: center; padding: 40px 10px; color: var(--ink-2); }
.empty .e { font-size: 48px; }
.result-big { font-size: 46px; font-weight: 800; text-align: center; margin: 8px 0; }
.wlist .item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.wlist .item:last-child { border-bottom: 0; }
.kbd-hint { display: none; }
@media (hover: hover) and (pointer: fine) { .kbd-hint { display: block; color: var(--muted); font-size: 13px; text-align: center; margin-top: 10px; } }

/* правки после проверки на iPhone-вьюпорте */
.actions .btn { padding: 0 10px; white-space: nowrap; }
.actions .btn.say { flex: none; width: 56px; }
body.study .toast { bottom: auto; top: calc(10px + var(--safe-t)); transform: translateX(-50%) translateY(-20px); }
body.study .toast.show { transform: translateX(-50%) translateY(0); }
.chart .ax { font-size: 9px; }
