:root {
  --blue: #4255ff;
  --blue-2: #6a4dff;
  --blue-dark: #2c3ddb;
  --cyan: #51cfff;
  --yellow: #ffcd1f;
  --green: #16a87a;
  --red: #ef4660;
  --purple: #a533ff;
  --ink: #181b28;
  --gray-600: #5a6375;
  --gray-400: #96a0b3;
  --gray-200: #dde2ec;
  --gray-100: #eef1f6;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f7f8fd;
  --card-grad: linear-gradient(135deg, #f3f5ff, #eaf6ff);
  --ok-bg: #dff5ec; --ok-fg: #0e8a5f;
  --bad-bg: #fde9ed; --bad-fg: #cf2e4a;
  --note-bg: #fff6dd; --note-border: #f2dc8e; --note-fg: #8a6b00;
  --info-bg: #e9edff; --info-border: #c9d2ff; --info-fg: #3a4cd6;
  --topbar-bg: rgba(255,255,255,.82);
  --glow-a: rgba(66,85,255,.10);
  --glow-b: rgba(81,207,255,.12);
  --glow-c: rgba(165,51,255,.07);
  --shadow: 0 1px 3px rgba(24,27,40,.05), 0 8px 24px rgba(24,27,40,.06);
  --shadow-lg: 0 2px 6px rgba(24,27,40,.06), 0 18px 48px rgba(24,27,40,.14);
  --shadow-blue: 0 10px 26px rgba(66,85,255,.28);
  font-size: 15px;
}
:root[data-theme="dark"] {
  --blue: #6478ff;
  --blue-2: #8b74ff;
  --blue-dark: #7c8dff;
  --cyan: #4cc7f5;
  --yellow: #ffd23f;
  --green: #2bd6a2;
  --red: #ff5d73;
  --purple: #b46bff;
  --ink: #e9ecf6;
  --gray-600: #9aa4bd;
  --gray-400: #6d7891;
  --gray-200: #2a3145;
  --gray-100: #222a3b;
  --bg: #0d1017;
  --surface: #151a25;
  --surface-2: #1b2130;
  --card-grad: linear-gradient(135deg, #1c2334, #1a2a3a);
  --ok-bg: #103527; --ok-fg: #3ce0a5;
  --bad-bg: #3c1a22; --bad-fg: #ff7d8f;
  --note-bg: #2d2612; --note-border: #54471c; --note-fg: #f0cd5c;
  --info-bg: #1b2340; --info-border: #35407a; --info-fg: #9dacff;
  --topbar-bg: rgba(13,16,23,.82);
  --glow-a: rgba(100,120,255,.14);
  --glow-b: rgba(76,199,245,.10);
  --glow-c: rgba(180,107,255,.09);
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 2px 6px rgba(0,0,0,.35), 0 18px 48px rgba(0,0,0,.5);
  --shadow-blue: 0 10px 26px rgba(100,120,255,.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 500px at 85% -10%, var(--glow-b), transparent 60%),
    radial-gradient(900px 480px at -10% 8%, var(--glow-a), transparent 55%),
    radial-gradient(800px 500px at 60% 110%, var(--glow-c), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.45;
  transition: background .25s ease, color .25s ease;
  display: flex; flex-direction: column; min-height: 100vh;
}
main.container { flex: 1; width: 100%; }
a { color: var(--blue); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }
::selection { background: rgba(66,85,255,.22); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); border: 2px solid transparent; background-clip: content-box; }

.ic { display: inline-block; flex-shrink: 0; vertical-align: -3px; }

.container { max-width: 1120px; margin: 0 auto; padding: 18px 18px 48px; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--topbar-bg); backdrop-filter: blur(12px) saturate(1.4);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 12px;
  padding: 9px 18px;
}
.logo { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 1.18rem; color: var(--ink); letter-spacing: -.02em; }
.logo-img { height: 42px; width: auto; display: block; }
.f-brand .logo-img { height: 54px; }
.topbar .spacer { flex: 1; }
.topbar .nav-link { color: var(--gray-600); font-weight: 600; padding: 7px 11px; border-radius: 9px; font-size: .92rem; display: inline-flex; align-items: center; gap: 6px; }
.topbar .nav-link:hover { color: var(--ink); background: var(--gray-100); }
.user-chip { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .95rem; }
.user-chip .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--blue-2)); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 700;
}
.user-chip .avatar.student { background: linear-gradient(135deg, var(--green), #2bbf8f); }
.role-pill { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 999px; background: var(--info-bg); color: var(--info-fg); }
.role-pill.student { background: var(--ok-bg); color: var(--ok-fg); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: none; border-radius: 10px; padding: 9px 16px;
  font-weight: 700; font-size: .92rem; transition: transform .12s ease, box-shadow .15s ease, background .15s, color .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--blue-2)); color: #fff;
  box-shadow: var(--shadow-blue);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 12px 30px rgba(66,85,255,.38); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--gray-200); box-shadow: 0 1px 2px rgba(24,27,40,.05); }
.btn-secondary:hover:not(:disabled) { border-color: var(--gray-400); background: var(--gray-100); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); color: var(--ink); }
.btn-danger { background: var(--bad-bg); color: var(--bad-fg); border: 1px solid transparent; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-success { background: linear-gradient(135deg, var(--green), #2bbf8f); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: .82rem; border-radius: 8px; }
.btn-lg { padding: 13px 26px; font-size: 1.02rem; border-radius: 12px; }
.btn-icon {
  padding: 7px; border-radius: 9px; background: transparent; border: none;
  color: var(--gray-600); display: inline-flex; align-items: center; justify-content: center; transition: background .15s;
}
.btn-icon:hover { background: var(--gray-100); color: var(--ink); }

/* ---------- hero / landing ---------- */
.hero { padding: 26px 0 8px; }
.hero-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 34px; align-items: center; }
.hero-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--info-bg); border: 1px solid var(--info-border); color: var(--info-fg);
  border-radius: 999px; padding: 6px 13px; font-size: .82rem; font-weight: 700; margin-bottom: 16px;
}
.hero h1 { font-size: 2.75rem; line-height: 1.12; letter-spacing: -.025em; font-weight: 800; }
.hero h1 .grad {
  background: linear-gradient(92deg, var(--blue) 10%, var(--purple) 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p.sub { font-size: 1.08rem; color: var(--gray-600); max-width: 520px; margin: 16px 0 24px; }
.hero .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero-stats { display: flex; gap: 26px; margin-top: 30px; }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats b { font-size: 1.35rem; font-weight: 800; color: var(--ink); letter-spacing: -.02em; }
.hero-stats span { font-size: .82rem; color: var(--gray-600); }
.hero-visual { position: relative; height: 320px; }
.mock-card {
  position: absolute; width: 280px; height: 170px; border-radius: 18px;
  box-shadow: var(--shadow-lg); background: var(--surface); border: 1px solid var(--gray-200);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
.mock-front { left: 50%; top: 26px; transform: translateX(-50%) rotate(1.5deg); padding: 16px; text-align: center; }
.mock-back-1 { left: calc(50% - 40px); top: 34px; transform: translateX(-50%) rotate(-6deg); background: var(--surface-2); }
.mock-back-2 { left: calc(50% - 66px); top: 40px; transform: translateX(-50%) rotate(-11deg); background: var(--surface-2); opacity: .7; }
.mock-side { font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--gray-400); }
.mock-word { font-size: 1.28rem; font-weight: 800; letter-spacing: -.01em; }
.mock-actions { display: flex; gap: 8px; }
.mock-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px;
  font-size: .82rem; font-weight: 700;
}
.mock-btn.ok { background: var(--ok-bg); color: var(--ok-fg); }
.mock-btn.bad { background: var(--bad-bg); color: var(--bad-fg); }
.mock-note {
  position: absolute; left: calc(50% + 118px); top: 128px; width: 210px;
  background: var(--surface); border: 1px solid var(--gray-200); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 11px 13px; font-size: .82rem; color: var(--gray-600);
}
.mock-note-head { display: flex; align-items: center; gap: 6px; font-weight: 800; color: var(--ink); margin-bottom: 5px; font-size: .85rem; }
.mock-note p { font-style: italic; }

.feature-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 40px; }
.feature-card {
  background: var(--surface); border: 1px solid var(--gray-200); border-radius: 16px; padding: 20px;
  box-shadow: var(--shadow); transition: transform .18s ease, box-shadow .18s ease;
}
.feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.feature-icon {
  width: 46px; height: 46px; border-radius: 13px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--info-bg); color: var(--info-fg);
}
.feature-icon.green { background: var(--ok-bg); color: var(--ok-fg); }
.feature-icon.purple { background: #f3e9ff; color: var(--purple); }
:root[data-theme="dark"] .feature-icon.purple { background: #2c2140; }
.feature-card h3 { margin: 12px 0 5px; font-size: 1.02rem; letter-spacing: -.01em; }
.feature-card p { color: var(--gray-600); font-size: .89rem; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--gray-200); background: var(--surface-2); margin-top: 40px; }
.footer-inner {
  max-width: 1120px; margin: 0 auto; padding: 30px 18px 22px;
  display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 22px;
}
.f-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.f-brand b { font-size: 1.15rem; letter-spacing: -.02em; }
.f-brand p { color: var(--gray-600); font-size: .9rem; line-height: 1.5; }
.f-col { display: flex; flex-direction: column; gap: 8px; }
.f-col h5 { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; color: var(--gray-400); margin-bottom: 4px; }
.f-col a { color: var(--gray-600); font-size: .92rem; }
.f-col a:hover { color: var(--blue); }
.footer-bottom {
  border-top: 1px solid var(--gray-200); padding: 13px 18px; text-align: center;
  color: var(--gray-400); font-size: .82rem;
}

/* ---------- auth ---------- */
.auth-wrap { max-width: 430px; margin: 26px auto; background: var(--surface); border: 1px solid var(--gray-200); border-radius: 18px; box-shadow: var(--shadow); padding: 26px; }
.auth-wrap h2 { margin-bottom: 2px; letter-spacing: -.02em; }
.auth-wrap .sub { color: var(--gray-600); font-size: .9rem; margin-bottom: 16px; }
.role-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.role-card { border: 2px solid var(--gray-200); border-radius: 13px; padding: 13px; text-align: center; cursor: pointer; transition: .15s; background: var(--surface); color: var(--ink); }
.role-card:hover { border-color: var(--blue); transform: translateY(-1px); }
.role-card.selected { border-color: var(--blue); background: var(--info-bg); box-shadow: 0 6px 18px rgba(66,85,255,.15); }
.role-card .ri {
  width: 42px; height: 42px; margin: 0 auto 7px; border-radius: 50%;
  background: var(--gray-100); color: var(--gray-600); display: flex; align-items: center; justify-content: center;
}
.role-card.selected .ri { background: linear-gradient(135deg, var(--blue), var(--blue-2)); color: #fff; }
.role-card b { display: block; font-size: .93rem; }
.role-card small { color: var(--gray-600); display: block; margin-top: 2px; font-size: .78rem; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .82rem; font-weight: 700; color: var(--gray-600); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--gray-200); border-radius: 10px;
  background: var(--surface); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(66,85,255,.15); }
.form-error { background: var(--bad-bg); color: var(--bad-fg); border-radius: 10px; padding: 9px 12px; margin-bottom: 12px; font-size: .88rem; font-weight: 600; }
.auth-switch { text-align: center; margin-top: 14px; font-size: .9rem; color: var(--gray-600); }
.note-box { background: var(--note-bg); border: 1px solid var(--note-border); color: var(--note-fg); border-radius: 10px; padding: 9px 12px; font-size: .86rem; margin-bottom: 14px; }
.info-box { background: var(--info-bg); border: 1px solid var(--info-border); color: var(--info-fg); border-radius: 10px; padding: 9px 12px; font-size: .86rem; margin-bottom: 14px; display: flex; align-items: baseline; gap: 7px; }

/* ---------- library / dashboard ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.55rem; letter-spacing: -.02em; }
.lib-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.lib-search {
  flex: 1 1 260px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1.5px solid var(--gray-200); border-radius: 12px; padding: 9px 13px;
  color: var(--gray-400); transition: border-color .15s, box-shadow .15s;
}
.lib-search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(66,85,255,.14); }
.lib-search input { flex: 1; border: none; background: transparent; color: var(--ink); outline: none; font-size: .95rem; }
.lib-sorts { display: flex; gap: 8px; }
.set-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.set-card {
  background: var(--surface); border: 1px solid var(--gray-200); border-radius: 16px;
  box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 8px;
  transition: transform .16s ease, box-shadow .16s ease;
}
.set-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.set-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.set-card h3 { font-size: 1rem; letter-spacing: -.01em; }
.set-card .meta { color: var(--gray-600); font-size: .82rem; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.set-card .meta .ic { color: var(--gray-400); }
.set-card .lang-line { font-weight: 700; color: var(--gray-600); }
.set-card .card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.badge { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.badge.draft { background: var(--gray-100); color: var(--gray-600); }
.badge.pub { background: var(--ok-bg); color: var(--ok-fg); }
.empty-state { text-align: center; padding: 48px 16px; color: var(--gray-600); }
.empty-state .big-ic {
  width: 66px; height: 66px; margin: 0 auto 12px; border-radius: 19px;
  background: var(--gray-100); color: var(--gray-400); display: flex; align-items: center; justify-content: center;
}
.empty-state h2 { color: var(--ink); margin-bottom: 6px; letter-spacing: -.01em; }

/* ---------- set editor ---------- */
.editor-card { background: var(--surface); border: 1px solid var(--gray-200); border-radius: 16px; box-shadow: var(--shadow); padding: 17px; margin-bottom: 14px; }
.editor-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.editor-row > * { flex: 1 1 200px; }
.term-row {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 9px; align-items: start;
  background: var(--surface); border: 1px solid var(--gray-200); border-radius: 14px; box-shadow: var(--shadow); padding: 13px; margin-bottom: 10px;
}
.term-row textarea, .term-row input {
  width: 100%; padding: 9px 11px; border: 1.5px solid var(--gray-200); border-radius: 10px; resize: vertical;
  background: var(--surface); color: var(--ink); transition: border-color .15s;
}
.term-row textarea:focus, .term-row input:focus { outline: none; border-color: var(--blue); }
.suggest-area { grid-column: 1 / -1; padding: 6px 2px 0; }
.suggest-chips { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 7px; }
.chip {
  border: 1.5px solid var(--gray-200); background: var(--surface); border-radius: 999px; padding: 5px 13px;
  font-size: .88rem; font-weight: 600; color: var(--ink); transition: .12s; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip.sel { background: linear-gradient(135deg, var(--blue), var(--blue-2)); border-color: transparent; color: #fff; }
.chip.loading { opacity: .5; }
.suggest-hint { font-size: .78rem; color: var(--gray-400); margin-top: 5px; }

/* ---------- language dropdown ---------- */
.lang-select { display: none; }
.lang-wrap { position: relative; }
.lang-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border: 1.5px solid var(--gray-200); border-radius: 10px;
  background: var(--surface); color: var(--ink); font-weight: 600; font-size: .95rem; text-align: left;
  transition: border-color .15s;
}
.lang-btn:hover { border-color: var(--blue); }
.lang-btn svg.ic { color: var(--gray-400); transition: transform .15s; }
.lang-wrap.open .lang-btn svg.ic { transform: rotate(180deg); }
.lang-panel {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 70;
  background: var(--surface); border: 1px solid var(--gray-200); border-radius: 14px;
  box-shadow: var(--shadow-lg); max-height: 264px; overflow-y: auto; padding: 6px;
  display: none; animation: dd-in .14s ease;
}
.lang-wrap.open .lang-panel { display: block; }
@keyframes dd-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.lang-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border-radius: 9px; border: none; background: transparent; color: var(--ink);
  font-size: .93rem; font-weight: 500; text-align: left; transition: background .12s;
}
.lang-item:hover { background: var(--gray-100); }
.lang-item .tick { color: var(--blue); opacity: 0; display: inline-flex; }
.lang-item.selected { font-weight: 700; }
.lang-item.selected .tick { opacity: 1; }
.lang-fixed {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border: 1.5px dashed var(--gray-200); border-radius: 10px;
  background: var(--surface-2); color: var(--gray-600); font-weight: 600; font-size: .95rem;
}
.lang-fixed .ic { color: var(--ok-fg); }

/* ---------- set page ---------- */
.set-head { background: var(--surface); border: 1px solid var(--gray-200); border-radius: 16px; box-shadow: var(--shadow); padding: 17px; margin-bottom: 12px; }
.set-head h1 { font-size: 1.4rem; letter-spacing: -.02em; margin-bottom: 6px; }
.set-head .by { color: var(--gray-600); font-size: .88rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.set-head .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.mode-tabs { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 12px; }
.mode-tab {
  border: 1px solid var(--gray-200); background: var(--surface); border-radius: 999px; padding: 8px 16px; font-weight: 700;
  color: var(--gray-600); box-shadow: var(--shadow); font-size: .9rem;
  display: inline-flex; align-items: center; gap: 7px; transition: .15s;
}
.mode-tab:hover { color: var(--ink); border-color: var(--gray-400); transform: translateY(-1px); }
.mode-tab.active { background: linear-gradient(135deg, var(--blue), var(--blue-2)); border-color: transparent; color: #fff; box-shadow: var(--shadow-blue); }
.mode-panel { background: var(--surface); border: 1px solid var(--gray-200); border-radius: 16px; box-shadow: var(--shadow); padding: 18px; min-height: 300px; }

/* flashcards */
.fc-stage { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.fc-card {
  width: min(540px, 100%); aspect-ratio: 1.6; perspective: 1200px; cursor: pointer; user-select: none;
  position: relative;
}
.fc-inner { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.fc-card.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 18px;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px;
  font-size: 1.8rem; font-weight: 700; box-shadow: var(--shadow-lg); background: var(--surface);
  border: 1px solid var(--gray-200); transition: box-shadow .3s ease;
}
.fc-face.back { transform: rotateY(180deg); background: var(--card-grad); }
.fc-face .side-label { position: absolute; top: 12px; left: 16px; font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--gray-400); }
.fc-actions { display: flex; gap: 9px; flex-wrap: wrap; justify-content: center; }
.fc-progress { color: var(--gray-600); font-size: .88rem; font-weight: 600; }
.fc-stats { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; font-size: .9rem; font-weight: 700; }
.fc-stats .st-ok { color: var(--ok-fg); display: inline-flex; align-items: center; gap: 5px; }
.fc-stats .st-bad { color: var(--bad-fg); display: inline-flex; align-items: center; gap: 5px; }
.fc-stats .st-rest { color: var(--gray-600); }
.fc-card.mark-ok .fc-face { box-shadow: 0 12px 38px rgba(22,168,122,.5) !important; border-color: var(--green); }
.fc-card.mark-bad .fc-face { box-shadow: 0 12px 38px rgba(239,70,96,.5) !important; border-color: var(--red); }
.fc-card.mark-ok { animation: card-ok .42s ease; }
.fc-card.mark-bad { animation: card-bad .42s ease; }
@keyframes card-ok { 30% { transform: scale(1.04) translateX(10px); } }
@keyframes card-bad { 30% { transform: scale(1.04) translateX(-10px); } }
.card-stamp {
  position: absolute; top: 14px; right: 14px; z-index: 5;
  padding: 5px 12px; border-radius: 999px; font-weight: 800; font-size: .85rem;
  pointer-events: none;
}
.card-stamp.know { background: var(--ok-bg); color: var(--ok-fg); border: 1.5px solid var(--green); }
.card-stamp.learning { background: var(--bad-bg); color: var(--bad-fg); border: 1.5px solid var(--red); }
.know-btn { background: var(--ok-bg); color: var(--ok-fg); border: none; border-radius: 999px; padding: 9px 20px; font-weight: 700; display: inline-flex; gap: 7px; align-items: center; transition: .15s; }
.know-btn:hover { background: var(--green); color: #fff; transform: translateY(-1px); }
.learn-btn { background: var(--bad-bg); color: var(--bad-fg); border: none; border-radius: 999px; padding: 9px 20px; font-weight: 700; display: inline-flex; gap: 7px; align-items: center; transition: .15s; }
.learn-btn:hover { background: var(--red); color: #fff; transform: translateY(-1px); }

/* learn / write / speller */
.learn-q { text-align: center; }
.learn-prompt { font-size: 1.55rem; font-weight: 700; margin: 10px 0 18px; letter-spacing: -.01em; }
.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 620px; margin: 0 auto; }
.option-btn {
  border: 2px solid var(--gray-200); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 12px;
  font-size: 1rem; font-weight: 600; transition: .12s;
}
.option-btn:hover:not(:disabled) { border-color: var(--blue); transform: translateY(-1px); }
.option-btn.correct { border-color: var(--green); background: var(--ok-bg); color: var(--ok-fg); }
.option-btn.wrong { border-color: var(--red); background: var(--bad-bg); color: var(--bad-fg); }
.written-input { width: min(500px, 100%); padding: 12px 15px; border: 2px solid var(--gray-200); border-radius: 12px; font-size: 1.02rem; text-align: center; background: var(--surface); color: var(--ink); transition: border-color .15s; }
.written-input:focus { outline: none; border-color: var(--blue); }
.learn-feedback { margin-top: 12px; font-weight: 700; min-height: 24px; }
.learn-feedback.ok { color: var(--ok-fg); }
.learn-feedback.bad { color: var(--bad-fg); }
.learn-bar { height: 8px; background: var(--gray-100); border-radius: 999px; overflow: hidden; margin: 12px 0 6px; }
.learn-bar > div { height: 100%; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width .25s; }
.learn-done { text-align: center; padding: 22px 0; }
.learn-done .big-ic {
  width: 66px; height: 66px; margin: 0 auto 10px; border-radius: 19px; display: flex; align-items: center; justify-content: center;
  background: var(--note-bg); color: var(--note-fg);
}
.learn-done h2 { margin-bottom: 6px; letter-spacing: -.01em; }

/* match */
.match-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 9px; max-width: 700px; margin: 0 auto; }
.match-tile {
  border: 2px solid var(--gray-200); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 11px 9px;
  font-weight: 600; font-size: .9rem; text-align: center; transition: .12s; word-break: break-word;
}
.match-tile:hover { border-color: var(--blue); transform: translateY(-1px); }
.match-tile.selected { border-color: var(--blue); background: var(--info-bg); }
.match-tile.matched { visibility: hidden; pointer-events: none; }
.match-tile.flash-red { border-color: var(--red); background: var(--bad-bg); }
.match-head { display: flex; justify-content: center; gap: 18px; margin-bottom: 14px; font-weight: 700; color: var(--gray-600); align-items: center; }
.match-head .stat { display: inline-flex; align-items: center; gap: 6px; }

/* test */
.test-q { max-width: 660px; margin: 0 auto; }
.test-q .q-num { color: var(--gray-400); font-size: .82rem; font-weight: 700; margin-bottom: 4px; }
.test-q .q-text { font-size: 1.25rem; font-weight: 700; margin-bottom: 16px; }
.test-result { text-align: center; padding: 16px 0; }
.score-big { font-size: 2.8rem; font-weight: 800; letter-spacing: -.02em; }
.score-big.good { color: var(--green); }
.score-big.mid { color: var(--yellow); }
.score-big.bad { color: var(--red); }
.wrong-list { text-align: left; max-width: 500px; margin: 14px auto 0; }
.wrong-list li { padding: 7px 0; border-bottom: 1px dashed var(--gray-200); }

/* terms list */
.terms-block { background: var(--surface); border: 1px solid var(--gray-200); border-radius: 16px; box-shadow: var(--shadow); padding: 15px; margin-top: 12px; }
.terms-block h3 { margin-bottom: 10px; font-size: 1rem; }
.terms-table { width: 100%; border-collapse: collapse; }
.terms-table td { padding: 8px; border-bottom: 1px solid var(--gray-100); vertical-align: top; font-size: .94rem; }
.terms-table td.t { font-weight: 600; width: 42%; }
.terms-table tr:last-child td { border-bottom: none; }

/* share modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,12,20,.55); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 14px; }
.modal { background: var(--surface); border: 1px solid var(--gray-200); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 24px; width: min(470px, 100%); }
.modal h3 { margin-bottom: 8px; letter-spacing: -.01em; }
.share-url-box { display: flex; gap: 7px; margin: 12px 0; }
.share-url-box input { flex: 1; padding: 9px 11px; border: 1.5px solid var(--gray-200); border-radius: 10px; font-size: .88rem; background: var(--surface-2); color: var(--ink); }
.modal .hint { color: var(--gray-600); font-size: .86rem; }
.modal .hint code { background: var(--gray-100); padding: 1px 5px; border-radius: 4px; font-size: .82rem; }

/* stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.stat-card { background: var(--surface); border: 1px solid var(--gray-200); border-radius: 13px; box-shadow: var(--shadow); padding: 14px; }
.stat-card .term { font-weight: 700; font-size: .95rem; }
.stat-card .nums { color: var(--gray-600); font-size: .86rem; margin-top: 5px; }
.stat-card .nums .k { color: var(--ok-fg); font-weight: 700; }
.stat-card .nums .l { color: var(--bad-fg); font-weight: 700; }
.students-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--gray-200); border-radius: 13px; box-shadow: var(--shadow); overflow: hidden; }
.students-table th, .students-table td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--gray-100); font-size: .92rem; }
.students-table th { background: var(--gray-100); font-size: .82rem; color: var(--gray-600); }

/* toasts */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 11px 18px; font-weight: 600;
  box-shadow: var(--shadow-lg); animation: toast-in .25s ease; max-width: 90vw; font-size: .93rem;
}
:root[data-theme="dark"] .toast { background: #e9ecf6; color: #0d1017; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- explanations ---------- */
.explain-item { border: 1px solid var(--gray-200); border-radius: 13px; margin-bottom: 8px; background: var(--surface); }
.explain-head {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 11px 13px;
  background: transparent; border: none; color: var(--ink); text-align: left; font-size: .95rem;
}
.explain-head:hover { background: var(--gray-100); }
.eh-term { font-weight: 700; min-width: 30%; }
.eh-def { color: var(--gray-600); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eh-chev { color: var(--gray-400); transition: transform .15s; display: inline-flex; }
.explain-item.open .eh-chev { transform: rotate(180deg); }
.explain-body { border-top: 1px dashed var(--gray-200); padding: 12px 14px; font-size: .93rem; }
.ex-block { margin-bottom: 10px; }
.ex-block:last-child { margin-bottom: 0; }
.ex-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--gray-400); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.ex-example { font-style: italic; font-size: 1rem; }

/* ---------- Q-Chat drawer ---------- */
#chat-drawer { position: fixed; right: 18px; bottom: 18px; z-index: 150; }
.chat-panel {
  width: 360px; max-width: calc(100vw - 30px); height: min(560px, 78vh);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--gray-200); border-radius: 18px;
  box-shadow: var(--shadow-lg); overflow: hidden; animation: toast-in .2s ease;
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--gray-200);
  font-weight: 700; font-size: .95rem; color: var(--ink);
  background: var(--surface-2);
}
.chat-head span { display: inline-flex; align-items: center; gap: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-bubble {
  max-width: 86%; padding: 9px 13px; border-radius: 14px; font-size: .92rem; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word;
}
.chat-bubble.ai { align-self: flex-start; background: var(--gray-100); color: var(--ink); border-bottom-left-radius: 4px; }
.chat-bubble.user { align-self: flex-end; background: linear-gradient(135deg, var(--blue), var(--blue-2)); color: #fff; border-bottom-right-radius: 4px; }
.chat-input-row { display: flex; gap: 7px; padding: 10px; border-top: 1px solid var(--gray-200); background: var(--surface-2); }
.chat-input-row input {
  flex: 1; padding: 9px 12px; border: 1.5px solid var(--gray-200); border-radius: 10px;
  background: var(--surface); color: var(--ink);
}
.chat-input-row input:focus { outline: none; border-color: var(--blue); }

/* ================= адаптив: планшеты и телефоны ================= */

@media (max-width: 900px) {
  .container { padding: 14px 14px 40px; }
  .hero-grid { grid-template-columns: 1fr; gap: 10px; }
  .hero-visual { display: none; }
  .hero { padding-top: 18px; }
  .hero h1 { font-size: 2.3rem; }
  .footer-inner { grid-template-columns: 1fr 1fr; }
  .mode-panel { padding: 14px; }
  .fc-face { font-size: 1.55rem; }
  .set-head h1 { font-size: 1.25rem; }
}

@media (max-width: 640px) {
  /* общее */
  .container { padding: 10px 10px 34px; }
  body { padding-bottom: env(safe-area-inset-bottom, 0); }
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-head h1 { font-size: 1.3rem; }
  .page-head .btn { justify-content: center; }

  /* шапка */
  .topbar { padding: 7px 10px; gap: 8px; flex-wrap: wrap; }
  .topbar .nav-link { font-size: .85rem; padding: 6px 8px; }
  .user-chip > span:not(.avatar):not(.role-pill) { display: none; } /* прячем имя, оставляем аватар */
  .role-pill { display: none; }

  /* герой */
  .hero h1 { font-size: 1.9rem; }
  .hero p.sub { font-size: 1rem; }
  .hero .actions .btn { flex: 1 1 100%; }
  .hero-stats { gap: 16px; flex-wrap: wrap; }
  .feature-row { margin-top: 26px; gap: 10px; }

  /* библиотека */
  .lib-toolbar { flex-direction: column; align-items: stretch; }
  .lib-sorts { justify-content: center; }
  .set-list { grid-template-columns: 1fr; }

  /* вкладки режимов — горизонтальный скролл */
  .mode-tabs {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 6px; scrollbar-width: none; margin: 0 -10px 10px; padding-left: 10px; padding-right: 10px;
  }
  .mode-tabs::-webkit-scrollbar { display: none; }
  .mode-tab { flex: 0 0 auto; padding: 9px 14px; font-size: .86rem; }

  /* страница набора */
  .set-head { padding: 13px; }
  .set-head h1 { font-size: 1.15rem; }
  .set-head .by { font-size: .82rem; gap: 6px; }
  .set-head .actions { gap: 6px; }
  .set-head .actions .btn { flex: 1 1 auto; justify-content: center; }

  /* карточки */
  .fc-card { width: 100%; aspect-ratio: 1.45; }
  .fc-face { font-size: 1.3rem; border-radius: 14px; padding: 12px; }
  .fc-actions .btn { flex: 1 1 auto; }
  .know-btn, .learn-btn { padding: 11px 16px; font-size: .95rem; flex: 1 1 40%; justify-content: center; }
  .fc-stats { gap: 10px; font-size: .84rem; }

  /* заучивание/письмо/правописание/тест */
  .learn-prompt { font-size: 1.25rem; }
  .option-grid { grid-template-columns: 1fr; gap: 8px; }
  .option-btn { padding: 13px; }
  .written-input { font-size: 1rem; }

  /* подбор */
  .match-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 7px; }
  .match-tile { padding: 10px 7px; font-size: .84rem; }
  .match-head { gap: 12px; font-size: .9rem; flex-wrap: wrap; }

  /* таблицы — горизонтальный скролл */
  .terms-block { overflow-x: auto; }
  .terms-table { min-width: 420px; }
  .students-table { display: block; overflow-x: auto; }

  /* редактор */
  .editor-row { flex-direction: column; }
  .editor-row > * { flex: none; width: 100%; }
  .term-row { grid-template-columns: 1fr; gap: 8px; }
  .term-row .suggest-area { grid-column: auto; }
  .lang-panel { max-height: 220px; }

  /* модалки и чат */
  .modal { padding: 18px; }
  .share-url-box { flex-direction: column; }
  #chat-drawer { right: 10px; bottom: 10px; }
  .chat-panel { width: calc(100vw - 20px); height: min(520px, 70vh); }

  /* тач-таргеты */
  .btn-sm { padding: 8px 12px; }
  .btn-icon { padding: 9px; }

  /* футер */
  .footer-inner { grid-template-columns: 1fr; gap: 16px; padding: 22px 16px 16px; }
  .toasts { bottom: 12px; width: calc(100% - 24px); }
  .toast { text-align: center; }
}

/* планшеты (портрет) между телефоном и десктопом */
@media (min-width: 641px) and (max-width: 900px) {
  .set-list { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .mode-tabs { justify-content: flex-start; }
  .fc-card { width: min(480px, 92%); }
}

