/* Academy platform design system. Brand color is injected per academy via --brand. */
:root {
  --brand: #4f46e5;
  --brand-dark: color-mix(in srgb, var(--brand) 80%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 10%, #fff);
  --brand-ink: color-mix(in srgb, var(--brand) 70%, #000);
  --bg: #f5f6fb;
  --panel: #ffffff;
  --text: #171a2b;
  --muted: #6b7280;
  --border: #e6e7f0;
  --ok: #15803d; --ok-soft: #dcfce7;
  --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(30, 32, 60, 0.08);
  --shadow-lg: 0 20px 60px rgba(30, 32, 60, 0.16);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.muted-sm { color: var(--muted); font-size: 12px; }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.col { flex: 1; min-width: 160px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.mt { margin-top: 14px; } .mt2 { margin-top: 24px; } .mb { margin-bottom: 14px; }
.right { text-align: right; } .center { text-align: center; }
.nowrap { white-space: nowrap; }

/* Avatars */
.avatar { width: 72px; height: 72px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 60%, #a855f7)); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 26px; letter-spacing: 1px; flex-shrink: 0; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 42px; height: 42px; font-size: 16px; }
.avatar.xs { width: 34px; height: 34px; font-size: 13px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border: none; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; transition: background .15s, transform .05s; text-decoration: none; line-height: 1.2; }
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid color-mix(in srgb, var(--brand) 35%, #fff); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.soft { background: var(--brand-soft); color: var(--brand-ink); }
.btn.soft:hover { background: color-mix(in srgb, var(--brand) 18%, #fff); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.danger:hover { background: #fecaca; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.lg { padding: 14px 22px; font-size: 16px; border-radius: 12px; }
.btn.wa { background: #25d366; } .btn.wa:hover { background: #1ebe5b; }

/* Forms */
.field, input.fi, textarea.fi, select.fi { width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff; color: var(--text); }
.field:focus, .fi:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.fi { min-height: 110px; resize: vertical; }
label.fl { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.err { color: var(--bad); font-size: 13px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.switch { position: relative; width: 42px; height: 24px; background: #d1d5db; border-radius: 999px; transition: .2s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; }
input:checked + .switch { background: var(--brand); } input:checked + .switch::after { left: 21px; }
.check input[type=checkbox].sw { display: none; }

/* Cards, badges, tables */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.tight { padding: 14px 16px; }
.card h2, .card h3 { margin: 0 0 6px; }
.card h3 { font-size: 15px; }
.badge { font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px; background: #eef0fe; color: var(--brand-ink); letter-spacing: .02em; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.gray { background: #f3f4f6; color: #4b5563; }
.badge.live { background: var(--ok-soft); color: var(--ok); }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fafbff; }
.table-wrap { overflow-x: auto; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; color: var(--text); }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .d { font-size: 11px; margin-top: 6px; color: var(--muted); }
.stat.brand { background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 65%, #a855f7)); color: #fff; border: none; }
.stat.brand .v, .stat.brand .l, .stat.brand .d { color: #fff; }
.pill-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-tabs button { border: 1px solid var(--border); background: #fff; padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.pill-tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.banner { padding: 12px 16px; border-radius: 12px; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--brand-soft); color: var(--brand-ink); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.progress { height: 8px; background: #eef0fe; border-radius: 6px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--brand); transition: width .3s; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv b { color: var(--muted); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #f3f4f6; border-radius: 8px; padding: 4px 9px; font-size: 12px; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }
.empty .ico { font-size: 34px; margin-bottom: 6px; }
code.inline { background: #f3f4f6; padding: 2px 6px; border-radius: 6px; font-size: 12.5px; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px; overflow: auto; font-size: 12.5px; line-height: 1.5; }

/* Toast + modal */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(10px); background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; z-index: 1000; max-width: 92vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--bad); }
.modal-bg { position: fixed; inset: 0; background: rgba(17, 24, 39, .55); display: grid; place-items: center; z-index: 900; padding: 16px; backdrop-filter: blur(2px); }
.modal { background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; box-shadow: var(--shadow-lg); }
.modal.wide { max-width: 860px; }
.modal h2 { margin: 0 0 4px; font-size: 19px; }

/* Gate (login / signup screens) */
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), var(--bg)); padding: 20px; overflow: auto; }
.gate-card { background: var(--panel); border-radius: 22px; padding: 36px 32px; width: 100%; max-width: 400px; text-align: center; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.gate-card h1 { margin: 8px 0 0; font-size: 24px; letter-spacing: -.01em; }
.gate-card label { align-self: flex-start; margin-top: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.gate-card input { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 15px; margin-top: 6px; }
.gate-card input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.gate-card .btn { margin-top: 14px; width: 100%; padding: 12px; font-size: 15px; }
.gate-card .links { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ===== Student app shell ===== */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; gap: 10px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.hello { font-size: 13px; color: var(--muted); }
.nav-tabs { display: flex; gap: 2px; background: #eef0fe; border-radius: 999px; padding: 3px; }
.nav-tabs button { border: none; background: transparent; padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.nav-tabs button.active { background: #fff; color: var(--brand-ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.layout { display: grid; grid-template-columns: 280px 1fr 380px; gap: 16px; padding: 16px; flex: 1; max-width: 1600px; width: 100%; margin: 0 auto; }
.lessons { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 14px; align-self: start; position: sticky; top: 74px; max-height: calc(100vh - 90px); overflow: auto; }
.lessons h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 4px 6px 10px; }
.lessons ul { list-style: none; padding: 0; margin: 0; }
.lesson-item { padding: 10px 12px; border-radius: 10px; cursor: pointer; margin-bottom: 4px; transition: background .15s; display: flex; gap: 10px; align-items: center; }
.lesson-item:hover { background: #f4f5fb; }
.lesson-item.active { background: var(--brand-soft); }
.lesson-item .n { width: 28px; height: 28px; border-radius: 8px; background: #eef0fe; color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex-shrink: 0; }
.lesson-item.active .n { background: var(--brand); color: #fff; }
.lesson-item .lt { font-weight: 600; font-size: 14px; }
.lesson-item .lm { font-size: 12px; color: var(--muted); }
.lesson-item .done { margin-left: auto; color: var(--ok); font-size: 14px; }
.stage { min-width: 0; }
.player-wrap { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); aspect-ratio: 16 / 9; }
.player-wrap video { width: 100%; height: 100%; display: block; background: #000; }
.placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #cbd5e1; text-align: center; padding: 20px; background: linear-gradient(135deg, #1e1b4b, #0f172a); }
.ph-icon { font-size: 44px; margin-bottom: 6px; }
.watermark { position: absolute; right: 12px; bottom: 44px; color: rgba(255,255,255,.55); font-size: 12px; pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.stage h2 { margin: 16px 0 4px; font-size: 20px; letter-spacing: -.01em; }
.chapters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chapters button { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--text); }
.chapters button:hover { border-color: var(--brand); color: var(--brand-ink); }
.chapters button b { color: var(--brand-ink); margin-right: 4px; }
.notes-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 14px; font-weight: 600; color: var(--brand); text-decoration: none; }
.lesson-notes-box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-top: 12px; font-size: 14.5px; line-height: 1.65; white-space: pre-wrap; }
.quiz-section { margin-top: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.quiz-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; gap: 10px; flex-wrap: wrap; }
.quiz-start { background: var(--brand); color: #fff; border: none; border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; }
.q-item { border-top: 1px solid var(--border); padding: 14px 0; }
.q-stem { font-weight: 600; margin-bottom: 8px; line-height: 1.5; }
.q-opt { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 6px; cursor: pointer; font-size: 14px; line-height: 1.45; transition: border-color .15s, background .15s; }
.q-opt:hover { border-color: var(--brand); }
.q-opt input { margin-top: 3px; accent-color: var(--brand); }
.q-opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.q-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.q-explain { margin-top: 8px; font-size: 13.5px; line-height: 1.55; }
.fb { border-radius: 10px; padding: 10px 12px; margin-top: 6px; }
.fb-ok { background: var(--ok-soft); } .fb-bad { background: var(--bad-soft); } .fb-tip { background: var(--warn-soft); }
.fb-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.fb-listen { display: flex; align-items: center; gap: 8px; margin: 4px 0 6px; flex-wrap: wrap; }
.fb-foot { margin-top: 8px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.quiz-actions { margin-top: 12px; }
.quiz-submit, .quiz-retry { background: var(--brand); color: #fff; border: none; border-radius: 10px; padding: 11px 16px; font-weight: 600; cursor: pointer; }
.quiz-score { margin-top: 12px; padding: 14px; background: var(--brand-soft); border-radius: 12px; font-size: 15px; line-height: 1.5; }
.quiz-review { margin-top: 10px; background: var(--warn-soft); border-radius: 12px; padding: 12px; }
.qr-head { font-weight: 700; margin-bottom: 6px; }
.qr-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.quiz-src { margin-top: 10px; font-size: 12px; color: var(--muted); }
.q-jump { background: #fff; border: 1px solid var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer; }
.q-jump:hover { background: var(--brand-soft); }
.voice-btn { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.voice-btn.playing { background: var(--brand); color: #fff; }
.chat { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 74px; height: calc(100vh - 90px); min-height: 480px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 700; font-size: 14px; }
.chat-sub { font-size: 12px; color: var(--muted); }
.messages { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.msg.bot { background: #f3f4f8; border-bottom-left-radius: 4px; align-self: flex-start; }
.msg.user { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }
.msg-jump, .msg-voice { margin-top: 8px; font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.typing { font-size: 12px; color: var(--muted); padding: 4px 8px; align-self: flex-start; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
.chat-input input:focus { outline: none; border-color: var(--brand); }
.chat-input button { padding: 0 16px; border: none; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 8px; }
.suggest button { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.suggest button:hover { border-color: var(--brand); color: var(--brand-ink); }
.page { max-width: 1100px; margin: 0 auto; padding: 18px 16px 40px; width: 100%; }
.page h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
.mobile-nav { display: none; }
.install-tip { display: none; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 240px 1fr; }
  .chat { grid-column: 1 / -1; position: static; height: 560px; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 12px; }
  .lessons { position: static; max-height: none; }
  .chat { height: 70vh; min-height: 420px; }
  .topbar { padding: 8px 12px; }
  .nav-tabs { display: none; }
  .hello { display: none; }
  .mobile-nav { display: flex; position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--border); z-index: 30; }
  .mobile-nav button { flex: 1; border: none; background: none; padding: 9px 4px 10px; font-size: 11px; color: var(--muted); font-weight: 600; display: flex; flex-direction: column; gap: 2px; align-items: center; }
  .mobile-nav button .i { font-size: 18px; }
  .mobile-nav button.active { color: var(--brand); }
  .stage h2 { font-size: 18px; }
  .msg { max-width: 94%; }
  .modal { padding: 18px; border-radius: 14px; }
  .gate-card { padding: 28px 22px; }
}

/* ===================== v2: dark mode ===================== */
[data-theme="dark"] {
  --bg: #0f1117; --panel: #171a23; --text: #e8eaf2; --muted: #9aa0b4; --border: #2a2e3d;
  --brand-soft: color-mix(in srgb, var(--brand) 22%, #171a23); --brand-ink: color-mix(in srgb, var(--brand) 70%, #fff);
  --ok-soft: #14351f; --warn-soft: #3a2a0a; --bad-soft: #3b1414; --shadow: 0 6px 24px rgba(0,0,0,.35); --shadow-lg: 0 20px 60px rgba(0,0,0,.55);
  color-scheme: dark;
}
[data-theme="dark"] input.fi, [data-theme="dark"] textarea.fi, [data-theme="dark"] select.fi, [data-theme="dark"] .field, [data-theme="dark"] .gate-card input, [data-theme="dark"] .chat-input input, [data-theme="dark"] .pill-tabs button, [data-theme="dark"] .chapters button, [data-theme="dark"] .suggest button, [data-theme="dark"] .q-jump, [data-theme="dark"] .voice-btn, [data-theme="dark"] .modal, [data-theme="dark"] .nav-tabs button.active, [data-theme="dark"] .lesson-row { background: #1f2330; color: var(--text); }
[data-theme="dark"] .msg.bot { background: #232736; }
[data-theme="dark"] .nav-tabs, [data-theme="dark"] .progress, [data-theme="dark"] .lesson-item .n, [data-theme="dark"] .chip, [data-theme="dark"] .badge { background: #262a3a; color: var(--text); }
[data-theme="dark"] .lesson-item:hover, [data-theme="dark"] .table tr:hover td { background: #1f2330; }
[data-theme="dark"] .lesson-notes-box, [data-theme="dark"] pre.code { background: #1f2330; color: #e2e8f0; }
[data-theme="dark"] .gate { background: radial-gradient(1200px 600px at 50% -10%, #1e2140, var(--bg)); }
[data-theme="dark"] .placeholder { background: linear-gradient(135deg, #1e1b4b, #0b0d14); }
[data-theme="dark"] .toast { background: #e8eaf2; color: #111; }

/* ===================== v2: topbar widgets ===================== */
.streak-chip { display: inline-flex; align-items: center; gap: 5px; background: #fff4e5; color: #9a5b00; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.streak-chip.cold { background: var(--border); color: var(--muted); }
[data-theme="dark"] .streak-chip { background: #3a2a0a; color: #fbbf24; }
.xp-chip { display: inline-flex; align-items: center; gap: 5px; background: var(--brand-soft); color: var(--brand-ink); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.icon-btn { position: relative; border: 1px solid var(--border); background: var(--panel); color: var(--text); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 16px; display: grid; place-items: center; }
.icon-btn:hover { border-color: var(--brand); }
.icon-btn .dot { position: absolute; top: -5px; right: -5px; background: var(--bad); color: #fff; font-size: 10px; font-weight: 800; min-width: 17px; height: 17px; border-radius: 999px; display: grid; place-items: center; padding: 0 4px; }
.menu { position: absolute; right: 0; top: 44px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 200px; padding: 6px; z-index: 60; }
.menu button, .menu a { display: flex; width: 100%; text-align: left; border: none; background: none; color: var(--text); padding: 9px 10px; border-radius: 8px; font-size: 13.5px; cursor: pointer; text-decoration: none; gap: 8px; align-items: center; }
.menu button:hover, .menu a:hover { background: var(--brand-soft); }
.rel { position: relative; }
.xp-toast { position: fixed; top: 70px; right: 16px; background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 999px; font-weight: 800; font-size: 14px; box-shadow: var(--shadow-lg); z-index: 1001; animation: xpUp 1.8s ease forwards; pointer-events: none; }
@keyframes xpUp { 0% { transform: translateY(10px); opacity: 0; } 15% { transform: none; opacity: 1; } 80% { opacity: 1; } 100% { transform: translateY(-16px); opacity: 0; } }

/* ===================== v2: home panel + lesson list ===================== */
.home-hero { background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 60%, #a855f7)); color: #fff; border-radius: var(--radius); padding: 20px 22px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: center; }
.home-hero h2 { margin: 0 0 4px; font-size: 22px; color: #fff; }
.home-hero .sub { opacity: .9; font-size: 13.5px; }
.home-hero .stats { display: flex; gap: 10px; }
.home-hero .stats div { background: rgba(255,255,255,.16); border-radius: 12px; padding: 8px 12px; text-align: center; min-width: 70px; }
.home-hero .stats b { display: block; font-size: 20px; }
.home-hero .stats span { font-size: 11px; opacity: .9; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 14px; }
.cw { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); cursor: pointer; }
.cw:first-of-type { border-top: none; }
.cw .bar { height: 5px; background: var(--border); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.cw .bar div { height: 100%; background: var(--brand); }
.ann { padding: 10px 0; border-top: 1px solid var(--border); }
.ann:first-of-type { border-top: none; }
.ann b { display: block; font-size: 14px; }
.ann p { margin: 3px 0 0; font-size: 13px; color: var(--text); white-space: pre-wrap; }
.ann .when { font-size: 11px; color: var(--muted); }
.ann.pinned b::before { content: "📌 "; }
.search-box { position: relative; margin: 0 0 10px; }
.search-box input { width: 100%; padding: 9px 12px 9px 32px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; background: var(--panel); color: var(--text); }
.search-box::before { content: "🔍"; position: absolute; left: 10px; top: 9px; font-size: 13px; opacity: .7; }
.search-res { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; overflow: hidden; }
.search-res > b { display: block; padding: 8px 10px; font-size: 13px; background: var(--brand-soft); cursor: pointer; }
.search-res button { display: block; width: 100%; text-align: left; border: none; background: none; color: var(--text); padding: 6px 10px; font-size: 12px; cursor: pointer; border-top: 1px solid var(--border); }
.search-res button b { color: var(--brand); margin-right: 6px; }
.course-h { display: flex; align-items: center; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 10px 6px 4px; cursor: pointer; user-select: none; }
.course-h .pct { font-size: 11px; text-transform: none; letter-spacing: 0; }
.lesson-item .lp { height: 3px; background: var(--border); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.lesson-item .lp div { height: 100%; background: var(--brand); }
.lesson-item .done { color: var(--ok); font-weight: 800; }

/* ===================== v2: stage extras ===================== */
.iframe-wrap { position: relative; padding-top: 56.25%; background: #000; border-radius: var(--radius); overflow: hidden; }
.iframe-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; }
.stage-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.mynotes { margin-top: 12px; }
.mynotes textarea { width: 100%; min-height: 90px; border: 1px solid var(--border); border-radius: 10px; padding: 10px; font-size: 13.5px; background: var(--panel); color: var(--text); resize: vertical; }
.bm { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px; margin: 4px 4px 0 0; background: var(--panel); }
.bm button { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 12px; padding: 0 2px; }
.bm b { color: var(--brand); cursor: pointer; }
.att { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; text-decoration: none; color: var(--text); font-size: 13px; margin: 6px 6px 0 0; background: var(--panel); }

/* ===================== v2: chat extras ===================== */
.msg ul, .msg ol { margin: 6px 0; padding-left: 20px; }
.msg li { margin: 2px 0; }
.msg code { background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.msg.bot { white-space: normal; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.msg-actions button { border: none; background: none; color: var(--muted); font-size: 11.5px; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.msg-actions button:hover { background: var(--brand-soft); color: var(--brand-ink); }
.chat-input .mic { width: 42px; padding: 0; background: var(--panel); border: 1px solid var(--border); color: var(--text); font-size: 17px; }
.chat-input .mic.on { background: var(--bad); color: #fff; border-color: var(--bad); animation: pulse 1s infinite; }
.chat-input .at { width: auto; padding: 0 10px; font-size: 12px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); }
.chat-input .at.on { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
.chat-tools { display: flex; gap: 6px; padding: 0 10px 8px; font-size: 11.5px; color: var(--muted); align-items: center; }

/* ===================== v2: flashcards ===================== */
.fc-wrap { max-width: 640px; margin: 0 auto; }
.fc { perspective: 1200px; height: 300px; cursor: pointer; }
.fc .in { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.fc.flip .in { transform: rotateY(180deg); }
.fc .face { position: absolute; inset: 0; backface-visibility: hidden; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 28px; display: grid; place-items: center; text-align: center; font-size: 19px; line-height: 1.5; white-space: pre-wrap; }
.fc .face.back { transform: rotateY(180deg); background: var(--brand-soft); font-size: 16px; }
.fc .tag { position: absolute; top: 12px; left: 16px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.fc-grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.fc-grades button { padding: 12px; border: none; border-radius: 12px; font-weight: 700; cursor: pointer; font-size: 14px; }
.fc-grades .again { background: var(--bad-soft); color: var(--bad); } .fc-grades .good { background: var(--brand-soft); color: var(--brand-ink); } .fc-grades .easy { background: var(--ok-soft); color: var(--ok); }
.fc-grades small { display: block; font-weight: 500; font-size: 11px; opacity: .8; }
.deck { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-top: 1px solid var(--border); gap: 10px; }
.deck:first-of-type { border-top: none; }
.deck .due { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 700; }

/* ===================== v2: tasks / tests ===================== */
.task { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border); align-items: center; }
.task:first-of-type { border-top: none; }
.task .t { font-weight: 700; } .task .m { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.timer { position: sticky; top: 64px; z-index: 10; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; font-weight: 700; box-shadow: var(--shadow); margin-bottom: 12px; }
.timer.low { border-color: var(--bad); color: var(--bad); }
.live-card { border-left: 4px solid #ef4444; }
.countdown { font-variant-numeric: tabular-nums; }
.doubt { padding: 12px 0; border-top: 1px solid var(--border); }
.doubt:first-of-type { border-top: none; }
.doubt .q { font-weight: 600; } .doubt .a { margin-top: 6px; padding: 10px 12px; background: var(--ok-soft); border-radius: 10px; white-space: pre-wrap; font-size: 13.5px; }
.doubt .a.wait { background: var(--warn-soft); color: var(--warn); }

/* ===================== v2: progress / badges / leaderboard ===================== */
.level-card { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.level-ring { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--brand) var(--p, 0%), var(--border) 0); }
.level-ring div { width: 68px; height: 68px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font-weight: 800; font-size: 13px; text-align: center; line-height: 1.1; }
.level-ring div b { font-size: 20px; display: block; color: var(--brand); }
.xpbar { height: 10px; background: var(--border); border-radius: 6px; overflow: hidden; margin-top: 8px; }
.xpbar div { height: 100%; background: linear-gradient(90deg, var(--brand), #a855f7); }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.badge-t { text-align: center; border: 1px solid var(--border); border-radius: 12px; padding: 10px 6px; font-size: 11px; color: var(--muted); }
.badge-t .i { font-size: 26px; display: block; margin-bottom: 3px; }
.badge-t.on { border-color: var(--brand); background: var(--brand-soft); color: var(--text); }
.badge-t.off { opacity: .45; filter: grayscale(1); }
.lb { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.lb td { padding: 8px 6px; border-bottom: 1px solid var(--border); }
.lb tr.me td { background: var(--brand-soft); font-weight: 700; }
.lb .r { width: 34px; font-weight: 800; color: var(--muted); }
.lb .r.top { font-size: 18px; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 60px; }
.spark div { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.inbox-item { padding: 10px 0; border-top: 1px solid var(--border); }
.inbox-item:first-of-type { border-top: none; }
.inbox-item.unread b::before { content: "● "; color: var(--brand); }
.inbox-item .w { font-size: 11px; color: var(--muted); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 1002; }
@media (max-width: 760px) { .home-hero { padding: 16px; } .fc { height: 240px; } .fc .face { font-size: 16px; padding: 18px; } .topbar .xp-chip { display: none; } .nav-tabs { display: none; } }

/* ---- v3 launch polish: phone-first layout, bigger tap targets ---- */
.mobile-only { display: none; }
.pin-wrap { position: relative; width: 100%; }
.pin-wrap input { width: 100%; padding-right: 46px !important; }
.pin-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: none; background: none; font-size: 18px; width: 40px; height: 40px; cursor: pointer; opacity: .7; }
.nbadge { position: absolute; top: 4px; left: 50%; margin-left: 8px; background: var(--bad); color: #fff; border-radius: 999px; font-size: 10px; min-width: 16px; height: 16px; line-height: 16px; padding: 0 4px; }
.mobile-nav button { position: relative; }
.bm button { padding: 6px 8px; font-size: 14px; }
.msg-actions button { font-size: 13px; padding: 6px 8px; }
.suggest button { padding: 8px 12px; font-size: 13px; }
#clearChat { width: 36px; height: 36px; font-size: 14px; }
@media (max-width: 760px) {
  .toast { bottom: 84px; }
  .layout .stage { order: -1; }
  body:not(.ask-mode) .layout .chat { display: none; }
  body.ask-mode .layout .lessons, body.ask-mode .layout .stage { display: none; }
  body.ask-mode .layout .chat { height: calc(100vh - 150px); height: calc(100dvh - 150px); min-height: 360px; }
  .mobile-nav button { font-size: 12px; min-height: 54px; }
  .stage-actions .btn { min-height: 40px; }
  .chat-input input { font-size: 16px; } /* stops iOS zooming into the field */
  .mobile-only { display: inline-flex; }
}
