:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --text: #1c1f33;
  --muted: #646a85;
  --line: #dde1ee;
  --primary: #4f46e5;
  --primary-2: #6d64f5;
  --primary-soft: #e8e7fd;
  --accent: #f59e0b;
  --accent-soft: #fdf1d8;
  --ok: #16a34a;
  --ok-soft: #dcf5e4;
  --bad: #dc2626;
  --bad-soft: #fde2e2;
  --teal: #0d9488;
  --teal-soft: #d5f3ef;
  --code-bg: #1e2235;
  --code-text: #e6e8f2;
  --shadow: 0 1px 2px rgba(20, 24, 60, .05), 0 6px 24px rgba(20, 24, 60, .07);
  --radius: 16px;
  --font: 'Noto Sans Armenian', 'Noto Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', Consolas, 'Courier New', monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12131c; --surface: #1b1d2a; --surface-2: #242737; --text: #e9eaf3; --muted: #9da2bd;
    --line: #2f3346; --primary: #8b84ff; --primary-2: #a29dff; --primary-soft: #2a2950;
    --accent-soft: #3a2f16; --ok: #34d399; --ok-soft: #173a2c; --bad: #f87171; --bad-soft: #3d1d22;
    --teal: #2dd4bf; --teal-soft: #163834; --code-bg: #0c0d14;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --bg: #12131c; --surface: #1b1d2a; --surface-2: #242737; --text: #e9eaf3; --muted: #9da2bd;
  --line: #2f3346; --primary: #8b84ff; --primary-2: #a29dff; --primary-soft: #2a2950;
  --accent-soft: #3a2f16; --ok: #34d399; --ok-soft: #173a2c; --bad: #f87171; --bad-soft: #3d1d22;
  --teal: #2dd4bf; --teal-soft: #163834; --code-bg: #0c0d14;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 64px; min-height: calc(100vh - 140px); }

.topbar {
  position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar .wrap { display: flex; align-items: center; gap: 12px; height: 62px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--teal)); font-size: .95rem;
}
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 10px; font-weight: 500; font-size: .95rem; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700;
}
.menu-btn { display: none; }
@media (max-width: 860px) {
  .nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column;
    background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 16px 16px; margin: 0; }
  .nav.open { display: flex; }
  .menu-btn { display: inline-flex; }
  .userbox .uname { display: none; }
}

footer.foot { border-top: 1px solid var(--line); padding: 20px 0; color: var(--muted); font-size: .85rem; }

/* ---------- components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent;
  background: var(--primary); color: #fff; padding: 11px 18px; border-radius: 12px; font: inherit; font-weight: 600;
  cursor: pointer; transition: transform .08s, background .15s, box-shadow .15s; text-decoration: none !important;
  font-size: .95rem; line-height: 1.2;
}
.btn:hover { background: var(--primary-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.soft:hover { filter: brightness(.97); }
.btn.danger { background: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.lg { padding: 14px 24px; font-size: 1.05rem; border-radius: 14px; }
.btn.sm { padding: 7px 12px; font-size: .85rem; border-radius: 10px; }
.btn.icon { padding: 8px 10px; }
.btn.google { background: var(--surface); color: var(--text); border-color: var(--line); width: 100%; }
.btn.google:hover { background: var(--surface-2); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--accent-soft); color: #b45309; }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
label.field { display: block; }
label.field > span { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 6px; }

.alert { padding: 12px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.alert.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.alert.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.alert.warn { background: var(--accent-soft); border-color: transparent; color: #92400e; }
:root[data-theme="dark"] .alert.warn { color: #fbbf24; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 16px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---------- hero / mode cards ---------- */
.hero { padding: 28px 0 8px; }
.hero h1 { max-width: 760px; }
.hero p.lead { font-size: 1.1rem; color: var(--muted); max-width: 680px; }
.mode-card { display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.mode-card .ico {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-size: 1.6rem;
}
.mode-card.a .ico { background: var(--accent-soft); }
.mode-card.b .ico { background: var(--primary-soft); }
.mode-card.c .ico { background: var(--teal-soft); }
.mode-card ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: .92rem; }
.mode-card .foot-row { margin-top: auto; padding-top: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 14px 16px; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }

/* ---------- grade picker ---------- */
.grades { display: flex; flex-wrap: wrap; gap: 8px; }
.grade-chip {
  min-width: 56px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  font: inherit; font-weight: 700; cursor: pointer; color: var(--text); transition: all .12s; text-align: center;
}
.grade-chip small { display: block; font-weight: 500; font-size: .7rem; color: var(--muted); }
.grade-chip:hover { border-color: var(--primary); }
.grade-chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.grade-chip.on small { color: rgba(255,255,255,.8); }
.grade-chip:disabled { opacity: .4; cursor: not-allowed; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- question ---------- */
.q-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.q-text { font-size: 1.12rem; font-weight: 600; margin-bottom: 14px; white-space: pre-line; }
code, pre, table.qtable, .num-answer input { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
.q-text code, .opt code, .explain code { font-family: var(--mono); background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .92em; }
pre.code {
  background: var(--code-bg); color: var(--code-text); padding: 14px 16px; border-radius: 12px; overflow-x: auto;
  font-family: var(--mono); font-size: .9rem; line-height: 1.5; margin: 0 0 16px;
}
table.qtable { border-collapse: collapse; margin: 0 0 16px; font-family: var(--mono); font-size: .92rem; }
table.qtable td, table.qtable th { border: 1px solid var(--line); padding: 6px 12px; text-align: center; }
table.qtable th { background: var(--surface-2); }
.opts { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; text-align: left; width: 100%; padding: 13px 16px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; transition: border .12s, background .12s, transform .1s;
}
.opt:hover:not(:disabled) { border-color: var(--primary); }
.opt .num {
  flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center;
  font-weight: 700; font-size: .85rem;
}
.opt.multi .num { border-radius: 6px; }
.opt.sel { border-color: var(--primary); background: var(--primary-soft); }
.opt.sel .num { background: var(--primary); color: #fff; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .num { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .num { background: var(--bad); color: #fff; }
.opt.missed { border-style: dashed; border-color: var(--ok); }
.opt:disabled { cursor: default; }
.num-answer { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.num-answer input { max-width: 260px; font-size: 1.1rem; font-family: var(--mono); }
.num-answer input.right { border-color: var(--ok); background: var(--ok-soft); }
.num-answer input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.explain { margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border-left: 4px solid var(--primary); white-space: pre-line; }
.explain.ok { border-left-color: var(--ok); }
.explain.bad { border-left-color: var(--bad); }
.hint-multi { font-size: .85rem; color: var(--muted); margin: -6px 0 12px; }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--teal)); border-radius: 99px; transition: width .3s; }

/* ---------- quiz game ---------- */
.quiz-top { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 700; font-size: .9rem; }
.pill.fire { background: var(--accent-soft); border-color: transparent; color: #b45309; }
:root[data-theme="dark"] .pill.fire { color: #fbbf24; }
.qtimer { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.qtimer > i { display: block; height: 100%; background: var(--accent); transition: width 1s linear; }
.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.96); } 60% { transform: scale(1.02); } 100% { transform: scale(1); } }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.float-pts { position: fixed; pointer-events: none; font-weight: 800; color: var(--ok); font-size: 1.4rem; animation: floatUp 1s ease forwards; z-index: 99; }
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-60px); } }
.stars { font-size: 2.4rem; letter-spacing: 6px; }
.big-score { font-size: 3.2rem; font-weight: 800; line-height: 1; }
canvas#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 100; }

/* ---------- test / exam ---------- */
.test-layout { display: grid; grid-template-columns: 1fr 280px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .test-layout { grid-template-columns: 1fr; } .test-side { order: -1; } }
.test-side { position: sticky; top: 78px; }
@media (max-width: 860px) { .test-side { position: static; } }
.timer { font-family: var(--mono); font-size: 1.7rem; font-weight: 700; letter-spacing: 1px; }
.timer.warn { color: var(--accent); }
.timer.danger { color: var(--bad); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .55; } }
.qnav { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 6px; }
.qnav button {
  height: 36px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); font: inherit; font-size: .82rem;
  font-weight: 700; cursor: pointer; color: var(--text); position: relative;
}
.qnav button.done { background: var(--primary-soft); border-color: var(--primary-soft); color: var(--primary); }
.qnav button.cur { outline: 2px solid var(--primary); outline-offset: 1px; }
.qnav button.flag::after { content: ''; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.qnav button.r-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.qnav button.r-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.qnav-sep { grid-column: 1 / -1; font-size: .75rem; color: var(--muted); font-weight: 600; margin-top: 6px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
table.data tr:hover td { background: var(--surface-2); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.bar.ok > i { background: var(--ok); } .bar.bad > i { background: var(--bad); } .bar.warn > i { background: var(--accent); }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 12, 30, .5); display: grid; place-items: center; z-index: 200; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 24px; max-width: 460px; width: 100%; box-shadow: var(--shadow); }
.modal .row { justify-content: flex-end; margin-top: 18px; }
.toast-box { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 300; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); animation: pop .3s; font-size: .92rem; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.auth-box { max-width: 440px; margin: 20px auto; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; padding: 10px; border-radius: 9px; background: transparent; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.demo-banner { background: var(--accent-soft); color: #92400e; font-size: .85rem; text-align: center; padding: 6px 16px; }
:root[data-theme="dark"] .demo-banner { color: #fbbf24; }
.lock { display: grid; place-items: center; text-align: center; padding: 40px 20px; }
.lock .ico { font-size: 3rem; margin-bottom: 8px; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--surface-2); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
