/* v2 design: Telegram-like chat, settings-style lists, story-style progress.
   Light/dark follow Telegram's colorScheme (set as data-theme on <html>). */
:root {
  --bg: #EFEFF4;
  --surface: #FFFFFF;
  --text: #000000;
  --text-2: #1C1C1E;
  --hint: #6D6D72;
  --subtle: #3C3C43;
  --sep: #E3E3E8;
  --fill: #F2F2F7;
  --accent: #1F6FDB;
  --accent-grad: linear-gradient(135deg, #4FA3FF, #1F6FDB);
  --accent-soft: rgba(31, 111, 219, 0.12);
  --link-chip-bg: #EEF4FD;
  --glass: rgba(255, 255, 255, 0.8);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --wall: radial-gradient(circle at 12% 18%, #D6E6FF 0, rgba(214,230,255,0) 42%),
          radial-gradient(circle at 88% 38%, #EADCFB 0, rgba(234,220,251,0) 44%),
          radial-gradient(circle at 25% 82%, #D5F2E3 0, rgba(213,242,227,0) 48%),
          radial-gradient(circle at 90% 92%, #FFE8D6 0, rgba(255,232,214,0) 40%), #E8EDF5;
  --wall-dots: rgba(60, 80, 130, 0.10);
  --bubble-out: #EFFDDE;
  --bubble-out-meta: #2F7D2D;
  --service: rgba(36, 48, 72, 0.62);
  --tab-idle: #4A5260;
  --streak-bg: #FFF1E0;
  --streak-fg: #9A4A00;
  --study-base: #F3F4F8;
  --shadow: 0 2px 4px rgba(20,30,60,0.05), 0 14px 36px rgba(20,30,60,0.10);

  --serif: 'Source Serif 4', Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
}

:root[data-theme="dark"] {
  --bg: #0E0E10;
  --surface: #1C1C1F;
  --text: #FFFFFF;
  --text-2: #EDEDF0;
  --hint: #9A9AA1;
  --subtle: #C7C7CC;
  --sep: #2C2C30;
  --fill: #2A2A2E;
  --accent: #5AA2FF;
  --accent-soft: rgba(90, 162, 255, 0.16);
  --link-chip-bg: rgba(90, 162, 255, 0.16);
  --glass: rgba(28, 28, 31, 0.8);
  --glass-strong: rgba(28, 28, 31, 0.92);
  --wall: radial-gradient(circle at 12% 18%, #1C2B4D 0, rgba(28,43,77,0) 45%),
          radial-gradient(circle at 88% 38%, #2C2046 0, rgba(44,32,70,0) 45%),
          radial-gradient(circle at 25% 82%, #163428 0, rgba(22,52,40,0) 50%), #11151E;
  --wall-dots: rgba(255, 255, 255, 0.05);
  --bubble-out: #2B5278;
  --bubble-out-meta: #A9C9F0;
  --service: rgba(255, 255, 255, 0.16);
  --tab-idle: #B0B4BC;
  --streak-bg: rgba(255, 138, 0, 0.18);
  --streak-fg: #FFB561;
  --study-base: #0E0E10;
  --shadow: 0 2px 4px rgba(0,0,0,0.3), 0 14px 36px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
p, h1, h2, h3, blockquote { margin: 0; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.glass { background: var(--glass); backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%); }

#app {
  position: relative;
  height: var(--tg-viewport-height, 100dvh);
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.view { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Per-word color, set inline as --grad / --ink / --soft */
.avatar { border-radius: 50%; background: var(--grad); color: #FFFFFF; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.tinted { background: var(--soft); color: var(--ink); }
:root[data-theme="dark"] .tinted { background: color-mix(in srgb, var(--ink) 26%, var(--surface)); color: color-mix(in srgb, var(--ink) 45%, #FFFFFF); }
.quote { padding: 6px 10px; border-radius: 6px; border-left: 3px solid var(--ink); background: var(--soft); }
:root[data-theme="dark"] .quote { background: color-mix(in srgb, var(--ink) 20%, var(--surface)); border-left-color: color-mix(in srgb, var(--ink) 55%, #FFFFFF); }
.quote p { font-family: var(--serif); font-style: italic; line-height: 1.4; color: var(--subtle); }

.streak-chip { display: flex; align-items: center; gap: 4px; padding: 6px 10px 6px 8px; border-radius: 999px; background: var(--streak-bg); color: var(--streak-fg); font-size: 14px; font-weight: 700; flex: none; }
.streak-chip svg { width: 16px; height: 16px; }
.streak-chip.soft { background: var(--glass-strong); }

/* ---------- Chat (add word) ---------- */
.chat { background: var(--wall); }
.wallpaper { position: absolute; inset: 0; background-image: radial-gradient(var(--wall-dots) 1.2px, transparent 1.6px); background-size: 20px 20px; pointer-events: none; }
.chat-head { position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 14px 10px; border-bottom: 0.5px solid var(--sep); }
.bot-avatar { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #72D5FD, #2A9EF1); color: #FFFFFF; display: flex; align-items: center; justify-content: center; flex: none; }
.bot-avatar .icon { width: 20px; height: 20px; }
.chat-title { flex: 1; min-width: 0; }
.chat-title h1 { font-size: 17px; font-weight: 600; }
.chat-title p { margin-top: 1px; font-size: 13px; color: var(--accent); }

.messages { position: relative; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 10px 10px 8px; }
.messages > * { flex-shrink: 0; }
.messages > :first-child { margin-top: auto; }
.messages > .anim { animation: pop 0.2s ease-out; }
.service { align-self: center; margin: 4px 0; padding: 3px 10px; border-radius: 999px; background: var(--service); color: #FFFFFF; font-size: 13px; font-weight: 500; }
.bubble { box-shadow: 0 1px 1px rgba(0,0,0,0.08); }
.out { align-self: flex-end; max-width: 75%; padding: 7px 10px 6px 12px; border-radius: 18px 18px 6px 18px; background: var(--bubble-out); display: flex; align-items: flex-end; gap: 8px; }
.out .text { font-size: 16px; overflow-wrap: anywhere; }
.meta-time { display: flex; align-items: center; gap: 2px; font-size: 11px; color: var(--bubble-out-meta); flex: none; }
.meta-time svg { width: 16px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.in { align-self: flex-start; max-width: 88%; padding: 10px 14px; border-radius: 18px 18px 18px 6px; background: var(--surface); }
.in p { font-size: 15px; line-height: 1.4; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }

.compact { align-self: flex-start; max-width: 88%; padding: 8px 12px 8px 8px; border-radius: 18px 18px 18px 6px; background: var(--surface); display: flex; align-items: center; gap: 10px; border: 0; text-align: left; }
.compact .avatar { width: 32px; height: 32px; font-size: 15px; }
.compact .line { font-size: 15px; line-height: 1.3; }
.compact .w { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.compact .status { margin-top: 2px; display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--hint); }
.compact .status.in-deck { color: #2C7D3A; }
:root[data-theme="dark"] .compact .status.in-deck { color: #7FD66B; }
.compact .status svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

.card-msg { align-self: flex-start; width: min(340px, 92%); display: flex; flex-direction: column; gap: 4px; }
.card-msg article { background: var(--surface); border-radius: 18px 18px 18px 6px; padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head .avatar { width: 42px; height: 42px; font-size: 19px; }
.card-head h2 { font-family: var(--serif); font-size: 25px; font-weight: 600; line-height: 1.1; overflow-wrap: anywhere; }
.card-head .meta { margin-top: 3px; font-size: 13px; color: var(--hint); }
.card-head > div { flex: 1; min-width: 0; }
.speak { width: 38px; height: 38px; border: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; }
.speak .icon { width: 18px; height: 18px; }
.card-msg .ru { font-size: 20px; font-weight: 700; line-height: 1.25; }
.card-msg .def { font-size: 15px; line-height: 1.4; color: var(--text-2); }
.card-msg .quote p { font-size: 15px; }
.card-msg .more { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; line-height: 1.4; color: var(--text-2); }
.card-msg .more i { color: var(--hint); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.link-chip { padding: 4px 10px; border: 0; border-radius: 999px; background: var(--link-chip-bg); color: var(--accent); font-size: 13px; font-weight: 500; }
.link-chip.ant { background: transparent; border: 1px dashed var(--hint); color: var(--subtle); }
.card-msg .time { margin-top: -4px; align-self: flex-end; font-size: 11px; color: var(--hint); }
.inline-kb { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.inline-kb button { height: 40px; border: 0; border-radius: 12px; background: var(--service); color: #FFFFFF; font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 6px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.inline-kb button:disabled { opacity: 0.85; }
.inline-kb svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.typing { display: flex; align-items: center; gap: 4px; padding: 12px 16px; }
.typing-word { margin-right: 6px; font-family: var(--serif); font-size: 16px; font-weight: 600; }
.mnemonic { font-size: 14px; line-height: 1.4; padding: 8px 10px; border-radius: 10px; background: var(--fill); color: var(--text-2); }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--hint); animation: blink 1s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.composer-wrap { position: relative; padding: 6px 10px calc(96px + var(--safe-bottom)); transition: padding 0.15s; }
body.kb-open .composer-wrap { padding-bottom: calc(10px + var(--safe-bottom)); }
.composer { border-radius: 22px; box-shadow: 0 2px 12px rgba(30,40,70,0.10); overflow: hidden; background: var(--glass-strong); }
.preview { display: flex; align-items: center; gap: 10px; padding: 10px 14px 8px; border-bottom: 0.5px solid var(--sep); color: var(--accent); }
.preview .icon { width: 20px; height: 20px; }
.preview-body { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 8px; }
.preview-title { font-size: 13px; font-weight: 600; }
.preview-text { margin-top: 1px; font-size: 15px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview.loading .preview-title::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: currentColor; animation: blink 1s infinite; vertical-align: middle; }
.composer-row { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px; margin: 0; }
.composer-row textarea { flex: 1; min-width: 0; height: 40px; max-height: 120px; padding: 9px 0; border: 0; outline: none; resize: none; background: transparent; font: inherit; font-size: 17px; line-height: 22px; color: var(--text); }
.composer-row textarea::placeholder { color: var(--hint); }
.composer-row { align-items: flex-end; }
.preview { cursor: pointer; }
.send-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--accent-grad); color: #FFFFFF; display: flex; align-items: center; justify-content: center; flex: none; transition: transform 0.12s, opacity 0.12s; }
.send-btn .icon { width: 20px; height: 20px; stroke-width: 2.4; }
.send-btn:disabled { background: var(--fill); color: var(--hint); }
.send-btn:not(:disabled):active { transform: scale(0.92); }

/* ---------- Deck ---------- */
.deck-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: calc(100px + var(--safe-bottom)); }
.hero { position: relative; overflow: hidden; padding: calc(18px + var(--safe-top)) 20px 52px; background: linear-gradient(140deg, #3D6CF0 0%, #5A55EC 55%, #7B4AE8 100%); color: #FFFFFF; display: flex; flex-direction: column; gap: 18px; }
.hero-deco { position: absolute; border-radius: 50%; pointer-events: none; }
.hero-deco.one { width: 220px; height: 220px; right: -70px; top: -80px; background: rgba(255,255,255,0.10); }
.hero-deco.two { width: 140px; height: 140px; left: -50px; bottom: -60px; background: rgba(255,255,255,0.08); }
.hero-top { position: relative; }
.hero h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; }
.hero-streak { position: relative; display: flex; align-items: center; gap: 14px; }
.flame-badge { width: 56px; height: 56px; border-radius: 50%; background: #FFFFFF; display: flex; align-items: center; justify-content: center; flex: none; box-shadow: 0 6px 18px rgba(20,20,80,0.25); }
.flame-badge svg { width: 32px; height: 32px; }
.flame-badge.off svg { filter: grayscale(1); opacity: 0.45; }
.streak-title { font-size: 24px; font-weight: 700; }
.streak-sub { margin-top: 2px; font-size: 14px; line-height: 1.35; }
.week { position: relative; list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.week li { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.week .day { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,0.14); color: #4B44D6; display: flex; align-items: center; justify-content: center; }
.week .day.done { background: #FFFFFF; }
.week .day.today { border: 2px dashed rgba(255,255,255,0.9); }
.week .day.done.today { border: 0; }
.week .day svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

.deck-body { position: relative; margin-top: -30px; padding: 0 16px; display: flex; flex-direction: column; gap: 8px; }
.summary { background: var(--surface); border-radius: 20px; padding: 14px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; }
.ring { width: 58px; height: 58px; flex: none; }
.ring circle { fill: none; stroke-width: 7; }
.ring-track { stroke: color-mix(in srgb, #5A55EC 15%, var(--surface)); }
.ring-value { stroke: #5A55EC; stroke-linecap: round; stroke-dasharray: 0 150.8; transition: stroke-dasharray 0.5s ease; }
.ring text { font-size: 13px; font-weight: 700; fill: var(--text); font-family: var(--sans); }
.summary-text { flex: 1; min-width: 0; }
.summary-title { font-size: 17px; font-weight: 700; }
.summary-sub { margin-top: 2px; font-size: 14px; color: var(--hint); }
.pill-btn { height: 40px; padding: 0 18px; border: 0; border-radius: 20px; background: var(--accent-grad); color: #FFFFFF; font-size: 15px; font-weight: 700; flex: none; }
.pill-btn:disabled { background: var(--fill); color: var(--hint); }

.group-title { margin: 10px 16px 2px; font-size: 13px; font-weight: 500; letter-spacing: 0.3px; text-transform: uppercase; color: var(--hint); }
.group { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 14px; overflow: hidden; }
.group:empty { display: none; }
.group-row { width: 100%; min-height: 46px; border: 0; background: transparent; padding: 0 0 0 14px; display: flex; align-items: center; gap: 12px; text-align: left; }
.group-row[aria-pressed="true"] { background: var(--accent-soft); }
.group-row .tile { width: 30px; height: 30px; border-radius: 8px; color: #FFFFFF; display: flex; align-items: center; justify-content: center; flex: none; }
.group-row .tile .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.group-row .label, .group-row .value { min-height: 46px; display: flex; align-items: center; font-size: 17px; }
.group-row .label { flex: 1; }
.group-row .value { gap: 4px; padding-right: 12px; color: var(--hint); }
.group-row .value svg { width: 14px; height: 14px; fill: none; stroke: var(--hint); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0.6; }
.group li + li .label, .group li + li .value { border-top: 0.5px solid var(--sep); }

.search { margin-top: 10px; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; background: var(--surface); border-radius: 12px; }
.search .icon { width: 18px; height: 18px; color: var(--hint); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font: inherit; font-size: 16px; color: var(--text); }
.search input::placeholder { color: var(--hint); }
.search input::-webkit-search-cancel-button { display: none; }

.word-row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 0 14px; border: 0; background: transparent; text-align: left; }
.word-row .avatar { width: 42px; height: 42px; font-size: 18px; }
.word-row .main { flex: 1; min-width: 0; min-height: 60px; display: flex; flex-direction: column; justify-content: center; }
.words li + li .main { border-top: 0.5px solid var(--sep); }
.word-row .w { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.word-row .t { margin-top: 1px; font-size: 14px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { flex: none; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.due { background: #FFF1E0; color: #9A4A00; }
.pill.new { background: #E3F2FD; color: #1769B5; }
.pill.learning { background: #ECEBFF; color: #4B44D6; }
.pill.learned { background: #E8F7E4; color: #2C7D3A; }
:root[data-theme="dark"] .pill.due { background: rgba(255,138,0,0.18); color: #FFB561; }
:root[data-theme="dark"] .pill.new { background: rgba(42,158,241,0.2); color: #8CCBFF; }
:root[data-theme="dark"] .pill.learning { background: rgba(102,95,255,0.24); color: #B9B5FF; }
:root[data-theme="dark"] .pill.learned { background: rgba(84,203,104,0.2); color: #8FE39D; }
.word-detail { padding: 0 14px 14px 68px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.45; color: var(--text-2); }
.word-detail .meta { font-size: 13px; color: var(--hint); }
.word-detail .quote p { font-size: 15px; }
.word-detail .actions { display: flex; gap: 16px; }
.text-btn { border: 0; background: transparent; padding: 6px 0; font-size: 15px; font-weight: 600; color: var(--accent); }
.text-btn.danger { margin-left: auto; color: #E5484D; }
.empty { padding: 28px 16px; text-align: center; color: var(--hint); font-size: 15px; line-height: 1.45; }

/* ---------- Study ---------- */
.study { background: linear-gradient(180deg, var(--soft, var(--fill)) 0%, var(--study-base) 62%); transition: background 0.3s; }
:root[data-theme="dark"] .study { background: linear-gradient(180deg, color-mix(in srgb, var(--ink, #333) 30%, var(--study-base)) 0%, var(--study-base) 62%); }
.study-head { padding: calc(12px + var(--safe-top)) 16px 6px; display: flex; flex-direction: column; gap: 12px; }
.segments { display: flex; gap: 4px; }
.segments span { flex: 1; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--text) 12%, transparent); transition: background 0.2s; }
.segments span.done { background: var(--accent); }
.segments span.current { background: color-mix(in srgb, var(--accent) 45%, transparent); }
.study-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.round-btn { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--glass-strong); color: var(--subtle); display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.round-btn .icon { width: 16px; height: 16px; stroke-width: 2.6; }
.study-counter { font-size: 15px; font-weight: 600; }
.study-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.stack { position: relative; flex: 1; min-height: 0; margin-top: 8px; }
.stack .ghost { position: absolute; border-radius: 28px; pointer-events: none; }
.stack .ghost.one { left: 40px; right: 40px; top: 0; bottom: 28px; background: color-mix(in srgb, var(--surface) 45%, transparent); }
.stack .ghost.two { left: 28px; right: 28px; top: 8px; bottom: 20px; background: color-mix(in srgb, var(--surface) 72%, transparent); }
.flashcard { position: absolute; left: 16px; right: 16px; top: 18px; bottom: 10px; border: 0; border-radius: 28px; background: var(--surface); box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; text-align: left; overflow-y: auto; animation: cardIn 0.22s ease-out; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
.flashcard .tile-letter { width: 44px; height: 44px; border-radius: 14px; background: var(--grad); color: #FFFFFF; font-size: 20px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.front-top { display: flex; align-items: center; gap: 10px; }
.pos-chip { padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.front-word { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 12px 0; }
.front-word .w { font-family: var(--serif); font-size: 48px; font-weight: 600; letter-spacing: -0.5px; line-height: 1.05; overflow-wrap: anywhere; }
.front-word .ipa { font-size: 17px; color: var(--hint); }
.flip-hint { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px; color: var(--hint); }
.flip-hint .icon { width: 16px; height: 16px; }
.back-top { display: flex; align-items: center; gap: 12px; }
.back-top .w { font-family: var(--serif); font-size: 28px; font-weight: 600; line-height: 1.05; overflow-wrap: anywhere; }
.back-top .meta { margin-top: 3px; font-size: 14px; color: var(--hint); }
.back-divider { height: 1px; background: var(--sep); margin: 16px 0; flex: none; }
.back-fields { display: flex; flex-direction: column; gap: 14px; }
.back-fields .ru { font-size: 26px; font-weight: 800; line-height: 1.2; letter-spacing: -0.3px; }
.back-fields .def { font-size: 17px; line-height: 1.45; color: var(--text-2); }
.back-fields .quote { padding: 8px 12px; border-radius: 8px; }
.back-fields .quote p { font-size: 16px; }
.syn-chip { padding: 5px 11px; border-radius: 999px; background: var(--fill); font-size: 14px; color: var(--text-2); }
.study-foot { padding: 12px 16px calc(24px + var(--safe-bottom)); }
.big-btn { width: 100%; height: 56px; border: 0; border-radius: 16px; background: var(--accent-grad); color: #FFFFFF; font-size: 17px; font-weight: 700; box-shadow: 0 8px 20px rgba(31,111,219,0.30); display: flex; align-items: center; justify-content: center; text-decoration: none; }
.big-btn.plain { background: var(--surface); color: var(--text); box-shadow: none; font-weight: 600; }
.ratings { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.rate { height: 64px; border: 0; border-radius: 16px; color: #FFFFFF; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transition: transform 0.1s; }
.rate:active { transform: scale(0.95); }
.rate b { font-size: 15px; }
.rate span { font-size: 12px; font-weight: 600; }
.rate.again { background: #D93A3F; box-shadow: 0 6px 14px rgba(217,58,63,0.28); }
.rate.hard { background: #C25E00; box-shadow: 0 6px 14px rgba(194,94,0,0.28); }
.rate.good { background: #2468D6; box-shadow: 0 6px 14px rgba(36,104,214,0.30); }
.rate.easy { background: #23843F; box-shadow: 0 6px 14px rgba(35,132,63,0.28); }
.done-screen { position: relative; flex: 1; padding: 0 24px calc(36px + var(--safe-bottom)); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.done-screen .confetti { position: absolute; border-radius: 3px; animation: fall 0.9s ease-out both; }
@keyframes fall { from { opacity: 0; transform: translateY(-30px) rotate(0); } }
.done-badge { width: 112px; height: 112px; border-radius: 50%; background: linear-gradient(135deg, #FFB547, #FF6A3D); display: flex; align-items: center; justify-content: center; box-shadow: 0 16px 36px rgba(255,106,61,0.35); animation: pop 0.4s ease-out; }
.done-badge svg { width: 60px; height: 60px; }
.done-badge.calm { background: linear-gradient(135deg, #7FD66B, #3DB257); box-shadow: 0 16px 36px rgba(61,178,87,0.3); }
.done-badge .icon { width: 56px; height: 56px; color: #FFFFFF; stroke-width: 2.6; }
.done-screen h1 { margin-top: 6px; font-size: 30px; font-weight: 800; letter-spacing: -0.4px; }
.done-screen p { font-size: 16px; line-height: 1.45; color: var(--subtle); }
.done-screen .buttons { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 14px; }

/* ---------- Tab bar ---------- */
.tabbar { position: absolute; z-index: 5; left: 20px; right: 20px; bottom: calc(18px + var(--safe-bottom)); height: 64px; padding: 6px; border-radius: 32px; box-shadow: 0 8px 30px rgba(30,40,70,0.16), inset 0 0 0 0.5px rgba(0,0,0,0.06); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
body.kb-open .tabbar { display: none; }
.tab { position: relative; border: 0; border-radius: 26px; background: transparent; color: var(--tab-idle); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; transition: background 0.15s, color 0.15s; }
.tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.tab .icon { width: 24px; height: 24px; }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #E5484D; color: #FFFFFF; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.toast { position: absolute; z-index: 10; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: rgba(28,28,30,0.92); color: #FFFFFF; font-size: 14px; }
