:root {
    --bg: #0a0e17;
    --bg-soft: #111827;
    --glass: rgba(23, 31, 48, 0.72);
    --glass-2: rgba(31, 41, 61, 0.6);
    --border: rgba(120, 140, 190, 0.16);
    --border-str: rgba(120, 140, 190, 0.32);
    --text: #e8edf7;
    --muted: #8b98b8;
    --accent: #ff9d2f;
    --accent-2: #6ea8ff;
    --violet: #a97bff;
    --green: #34d399;
    --danger: #ff5d6c;
    --radius: 16px;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); overflow: hidden; }

/* aurora animated background */
.aurora {
    position: fixed; inset: 0; z-index: -2; overflow: hidden; background: var(--bg);
}
.aurora::before, .aurora::after {
    content: ""; position: absolute; width: 60vw; height: 60vw; border-radius: 50%;
    filter: blur(120px); opacity: 0.35;
}
.aurora::before {
    background: radial-gradient(circle, var(--accent-2), transparent 60%);
    top: -20vw; left: -10vw; animation: float1 20s ease-in-out infinite;
}
.aurora::after {
    background: radial-gradient(circle, var(--violet), transparent 60%);
    bottom: -25vw; right: -10vw; animation: float2 24s ease-in-out infinite;
}
@keyframes float1 { 50% { transform: translate(20vw, 15vh) scale(1.2); } }
@keyframes float2 { 50% { transform: translate(-15vw, -10vh) scale(1.15); } }

.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.accent { color: var(--accent); }

/* ---------- Topbar ---------- */
.topbar {
    height: 66px; display: flex; align-items: center; gap: 22px; padding: 0 24px;
    background: var(--glass); backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border); position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.brand .logo { font-size: 30px; filter: drop-shadow(0 4px 10px rgba(255,157,47,.4)); }
.brand-txt b { font-size: 19px; letter-spacing: .3px; }
.brand-txt small { display: block; font-size: 10.5px; color: var(--muted); letter-spacing: .5px; }

.tabs { display: flex; gap: 6px; }
.tab {
    display: flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 12px;
    background: transparent; border: 1px solid transparent; color: var(--muted);
    cursor: pointer; font-size: 14px; font-weight: 500; transition: .18s;
}
.tab span { font-size: 15px; }
.tab:hover { color: var(--text); background: var(--glass-2); }
.tab.active { color: var(--text); background: var(--glass-2); border-color: var(--border-str);
    box-shadow: inset 0 0 0 1px rgba(255,157,47,.25); }

.global-search { flex: 1; max-width: 460px; position: relative; }
#search {
    width: 100%; padding: 11px 16px; border-radius: 12px; font-size: 14px;
    background: rgba(10,14,23,.6); border: 1px solid var(--border); color: var(--text); outline: none;
}
#search:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(110,168,255,.12); }
.search-results {
    position: absolute; top: 48px; left: 0; right: 0; background: var(--bg-soft);
    border: 1px solid var(--border-str); border-radius: 12px; max-height: 60vh; overflow-y: auto;
    box-shadow: var(--shadow); z-index: 40; padding: 6px;
}
.sr-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.sr-item:hover { background: var(--glass-2); }
.sr-item b { font-size: 13.5px; font-weight: 600; }
.sr-item small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-cat { font-size: 11px; color: var(--accent-2); }

.auth-area { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 30px;
    background: var(--glass-2); border: 1px solid var(--border); font-size: 13px; }
.user-chip .av { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--accent), var(--violet)); color: #1a1000; font-weight: 700; font-size: 12px; }

/* ---------- Buttons ---------- */
.btn {
    padding: 9px 15px; border-radius: 11px; border: 1px solid var(--border-str);
    background: var(--glass-2); color: var(--text); cursor: pointer; font-size: 13.5px;
    font-weight: 500; transition: .16s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent-2); transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff7a2f); color: #201200;
    border: none; font-weight: 700; box-shadow: 0 6px 18px rgba(255,140,47,.28); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; justify-content: center; }
.btn.danger { color: var(--danger); border-color: rgba(255,93,108,.4); background: transparent; }
.mini-btn { width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--border-str);
    background: var(--glass-2); color: var(--accent); cursor: pointer; font-size: 15px; line-height: 1; }
.mini-btn:hover { background: var(--accent); color: #201200; }

/* ---------- Views ---------- */
#main { height: calc(100vh - 66px); position: relative; }
.view { display: none; height: 100%; }
.view.active { display: flex; }

/* ---------- Tree panel ---------- */
.tree-panel {
    width: 320px; flex-shrink: 0; background: var(--glass); backdrop-filter: blur(14px);
    border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.tree-head { display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.tree { flex: 1; overflow-y: auto; padding: 4px 10px 20px; }

.tnode { margin-bottom: 2px; }
.tnode-head {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
    cursor: pointer; transition: .14s; user-select: none;
}
.tnode-head:hover { background: var(--glass-2); }
.tnode-head .ic { font-size: 17px; width: 22px; text-align: center; }
.tnode-head .nm { flex: 1; font-size: 14px; font-weight: 500; }
.tnode-head .cnt { font-size: 11px; color: var(--muted); background: rgba(10,14,23,.5);
    padding: 2px 8px; border-radius: 20px; }
.tnode-head .arrow { color: var(--muted); font-size: 11px; transition: transform .2s; }
.tnode.open .arrow { transform: rotate(90deg); }
.tnode.open .tnode-head { color: var(--accent); }
.tnode.ai .nm::after { content: " ✦"; color: var(--violet); }

.tleaves { display: none; margin: 2px 0 6px 20px; border-left: 1px solid var(--border);
    padding-left: 6px; }
.tnode.open .tleaves { display: block; }
.tleaf { padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--muted);
    transition: .12s; display: flex; align-items: center; gap: 7px; }
.tleaf:hover { background: var(--glass-2); color: var(--text); }
.tleaf.active { background: linear-gradient(90deg, rgba(255,157,47,.16), transparent); color: var(--text);
    box-shadow: inset 2px 0 0 var(--accent); }
.tleaf .lock { font-size: 10px; }
.tleaf-loading { padding: 8px 12px; font-size: 12px; color: var(--muted); }

/* ---------- Reader ---------- */
.reader { flex: 1; overflow-y: auto; padding: 34px 46px; }
.reader-content { max-width: 820px; margin: 0 auto; animation: fadein .3s; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }
.article-head { margin-bottom: 20px; }
.article-badges { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 4px 11px; border-radius: 20px; background: var(--glass-2);
    border: 1px solid var(--border); color: var(--muted); }
.badge.cat { color: var(--accent-2); }
.badge.priv { color: var(--violet); border-color: rgba(169,123,255,.4); }
.article-head h1 { font-size: 27px; line-height: 1.25; margin: 0; }
.reader-actions { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--border);
    display: flex; gap: 10px; }

/* Welcome */
.welcome { height: 100%; display: grid; place-items: center; padding: 20px; }
.welcome-card { max-width: 640px; text-align: center; background: var(--glass); backdrop-filter: blur(14px);
    border: 1px solid var(--border); border-radius: 24px; padding: 48px 44px; box-shadow: var(--shadow); }
.welcome-emoji { font-size: 56px; margin-bottom: 8px; }
.welcome-card h1 { font-size: 30px; margin: 6px 0 14px;
    background: linear-gradient(120deg, #fff, var(--accent)); -webkit-background-clip: text;
    background-clip: text; -webkit-text-fill-color: transparent; }
.welcome-card > p { color: var(--muted); line-height: 1.7; font-size: 15px; }
.welcome-stats { display: flex; gap: 14px; justify-content: center; margin: 26px 0 8px; flex-wrap: wrap; }
.wstat { background: var(--glass-2); border: 1px solid var(--border); border-radius: 14px;
    padding: 14px 20px; min-width: 96px; }
.wstat b { display: block; font-size: 26px; background: linear-gradient(120deg, var(--accent-2), var(--violet));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.wstat small { color: var(--muted); font-size: 12px; }
.welcome-hint { margin-top: 18px; font-size: 13px; color: var(--muted); }

/* ---------- Markdown ---------- */
.md { line-height: 1.72; font-size: 15.5px; }
.md p { margin: 12px 0; }
.md h1,.md h2,.md h3 { line-height: 1.3; margin: 22px 0 10px; }
.md h2 { font-size: 20px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.md h3 { font-size: 17px; }
.md ul,.md ol { padding-left: 24px; }
.md li { margin: 5px 0; }
.md code { background: rgba(10,14,23,.7); padding: 2px 7px; border-radius: 6px;
    font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 13.5px; color: var(--accent); }
.md pre { background: #0b1020; border: 1px solid var(--border-str); border-radius: 12px;
    padding: 16px; overflow-x: auto; margin: 14px 0; }
.md pre code { background: none; color: #d6e2ff; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent); margin: 14px 0; padding: 6px 16px;
    background: var(--glass-2); border-radius: 0 10px 10px 0; color: var(--muted); }
.md table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 14px; }
.md th,.md td { border: 1px solid var(--border-str); padding: 8px 12px; text-align: left; }
.md th { background: var(--glass-2); }
.md a { color: var(--accent-2); }

/* ---------- Quiz ---------- */
.quiz-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.quiz-modes { display: flex; gap: 8px; padding: 20px 28px 4px; justify-content: center; }
.qmode { display: flex; align-items: center; gap: 8px; padding: 10px 20px; border-radius: 30px;
    background: var(--glass); border: 1px solid var(--border); color: var(--muted); cursor: pointer;
    font-size: 14px; font-weight: 500; transition: .16s; }
.qmode:hover { color: var(--text); }
.qmode.active { color: #201200; background: linear-gradient(135deg, var(--accent), #ff7a2f); border: none;
    box-shadow: 0 6px 18px rgba(255,140,47,.3); }
.quiz-pane { display: none; flex: 1; overflow: hidden; padding: 18px 28px 28px; }
.quiz-pane.active { display: flex; flex-direction: column; }

/* Flashcards */
.quiz-toolbar { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 20px; }
.quiz-toolbar select { padding: 9px 14px; border-radius: 11px; background: var(--glass-2);
    border: 1px solid var(--border); color: var(--text); font-size: 13.5px; }
.progress { color: var(--muted); font-size: 14px; font-weight: 600; }
#quiz-flash { align-items: center; justify-content: center; }
.flashcard { width: min(680px, 92%); height: 360px; perspective: 1800px; cursor: pointer; }
.fc-inner { position: relative; width: 100%; height: 100%; transition: transform .55s cubic-bezier(.4,.2,.2,1);
    transform-style: preserve-3d; }
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 22px; padding: 36px;
    display: flex; flex-direction: column; align-items: center; background: var(--glass);
    backdrop-filter: blur(14px); border: 1px solid var(--border-str); box-shadow: var(--shadow); overflow: auto; }
.fc-front { justify-content: center; text-align: center; border-top: 4px solid var(--accent); }
.fc-back { transform: rotateY(180deg); border-top: 4px solid var(--green); }
.fc-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--accent);
    align-self: center; margin-bottom: 14px; }
.fc-front p { font-size: 21px; line-height: 1.5; margin: 0; font-weight: 500; }
.fc-hint { margin-top: auto; padding-top: 18px; font-size: 12px; color: var(--muted); }
.fc-answer { font-size: 15px; line-height: 1.65; width: 100%; }
.quiz-nav { display: flex; gap: 12px; margin-top: 22px; }

/* Task layout (SQL / coding) */
.task-layout { display: flex; gap: 18px; flex: 1; overflow: hidden; }
.task-list { width: 300px; flex-shrink: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.task-item { padding: 13px 15px; border-radius: 12px; background: var(--glass); border: 1px solid var(--border);
    cursor: pointer; transition: .15s; }
.task-item:hover { border-color: var(--accent-2); transform: translateY(-1px); }
.task-item.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.task-item b { font-size: 14px; font-weight: 600; display: block; }
.task-item .meta { display: flex; gap: 8px; margin-top: 6px; }
.chip { font-size: 10.5px; padding: 2px 9px; border-radius: 20px; background: var(--glass-2); color: var(--muted); }
.chip.easy { color: var(--green); } .chip.medium { color: var(--accent); } .chip.hard { color: var(--danger); }

.task-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; gap: 14px; }
.task-desc { background: var(--glass); border: 1px solid var(--border); border-radius: 14px;
    padding: 18px 22px; max-height: 34%; overflow-y: auto; }
.task-desc h3 { margin: 0 0 8px; font-size: 18px; }
.editor-box { flex: 1; display: flex; flex-direction: column; background: var(--glass);
    border: 1px solid var(--border-str); border-radius: 14px; overflow: hidden; }
.editor-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    border-bottom: 1px solid var(--border); background: var(--glass-2); }
.lang-badge { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent-2);
    padding: 3px 10px; border-radius: 6px; background: rgba(110,168,255,.12); }
.editor-box .CodeMirror { flex: 1; height: auto; font-size: 14px;
    font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; }
.run-output { max-height: 40%; overflow: auto; border-top: 1px solid var(--border); padding: 12px 14px;
    font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: #0b1020; }
.run-output table { border-collapse: collapse; font-size: 12.5px; }
.run-output th, .run-output td { border: 1px solid var(--border-str); padding: 4px 10px; }
.run-output th { background: var(--glass-2); color: var(--accent-2); }
.run-ok { color: var(--green); } .run-err { color: var(--danger); }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(4,7,14,.72); backdrop-filter: blur(5px);
    display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.modal-card { background: var(--bg-soft); border: 1px solid var(--border-str); border-radius: 20px;
    padding: 28px; width: 100%; max-width: 560px; position: relative; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow); animation: pop .22s; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } }
.modal-card.auth-card { max-width: 420px; }
.x { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 9px;
    background: var(--glass-2); border: 1px solid var(--border); color: var(--muted); cursor: pointer; }
.x:hover { color: var(--text); }
.modal-card h2 { margin: 0 0 6px; }
textarea { width: 100%; margin-top: 12px; padding: 14px; border-radius: 12px; background: rgba(10,14,23,.6);
    border: 1px solid var(--border); color: var(--text); font-size: 13.5px; resize: vertical; line-height: 1.55;
    font-family: ui-monospace, Consolas, monospace; }
.up-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.analysis { margin-top: 16px; background: var(--glass-2); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.analysis .arow { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.analysis label { font-size: 12px; color: var(--muted); width: 96px; }
.analysis select, .analysis input { flex: 1; padding: 9px 11px; border-radius: 9px; background: rgba(10,14,23,.6);
    border: 1px solid var(--border); color: var(--text); font-size: 13.5px; }
.ai-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--violet);
    background: rgba(169,123,255,.12); padding: 3px 10px; border-radius: 20px; }
.new-cat { color: var(--green); font-size: 12px; }
.modal-actions { margin-top: 18px; display: flex; justify-content: flex-end; }

/* Auth modal */
.auth-tabs { display: flex; gap: 6px; margin-bottom: 20px; background: var(--glass-2); padding: 5px;
    border-radius: 12px; }
.auth-tab { flex: 1; padding: 9px; border-radius: 9px; border: none; background: transparent; color: var(--muted);
    cursor: pointer; font-size: 14px; font-weight: 500; }
.auth-tab.active { background: var(--bg-soft); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.auth-form { display: flex; flex-direction: column; }
.auth-form label { font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.auth-form input { padding: 12px 14px; border-radius: 11px; background: rgba(10,14,23,.6);
    border: 1px solid var(--border); color: var(--text); font-size: 14px; }
.auth-form input:focus { border-color: var(--accent); outline: none; }
.auth-form button { margin-top: 20px; }
.auth-msg { min-height: 16px; margin-top: 12px; font-size: 13px; color: var(--danger); text-align: center; }
.auth-note { margin: 16px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; text-align: center; }

/* Toast */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--bg-soft);
    border: 1px solid var(--accent); color: var(--text); padding: 13px 22px; border-radius: 13px; z-index: 100;
    box-shadow: var(--shadow); font-size: 14px; animation: pop .2s; max-width: 90vw; }

/* Scrollbar */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-str); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- section tree ---------- */
.tnode.section > .sec-head { font-weight: 700; }
.tnode.section > .sec-head .nm { font-size: 14.5px; }
.tnode.section > .tleaves { margin-left: 8px; border-left: 1px solid var(--border); padding-left: 6px; }
.tnode.topic .tnode-head .nm { font-weight: 500; }
.tnode.topic.open > .tnode-head { color: var(--accent); }

/* ---------- images in answers ---------- */
.md img { max-width: 100%; height: auto; border-radius: 10px; margin: 10px 0; border: 1px solid var(--border);
    background: #fff; display: block; }
.md .imgline { margin: 12px 0; }
.fc-answer img { max-width: 100%; border-radius: 8px; margin: 8px 0; }

/* ---------- mock interview chat ---------- */
.chat-wrap { flex: 1; display: flex; flex-direction: column; max-width: 900px; width: 100%; margin: 0 auto; overflow: hidden; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px;
    border-bottom: 1px solid var(--border); background: var(--glass); }
.chat-head b { font-size: 16px; } .chat-head small { display: block; color: var(--muted); font-size: 12px; }
.chat-controls { display: flex; gap: 8px; align-items: center; }
.chat-controls select { padding: 8px 12px; border-radius: 10px; background: var(--glass-2);
    border: 1px solid var(--border); color: var(--text); font-size: 13px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: 78%; padding: 13px 17px; border-radius: 16px; line-height: 1.6; font-size: 14.5px; }
.msg.assistant .bubble { background: var(--glass); border: 1px solid var(--border); border-top-left-radius: 4px; }
.msg.user .bubble { background: linear-gradient(135deg, var(--accent), #ff7a2f); color: #201200; border-top-right-radius: 4px; font-weight: 500; }
.msg .bubble p:first-child { margin-top: 0; } .msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble pre { background: #0b1020; border-radius: 10px; padding: 12px; overflow-x: auto; }
.msg .bubble code { background: rgba(0,0,0,.25); padding: 1px 5px; border-radius: 4px; }
.typing { color: var(--muted); font-style: italic; }
.chat-settings { padding: 14px 24px; background: var(--glass-2); border-top: 1px solid var(--border); }
.chat-settings label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 8px; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; padding: 10px 12px; border-radius: 10px; background: rgba(10,14,23,.6);
    border: 1px solid var(--border); color: var(--text); font-size: 13px; font-family: ui-monospace, monospace; }
.chat-settings p { margin: 10px 0 0; font-size: 12px; line-height: 1.5; } .chat-settings a { color: var(--accent-2); }
.chat-input { display: flex; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--glass); align-items: flex-end; }
.chat-input textarea { flex: 1; margin: 0; resize: none; min-height: 44px; max-height: 140px;
    font-family: inherit; font-size: 14.5px; }
.chat-input .btn { height: 44px; width: 52px; font-size: 18px; }

@media (max-width: 860px) {
    .brand-txt small, .global-search { display: none; }
    .tree-panel { position: absolute; z-index: 15; height: 100%; }
    .reader { padding: 22px; }
    .task-layout { flex-direction: column; } .task-list { width: 100%; flex-direction: row; overflow-x: auto; }
    .task-list .task-item { min-width: 200px; }
}
