/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
  --radius: 12px;
  --radius-sm: 8px;

  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --surface-3: #e7eaf0;
  --border: #e1e5ec;
  --border-strong: #cdd3dd;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --accent: #2459e0;
  --accent-hover: #1c4bc4;
  --accent-soft: #e8efff;
  --accent-ink: #ffffff;
  --danger: #d12d2d;
  --danger-soft: #fdeceb;
  --success: #138a43;
  --success-soft: #e5f6ec;
  --warn: #b86b00;
  --warn-soft: #fff4de;
  --purple: #6d3fd8;
  --purple-soft: #efe9fd;

  --phy: #2459e0;
  --chem: #0f8a62;
  --math: #c26a00;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, .18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --surface: #121826; --surface-2: #182032; --surface-3: #212a3f;
    --border: #253049; --border-strong: #34405c; --text: #e7ebf3; --text-2: #c4ccda; --muted: #8b97ad;
    --accent: #5b8cff; --accent-hover: #7aa2ff; --accent-soft: #1b2a4d; --accent-ink: #0b1020;
    --danger: #ff6b6b; --danger-soft: #3a1c22; --success: #3ccf7e; --success-soft: #14301f;
    --warn: #f0a83c; --warn-soft: #362812; --purple: #a585ff; --purple-soft: #261d42;
    --phy: #6d9bff; --chem: #34c79a; --math: #f0a83c;
    --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --surface: #121826; --surface-2: #182032; --surface-3: #212a3f;
  --border: #253049; --border-strong: #34405c; --text: #e7ebf3; --text-2: #c4ccda; --muted: #8b97ad;
  --accent: #5b8cff; --accent-hover: #7aa2ff; --accent-soft: #1b2a4d; --accent-ink: #0b1020;
  --danger: #ff6b6b; --danger-soft: #3a1c22; --success: #3ccf7e; --success-soft: #14301f;
  --warn: #f0a83c; --warn-soft: #362812; --purple: #a585ff; --purple-soft: #261d42;
  --phy: #6d9bff; --chem: #34c79a; --math: #f0a83c;
  --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ── Base ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0; }
img { max-width: 100%; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.fine { font-size: 12.5px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.tex-raw { font-family: var(--mono); font-size: .92em; color: var(--text-2); }
.katex { font-size: 1.08em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); background: var(--success); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-provider { height: 46px; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 9px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 13px; color: var(--danger); min-height: 1em; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.prefix-input { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); overflow: hidden; }
.prefix-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.prefix-input > span { display: grid; place-items: center; padding: 0 4px 0 12px; color: var(--muted); font-weight: 600; }
.prefix-input .input { border: 0; box-shadow: none; padding-left: 2px; min-width: 0; }
.identity-row { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 640px) { .identity-row { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); } }
.captcha:empty { display: none; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--accent); }

/* ── Surfaces ──────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge-live { background: var(--danger-soft); color: var(--danger); }
.badge-live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.4s infinite; }
.badge-upcoming { background: var(--accent-soft); color: var(--accent); }
.badge-done { background: var(--surface-2); color: var(--muted); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-danger-soft { background: var(--danger-soft); color: var(--danger); }
.center-text { text-align: center; align-items: center; }
@keyframes pulse { 50% { opacity: .35; } }
.subj-physics { --subj: var(--phy); }
.subj-chemistry { --subj: var(--chem); }
.subj-mathematics { --subj: var(--math); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }
.callout { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-size: 14px; }
.callout-warn { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.callout-danger { background: var(--danger-soft); border-color: transparent; }
.callout-success { background: var(--success-soft); border-color: transparent; }
.callout-info { background: var(--accent-soft); border-color: transparent; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.table tr.me td { background: var(--accent-soft); }

/* ── Tabs / segmented ──────────────────────────────────────────────────────── */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ── Top navigation ────────────────────────────────────────────────────────── */
.topnav { 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(--border); }
.topnav-inner { max-width: 1120px; margin: 0 auto; padding: 0 16px; height: 60px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 750; letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(135deg, var(--phy), var(--chem) 55%, var(--math)); color: #fff; font-weight: 800; }
.nav-links { display: flex; gap: 4px; }
.nav-links a { color: var(--muted); font-weight: 600; font-size: 14px; padding: 7px 10px; border-radius: 8px; }
.nav-links a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-links a.active { color: var(--text); }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menu-wrap { position: relative; }
.avatar-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 12px 3px 3px; cursor: pointer; font-weight: 600; font-size: 14px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 750; font-size: 13px; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 60; }
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-item { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; border: 0; background: none; color: var(--text); font-size: 14px; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.demo-banner { background: var(--warn-soft); color: var(--text); font-size: 13.5px; text-align: center; padding: 8px 16px; border-bottom: 1px solid var(--border); }
@media (max-width: 640px) {
  .brand-name { display: none; }
  .avatar-name { display: none; }
  .avatar-btn { padding: 3px; }
  .topnav-inner { gap: 8px; }
}
.site-footer { max-width: 1120px; margin: 48px auto 0; padding: 24px 16px 40px; display: flex; gap: 16px; justify-content: space-between; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); }

/* ── Modal & toast ─────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; z-index: 1000; background: rgba(8, 12, 20, .55); display: grid; place-items: center; padding: 16px; animation: fade .15s ease; }
.modal { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 22px; animation: rise .18s ease; }
.modal-wide { max-width: 760px; }
.modal-title { font-size: 18px; margin-bottom: 12px; }
.modal-body { font-size: 14.5px; color: var(--text-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.98); } }
#toasts { position: fixed; z-index: 2000; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; max-width: 420px; background: var(--text); color: var(--bg); padding: 11px 15px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; animation: rise .18s ease; transition: opacity .35s, transform .35s; }
.toast-error { background: var(--danger); color: #fff; }
.toast-success { background: var(--success); color: #fff; }
.toast-warn { background: var(--warn); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }
