/* ================= Tokens ================= */

:root {
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --bg: #faf7f2;
  --bg-glow-1: rgba(232, 72, 44, 0.10);
  --bg-glow-2: rgba(245, 176, 30, 0.12);
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --surface-hover: #fbf9f6;
  --header: rgba(250, 247, 242, 0.75);
  --text: #1c1a17;
  --text-2: #4a463f;
  --muted: #8a847a;
  --border: #e9e3d9;
  --border-strong: #d8d0c3;

  --accent: #e0442a;
  --accent-2: #f2a516;
  --accent-text: #ffffff;
  --accent-soft: #fdebe6;
  --accent-ink: #b8301a;
  --gradient: linear-gradient(135deg, #e8482c 0%, #f08a24 55%, #f5b21e 100%);

  --ok: #198754;
  --ok-soft: #e3f4ea;
  --bad: #d63a3a;
  --bad-soft: #fde7e7;
  --warn: #a86a00;
  --warn-soft: #fff2d2;

  --shadow-sm: 0 1px 2px rgba(60, 40, 20, 0.06), 0 1px 1px rgba(60, 40, 20, 0.04);
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.05), 0 8px 24px -8px rgba(60, 40, 20, 0.12);
  --shadow-lg: 0 2px 6px rgba(60, 40, 20, 0.06), 0 24px 48px -12px rgba(60, 40, 20, 0.22);
  --ring: 0 0 0 4px rgba(224, 68, 42, 0.18);

  --radius: 16px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  color-scheme: light;
}

/* The theme is always set on <html data-theme> by an inline script in index.html
   (saved choice, or the system preference on first visit). */
:root[data-theme="dark"] {
  --bg: #121110;
  --bg-glow-1: rgba(232, 72, 44, 0.14);
  --bg-glow-2: rgba(245, 176, 30, 0.07);
  --surface: #1b1a18;
  --surface-2: #24221f;
  --surface-hover: #211f1d;
  --header: rgba(18, 17, 16, 0.7);
  --text: #f2eee8;
  --text-2: #c9c3b9;
  --muted: #8d877d;
  --border: #2e2b27;
  --border-strong: #3d3934;

  --accent: #ff6a4d;
  --accent-text: #1a0d08;
  --accent-soft: rgba(255, 106, 77, 0.13);
  --accent-ink: #ff8a72;
  --gradient: linear-gradient(135deg, #ff5a3c 0%, #ff8f3a 55%, #ffbf3a 100%);

  --ok: #4fd18b;
  --ok-soft: rgba(79, 209, 139, 0.12);
  --bad: #ff6b6b;
  --bad-soft: rgba(255, 107, 107, 0.12);
  --warn: #f5c451;
  --warn-soft: rgba(245, 196, 81, 0.12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -8px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 24px 48px -12px rgba(0, 0, 0, 0.7);
  --ring: 0 0 0 4px rgba(255, 106, 77, 0.22);

  color-scheme: dark;
}

/* ================= Base ================= */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 16px/1.55 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background-color .4s var(--ease), color .4s var(--ease);
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 500px at 85% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(700px 500px at -10% 10%, var(--bg-glow-2), transparent 60%);
  transition: opacity .4s;
}
::selection { background: var(--accent); color: var(--accent-text); }
a { color: var(--accent-ink); }
h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.2; }
h1 { font-size: clamp(26px, 4vw, 34px); font-weight: 800; margin: 0; }
h2 { font-size: 20px; font-weight: 700; margin: 36px 0 14px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
kbd {
  font: 600 11px/1 var(--font); padding: 3px 6px; border-radius: 5px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; background: var(--surface); color: var(--muted);
}

/* ================= Header ================= */

header {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  background: var(--header);
  border-bottom: 1px solid var(--border);
  transition: background-color .4s, border-color .4s;
}
.header-inner {
  max-width: 1040px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 16px;
}
.logo {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text);
  font-weight: 800; font-size: 18px; letter-spacing: -0.02em;
}
.logo-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--gradient); color: #fff; font-size: 17px; font-weight: 800;
  box-shadow: 0 4px 14px -4px rgba(232, 72, 44, 0.6);
  transition: transform .5s var(--spring);
}
.logo:hover .logo-mark { transform: rotate(-8deg) scale(1.06); }
.logo small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: -2px; }

nav { position: relative; display: flex; gap: 2px; margin-left: auto; padding: 4px; background: var(--surface-2); border-radius: 12px; }
nav a {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: 9px; color: var(--text-2); text-decoration: none;
  font-weight: 600; font-size: 14px; transition: color .25s;
}
nav a:hover { color: var(--text); }
nav a.active { color: var(--text); }
nav .pill {
  position: absolute; z-index: 0; top: 4px; bottom: 4px; left: 0; width: 0;
  background: var(--surface); border-radius: 9px; box-shadow: var(--shadow-sm);
  transition: transform .45s var(--spring), width .45s var(--spring), opacity .2s;
}
.theme-toggle {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; display: grid; place-items: center;
  position: relative; overflow: hidden; transition: border-color .2s, transform .2s, background-color .4s;
}
.theme-toggle:hover { border-color: var(--border-strong); }
.theme-toggle:active { transform: scale(.92); }
.theme-toggle .icon { position: absolute; transition: transform .5s var(--spring), opacity .3s; }
.theme-toggle .sun { transform: rotate(90deg) scale(0); opacity: 0; }
:root[data-theme="dark"] .theme-toggle .sun { transform: none; opacity: 1; }
:root[data-theme="dark"] .theme-toggle .moon { transform: rotate(-90deg) scale(0); opacity: 0; }

/* ================= Layout ================= */

main { max-width: 1040px; margin: 0 auto; padding: 32px 20px 96px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.back {
  display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none;
  font-weight: 600; font-size: 14px; margin-bottom: 14px; transition: color .2s, gap .25s var(--ease);
}
.back:hover { color: var(--text); gap: 10px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm);
  transition: background-color .4s, border-color .4s;
}
.card + .card { margin-top: 14px; }
.stats > .card, .grid > .card { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }

/* staggered entrance */
.view > * { animation: rise .55s var(--ease) both; }
.view > *:nth-child(2) { animation-delay: .05s; }
.view > *:nth-child(3) { animation-delay: .1s; }
.view > *:nth-child(4) { animation-delay: .15s; }
.view > *:nth-child(5) { animation-delay: .2s; }
.view > *:nth-child(n+6) { animation-delay: .25s; }
.stagger > * { animation: rise .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms + 80ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade { from { opacity: 0; } }

/* ================= Buttons & inputs ================= */

button, .btn {
  font: 600 15px/1 var(--font); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: transform .2s var(--ease), box-shadow .25s var(--ease), background-color .2s, border-color .2s, color .2s, opacity .2s;
  -webkit-tap-highlight-color: transparent;
}
button:hover, .btn:hover { border-color: var(--border-strong); background: var(--surface-hover); }
button:active, .btn:active { transform: scale(.97); }
button:focus-visible, .btn:focus-visible, a:focus-visible { outline: none; box-shadow: var(--ring); }
button.primary, .btn.primary {
  background: var(--gradient); border: 0; color: #fff;
  box-shadow: 0 6px 18px -6px rgba(232, 72, 44, 0.55), inset 0 1px 0 rgba(255,255,255,.2);
}
button.primary:hover, .btn.primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -8px rgba(232, 72, 44, 0.65), inset 0 1px 0 rgba(255,255,255,.2); }
button.primary:active { transform: translateY(0) scale(.97); }
button.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-soft); border-color: transparent; }
button.danger.solid { background: var(--bad); color: #fff; border: 0; }
button.small { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
button.icon-btn { width: 34px; height: 34px; padding: 0; border-radius: 10px; }
button.large { height: 52px; padding: 0 28px; font-size: 16px; border-radius: 14px; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

input[type=text], input[type=search], textarea {
  font: 500 15px/1.4 var(--font); color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 12px; padding: 11px 14px; width: 100%;
  transition: border-color .2s, box-shadow .2s, background-color .4s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
textarea { min-height: 150px; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--muted); }
code { font-size: 13px; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); }

/* ================= Home ================= */

.hero {
  position: relative; overflow: hidden; border-radius: 24px; padding: 40px 36px;
  background: var(--gradient); color: #fff; box-shadow: var(--shadow-lg);
}
.hero h1 { font-size: clamp(28px, 5vw, 44px); color: #fff; max-width: 560px; }
.hero p { opacity: .92; max-width: 480px; margin: 12px 0 24px; font-size: 17px; }
.hero .btn { background: #fff; color: #1c1a17; border: 0; height: 48px; padding: 0 22px; box-shadow: 0 8px 20px -8px rgba(0,0,0,.35); }
.hero .btn:hover { transform: translateY(-2px); background: #fff; }
.hero .btn.glass { background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.45); backdrop-filter: blur(6px); box-shadow: none; }
.hero .btn.glass:hover { background: rgba(255,255,255,.28); }
.hero-deco {
  position: absolute; right: -20px; top: 50%; transform: translateY(-50%);
  font-size: 220px; font-weight: 800; line-height: 1; opacity: .13; letter-spacing: -0.06em;
  pointer-events: none; user-select: none; animation: float 8s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(calc(-50% - 12px)) rotate(-3deg); } }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 18px; }
.stat { padding: 18px 20px; }
.stat .value { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.stat .label { font-size: 13px; color: var(--muted); font-weight: 500; }

.tile {
  position: relative; display: flex; flex-direction: column; gap: 6px; color: inherit; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow-sm); overflow: hidden;
  transition: transform .35s var(--ease), box-shadow .35s var(--ease), border-color .25s, background-color .4s;
}
a.tile:hover, button.tile:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
a.tile:active { transform: translateY(-1px) scale(.99); }
.tile .title { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.tile .desc { color: var(--muted); font-size: 14px; }
.tile.disabled { opacity: .55; pointer-events: none; }
.tile-icon {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; margin-bottom: 10px;
  background: var(--accent-soft); color: var(--accent);
  transition: transform .5s var(--spring);
}
.tile:hover .tile-icon { transform: scale(1.1) rotate(-6deg); }
.tile-icon .icon { width: 22px; height: 22px; }
.tile .arrow {
  position: absolute; right: 20px; top: 22px; color: var(--muted); opacity: 0; transform: translateX(-6px);
  transition: opacity .25s, transform .35s var(--ease);
}
a.tile:hover .arrow { opacity: 1; transform: none; }
.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2);
}

/* ================= Groups ================= */

.group-tile .swatch {
  width: 46px; height: 46px; border-radius: 13px; margin-bottom: 10px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 19px; background: var(--g);
  box-shadow: 0 6px 16px -6px var(--g-shadow);
  transition: transform .5s var(--spring);
}
.group-tile:hover .swatch { transform: scale(1.08) rotate(-6deg); }
.group-tile .preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }
.new-tile {
  border: 2px dashed var(--border-strong); background: transparent; box-shadow: none;
  align-items: center; justify-content: center; min-height: 150px; color: var(--muted);
  cursor: pointer; font: 600 15px var(--font); height: auto;
}
.new-tile:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft) !important; transform: translateY(-4px); }
.new-tile .icon { width: 28px; height: 28px; transition: transform .4s var(--spring); }
.new-tile:hover .icon { transform: rotate(90deg); }

.sortable .group-tile { cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.drag-handle {
  position: absolute; top: 18px; right: 44px; width: 28px; height: 28px; display: grid; place-items: center;
  color: var(--muted); opacity: 0; touch-action: none; transition: opacity .2s;
}
.drag-handle .icon { stroke-width: 3; }
.group-tile:hover .drag-handle { opacity: 1; }
@media (hover: none) { .drag-handle { opacity: .8; top: 10px; right: 8px; width: 44px; height: 44px; } }
.group-tile.dragging {
  z-index: 10; cursor: grabbing; pointer-events: none; transition: none; animation: none;
  box-shadow: var(--shadow-lg); opacity: .95;
}

.empty {
  text-align: center; padding: 56px 20px; color: var(--muted);
  border: 2px dashed var(--border); border-radius: var(--radius);
}
.empty .big { font-size: 48px; margin-bottom: 8px; display: inline-block; animation: float-sm 4s ease-in-out infinite; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }
@keyframes float-sm { 50% { transform: translateY(-6px); } }

/* word list */
.add-bar { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; }
.word-list { list-style: none; margin: 0; padding: 0; }
.word {
  display: grid; grid-template-columns: 32px 1fr 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; border-radius: 12px; transition: background-color .2s;
}
.word + .word { border-top: 1px solid var(--border); }
.word:hover { background: var(--surface-hover); }
.word .n { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.word .es { font-weight: 600; }
.word .ru { color: var(--text-2); }
.word .actions { display: flex; gap: 4px; opacity: 0; transition: opacity .2s; }
.word:hover .actions, .word:focus-within .actions { opacity: 1; }
.word.editing { background: var(--surface-2); }
.word.editing input { padding: 7px 10px; }
.word.enter { animation: word-in .5s var(--spring); }
.word.leave { animation: word-out .3s var(--ease) forwards; }
@keyframes word-in { from { opacity: 0; transform: translateY(-8px) scale(.98); background: var(--accent-soft); } }
@keyframes word-out { to { opacity: 0; transform: translateX(24px); } }
@media (hover: none) { .word .actions { opacity: 1; } }

.list-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.list-head input { max-width: 260px; height: 38px; padding: 7px 12px; }

details.card summary {
  cursor: pointer; font-weight: 700; list-style: none; display: flex; align-items: center; gap: 10px;
}
details.card summary::-webkit-details-marker { display: none; }
details.card summary .chev { margin-left: auto; transition: transform .3s var(--ease); color: var(--muted); }
details[open].card summary .chev { transform: rotate(180deg); }
details.card .body { animation: rise .35s var(--ease); margin-top: 14px; }

/* ================= Test setup ================= */

.select-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.select-card {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer;
  border: 1.5px solid var(--border); border-radius: 14px; background: var(--surface);
  transition: border-color .2s, background-color .2s, transform .2s var(--ease), box-shadow .25s;
  user-select: none;
}
.select-card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow); }
.select-card input { position: absolute; opacity: 0; pointer-events: none; }
.select-card .swatch { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 800; background: var(--g); }
.select-card .name { font-weight: 600; line-height: 1.25; }
.select-card .cnt { font-size: 13px; color: var(--muted); }
.select-card .tick {
  margin-left: auto; width: 22px; height: 22px; border-radius: 7px; flex: none;
  border: 1.5px solid var(--border-strong); display: grid; place-items: center; color: #fff;
  transition: background-color .2s, border-color .2s;
}
.select-card .tick .icon { width: 14px; height: 14px; stroke-width: 3; transform: scale(0); transition: transform .35s var(--spring); }
.select-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.select-card:has(input:checked) .tick { background: var(--accent); border-color: var(--accent); }
.select-card:has(input:checked) .tick .icon { transform: scale(1); }
.select-card:has(input:focus-visible) { box-shadow: var(--ring); }

.seg { position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.seg label { position: relative; z-index: 1; padding: 9px 16px; cursor: pointer; text-align: center; font-weight: 600; font-size: 14px; color: var(--text-2); border-radius: 9px; transition: color .25s; white-space: nowrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { color: var(--text); }
.seg label:has(input:focus-visible) { box-shadow: var(--ring); }
.seg .thumb {
  position: absolute; z-index: 0; top: 4px; bottom: 4px; left: 4px; border-radius: 9px; background: var(--surface);
  box-shadow: var(--shadow-sm); transition: transform .45s var(--spring);
}

.start-bar {
  position: sticky; bottom: 16px; margin-top: 20px; z-index: 5;
  display: flex; align-items: center; gap: 14px; padding: 12px 12px 12px 20px;
  background: var(--header); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg);
}
.start-bar .count { font-weight: 600; }
.count-num { display: inline-block; }
.count-num.bump { animation: bump .4s var(--spring); }
@keyframes bump { 40% { transform: scale(1.25); color: var(--accent); } }

/* ================= Quiz ================= */

.quiz-wrap { max-width: 640px; margin: 0 auto; }
.quiz-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.quiz-top .progress { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; color: var(--text-2); white-space: nowrap; }
.bar { flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--gradient); border-radius: 99px; transition: width .6s var(--ease); }
.streak {
  display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 14px; color: var(--accent);
  padding: 4px 10px; border-radius: 99px; background: var(--accent-soft);
  transition: opacity .3s, transform .4s var(--spring);
}
.streak.hidden { opacity: 0; transform: scale(.6); }
.streak.pop { animation: bump .45s var(--spring); }

.quiz-card {
  text-align: center; padding: 44px 28px 32px; border-radius: 24px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  transition: border-color .3s, box-shadow .3s, background-color .4s;
}
.quiz-card.in { animation: card-in .5s var(--ease) both; }
.quiz-card.out { animation: card-out .22s ease-in forwards; }
@keyframes card-in { from { opacity: 0; transform: translateX(40px) rotate(1.5deg); } }
@keyframes card-out { to { opacity: 0; transform: translateX(-40px) rotate(-1.5deg); } }
.quiz-card.is-ok { border-color: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft), var(--shadow-lg); }
.quiz-card.is-bad { border-color: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft), var(--shadow-lg); animation: shake .45s var(--ease); }
.quiz-card.is-warn { border-color: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft), var(--shadow-lg); }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }

.quiz .dir { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.quiz .prompt { font-size: clamp(32px, 7vw, 52px); font-weight: 800; letter-spacing: -0.03em; margin: 14px 0 28px; line-height: 1.1; word-break: break-word; }
.quiz input[type=text] { font-size: 22px; font-weight: 600; text-align: center; max-width: 440px; height: 60px; border-radius: 16px; }
.quiz input[readonly] { background: var(--surface-2); }
.accents { margin: 12px 0 0; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.accents button { height: 34px; min-width: 38px; padding: 0 10px; font-size: 16px; border-radius: 10px; }
.quiz-actions { margin-top: 22px; display: flex; gap: 10px; justify-content: center; }
.feedback {
  margin: 22px auto 0; max-width: 440px; padding: 14px 16px; border-radius: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 12px; text-align: left; animation: pop .45s var(--spring);
}
.feedback .fb-icon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff; }
.feedback .fb-icon .icon { stroke-width: 3; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); } .feedback.ok .fb-icon { background: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); } .feedback.bad .fb-icon { background: var(--bad); }
.feedback.warn { background: var(--warn-soft); color: var(--warn); } .feedback.warn .fb-icon { background: var(--warn); }
.feedback strong { color: var(--text); }
@keyframes pop { from { opacity: 0; transform: scale(.85) translateY(6px); } }
.kbd-hint { margin-top: 18px; font-size: 13px; color: var(--muted); display: flex; gap: 6px; justify-content: center; align-items: center; }

/* pronunciation */
.say {
  margin: 14px auto 0; height: 44px; padding: 0 18px 0 8px; border-radius: 99px; gap: 10px;
  font-size: 17px; font-weight: 700; animation: pop .45s var(--spring) .1s both;
}
.say-icon {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); position: relative;
}
.say-icon .icon { width: 16px; height: 16px; }
.say.playing .say-icon::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent);
  animation: ripple 1s var(--ease) infinite;
}
@keyframes ripple { from { transform: scale(1); opacity: .8; } to { transform: scale(1.7); opacity: 0; } }

/* AI sentences */
.option-card { display: flex; align-items: center; gap: 16px; cursor: pointer; margin-top: 14px; transition: border-color .2s, background-color .2s; }
.option-card:hover { border-color: var(--border-strong); }
.option-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option-card .tile-icon { margin: 0; flex: none; }
.option-card .option-text { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.option-card .option-text .muted { font-size: 14px; }
.option-card.disabled { opacity: .6; cursor: not-allowed; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: inherit; }
.switch .knob {
  position: absolute; inset: 0; border-radius: 99px; background: var(--border-strong); pointer-events: none;
  transition: background-color .25s;
}
.switch .knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .35s var(--spring);
}
.switch input:checked + .knob { background: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(20px); }
.switch input:focus-visible + .knob { box-shadow: var(--ring); }

.sentence-card .prompt.sentence { font-size: clamp(22px, 4.5vw, 30px); font-weight: 700; line-height: 1.3; min-height: 80px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.sentence-card .prompt.ready { animation: pop .45s var(--spring); }
.skeleton {
  display: block; height: 22px; width: min(420px, 90%); border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
.skeleton.short { width: min(240px, 60%); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
textarea.answer-area {
  font: 600 19px/1.4 var(--font); text-align: center; max-width: 520px; min-height: 0; resize: none;
  border-radius: 16px; padding: 14px 16px; display: block; margin: 0 auto;
}
textarea.answer-area[readonly] { background: var(--surface-2); }
.quiz-card:is(.is-ok, .is-bad, .is-warn) textarea + .accents { opacity: 0; pointer-events: none; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.say.say-sentence { height: auto; min-height: 44px; padding: 7px 18px 7px 8px; font-size: 16px; max-width: 520px; text-align: left; line-height: 1.35; }
.feedback br + strong, .feedback strong { word-break: break-word; }

.sentence-score {
  display: inline-flex; align-items: center; gap: 8px; margin: -8px 0 22px; padding: 8px 14px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-ink); font-size: 14px; font-weight: 600;
}
.sentence-review { list-style: none; margin: 0; padding: 0; }
.sentence-review li { padding: 14px 4px; display: grid; gap: 4px; }
.sentence-review li + li { border-top: 1px solid var(--border); }
.sentence-review .src { font-weight: 700; }
.sentence-review .given { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.sentence-review .right { color: var(--ok); font-weight: 600; }

.hints { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; margin: -12px 0 20px; animation: rise .4s var(--ease) both; }
.hints[hidden] { display: none; }
.hints-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.hint-chip { font-size: 14px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }
.hint-chip b { color: var(--text); font-weight: 700; }
.pass-badge {
  display: inline-flex; align-items: center; gap: 3px; margin-left: 4px; padding: 1px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 700; background: var(--ok-soft); color: var(--ok); vertical-align: 1px;
}
.pass-badge .icon { width: 12px; height: 12px; stroke-width: 3; }

/* ================= Results ================= */

.result-card { text-align: center; padding: 40px 24px 32px; }
.ring { position: relative; width: 168px; height: 168px; margin: 0 auto 16px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.ring .track { stroke: var(--surface-2); }
.ring .val { stroke: url(#ringGrad); transition: stroke-dashoffset 1.4s var(--ease); }
.ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-size: 42px; font-weight: 800; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.verdict { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.result-stats { display: flex; justify-content: center; gap: 10px; margin: 16px 0 24px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 99px; font-weight: 600; font-size: 14px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.neutral { background: var(--surface-2); color: var(--text-2); }

.mistakes { list-style: none; margin: 0; padding: 0; }
.mistakes li { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; padding: 12px 4px; align-items: center; }
.mistakes li + li { border-top: 1px solid var(--border); }
.mistakes .head { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding-top: 0; }
.mistakes .given { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.mistakes .right { color: var(--ok); font-weight: 600; }

.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.warn-text { color: var(--warn); }

/* history */
.history-item { display: grid; grid-template-columns: 56px 1fr auto; gap: 16px; align-items: center; padding: 14px 6px; }
.history-item + .history-item { border-top: 1px solid var(--border); }
.mini-ring { width: 52px; height: 52px; position: relative; }
.mini-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.mini-ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.mini-ring .track { stroke: var(--surface-2); }
.mini-ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.history-item .title { font-weight: 600; }
.history-item .meta { font-size: 13px; color: var(--muted); }

/* ================= Modal & toast ================= */

dialog.modal {
  border: 1px solid var(--border); padding: 0; border-radius: 20px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.modal[open] { animation: modal-in .4s var(--spring); }
dialog.modal.closing { animation: modal-out .2s ease-in forwards; }
dialog.modal::backdrop { background: rgba(15, 10, 5, 0.45); backdrop-filter: blur(4px); animation: fade .3s; }
dialog.modal.closing::backdrop { animation: fade .2s reverse forwards; }
@keyframes modal-in { from { opacity: 0; transform: translateY(20px) scale(.95); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(10px) scale(.97); } }
.modal form { padding: 24px; }
.modal h3 { margin: 0 0 6px; font-size: 20px; font-weight: 800; }
.modal p { margin: 0 0 18px; color: var(--text-2); }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg);
  animation: toast-in .45s var(--spring);
}
.toast.out { animation: toast-out .25s ease-in forwards; }
.toast .icon { color: var(--ok); }
:root[data-theme="dark"] .toast .icon { color: #198754; }
@keyframes toast-in { from { opacity: 0; transform: translateY(20px) scale(.9); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(.95); } }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; }

/* theme switch: circular reveal via View Transitions where supported */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* ================= Account ================= */

body:not(.in-app) nav { display: none; }
body:not(.logged-in) .user-menu { display: none; }
body:not(.logged-in) .theme-toggle { margin-left: auto; }
.user-menu { position: relative; margin-left: auto; }
body.in-app .user-menu { margin-left: 0; }
.user-btn {
  display: flex; align-items: center; gap: 7px; height: 40px; padding: 0 10px 0 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 14px;
  cursor: pointer; list-style: none; user-select: none; transition: border-color .2s, background-color .4s;
}
.user-btn::-webkit-details-marker { display: none; }
.user-btn:hover { border-color: var(--border-strong); }
.user-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.user-btn .chev { width: 14px; height: 14px; color: var(--muted); transition: transform .3s var(--ease); }
.user-menu[open] .chev { transform: rotate(180deg); }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: pop .25s var(--ease);
}
.user-dropdown a, .user-dropdown button {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; height: 40px; padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; color: var(--text-2);
  font: 600 14px/1 var(--font); text-decoration: none; cursor: pointer;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--surface-2); color: var(--text); }
body:not(.is-admin) .admin-only { display: none; }

.app-mark { width: 46px; height: 46px; border-radius: 13px; font-size: 22px; margin-bottom: 10px; }
a.tile:hover .app-mark { transform: scale(1.08) rotate(-6deg); }

.add-user { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.user-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px 6px; }
.user-row + .user-row { border-top: 1px solid var(--border); }
.user-row .name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 700; }
.user-row .meta { font-size: 13px; color: var(--muted); }
.temp-password {
  display: block; padding: 14px; border-radius: 12px; text-align: center; word-break: break-all; user-select: all;
  font: 700 20px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .04em;
}

.auth-wrap { min-height: 60vh; display: grid; place-items: center; }
.auth-card { width: min(420px, 100%); text-align: center; padding: 36px 28px; box-shadow: var(--shadow-lg); }
.auth-card .tile-icon { margin: 0 auto 16px; }
.auth-card h1 { font-size: 24px; }
.auth-card p { margin: 8px 0 22px; }
.auth-card input { text-align: center; margin-bottom: 6px; }
.auth-error { min-height: 22px; font-size: 14px; font-weight: 600; color: var(--bad); margin-bottom: 8px; }
.shake { animation: shake .45s var(--ease); }
input[type=password] {
  font: 500 15px/1.4 var(--font); color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 12px; padding: 11px 14px; width: 100%;
  transition: border-color .2s, box-shadow .2s;
}

footer {
  max-width: 1040px; margin: 0 auto; padding: 24px 20px 40px; display: flex; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border);
}
main { padding-bottom: 56px; }

/* ================= Responsive ================= */

@media (max-width: 760px) {
  .header-inner { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .logo { flex: 1; min-width: 0; font-size: 16px; }
  .logo > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .logo small { display: none; }
  #user-name { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-btn { padding: 0 12px; }
  .user-btn .chev { display: none; }
  nav { order: 3; width: 100%; margin: 0; }
  nav a { flex: 1; justify-content: center; padding: 8px 6px; font-size: 13px; }
  body.in-app .user-menu { margin-left: auto; }
  main { padding: 22px 16px 80px; }
  .hero { padding: 28px 22px; border-radius: 20px; }
  .hero-deco { font-size: 140px; right: -30px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .add-bar { grid-template-columns: 1fr; }
  .word { grid-template-columns: 1fr auto; gap: 2px 12px; }
  .word .n { display: none; }
  .word .ru { grid-column: 1; grid-row: 2; font-size: 14px; }
  .word .actions { grid-column: 2; grid-row: 1 / span 2; }
  .word.editing { grid-template-columns: 1fr; }
  .seg { display: grid; width: 100%; }
  .seg label { padding: 9px 6px; font-size: 13px; white-space: normal; }
  .quiz-card { padding: 32px 18px 24px; }
  .mistakes li { grid-template-columns: 1fr 1fr; }
  .mistakes li > :first-child { grid-column: 1 / -1; font-weight: 600; }
  .mistakes .head { display: none !important; }
  .kbd-hint { display: none; }
}

.quiz-card:is(.is-ok, .is-bad, .is-warn) .accents { opacity: 0; pointer-events: none; transition: opacity .2s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
