:root {
  --bg: #0b1220;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-2: rgba(255, 255, 255, 0.09);
  --text: rgba(255, 255, 255, 0.93);
  --muted: rgba(255, 255, 255, 0.65);
  --border: rgba(255, 255, 255, 0.12);
  --primary: #7c3aed;
  --primary-2: #a78bfa;
  --danger: #ef4444;
  --shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5);
  --radius: 16px;
  --ring: 0 0 0 3px rgba(167, 139, 250, 0.25);
  --topbar-h: 72px;
}

/* Theme presets */
:root[data-theme="violet"] { --bg: #0b1220; --primary: #7c3aed; --primary-2: #a78bfa; --ring: 0 0 0 3px rgba(167, 139, 250, 0.25); }
:root[data-theme="ocean"] { --bg: #071a2b; --primary: #0ea5e9; --primary-2: #67e8f9; --ring: 0 0 0 3px rgba(103, 232, 249, 0.25); }
:root[data-theme="sunset"] { --bg: #1a0b18; --primary: #f97316; --primary-2: #fb7185; --ring: 0 0 0 3px rgba(251, 113, 133, 0.25); }
:root[data-theme="mint"] { --bg: #061c16; --primary: #22c55e; --primary-2: #5eead4; --ring: 0 0 0 3px rgba(94, 234, 212, 0.25); }
:root[data-theme="mono"] { --bg: #0b0f14; --primary: #e5e7eb; --primary-2: #cbd5e1; --ring: 0 0 0 3px rgba(226, 232, 240, 0.25); }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 15% 15%, color-mix(in srgb, var(--primary) 20%, transparent), transparent 60%),
    radial-gradient(1000px 700px at 85% 0%, color-mix(in srgb, var(--primary-2) 15%, transparent), transparent 60%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  overflow: hidden;
}

a { color: var(--primary-2); text-decoration: none; transition: opacity 0.2s; }
a:hover { opacity: 0.8; }
.small { font-size: 13px; }
.muted { color: var(--muted); }

/* Layouts */
.page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  background: rgba(11, 18, 32, 0.6);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  height: 100%;
}
.brand-title { font-weight: 800; font-size: 1.1rem; display: flex; align-items: center; gap: 8px;}
.brand-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* Theme Select */
.theme-picker {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--panel);
}
.theme-picker label { font-size: 12px; color: var(--muted); }
.theme-select {
  appearance: none; background: transparent; border: none; color: var(--text);
  font-weight: 600; font-size: 13px; cursor: pointer; outline: none; padding-right: 16px;
}

/* User & Cards */
.user-chip { padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--panel); font-size: 13px; display: flex; align-items: center; gap: 6px;}
.card {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.auth-card { width: min(440px, 100%); padding: 32px; text-align: center; }

/* Headings */
h1, h2, h3 { margin: 0 0 8px 0; font-weight: 700; line-height: 1.2; }
.h2 { font-size: 20px; } .h3 { font-size: 16px; }
p { margin: 0 0 16px 0; }

/* Alerts */
.alert {
  border: 1px solid rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.1);
  padding: 12px 16px; border-radius: 12px; margin: 16px 0; font-size: 14px;
  display: flex; align-items: center; gap: 8px; text-align: left;
}
.alert.success { border-color: rgba(34, 197, 94, 0.3); background: rgba(34, 197, 94, 0.1); }

/* Forms & Inputs */
.form { display: grid; gap: 16px; margin-top: 24px; text-align: left; }
label span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 500;}
input[type="text"], input[type="email"], input[type="password"] {
  width: 100%; padding: 12px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(0, 0, 0, 0.2);
  color: var(--text); font-size: 15px; outline: none; transition: all 0.2s ease;
}
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus {
  border-color: var(--primary); box-shadow: var(--ring); background: rgba(0, 0, 0, 0.4);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); cursor: pointer;
  font-weight: 600; font-size: 14px; transition: all 0.2s ease;
}
.btn:hover { background: var(--panel-2); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.btn.primary {
  background: var(--primary); border-color: color-mix(in srgb, var(--primary) 80%, white);
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

.footer-links { margin-top: 24px; font-size: 14px; }

/* Drag & Drop Zone */
.drop-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 32px 24px; border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: 12px; background: rgba(0, 0, 0, 0.1); cursor: pointer;
  transition: all 0.2s ease; text-align: center; margin-bottom: 12px;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary); background: rgba(var(--primary), 0.05);
}
.drop-zone i { font-size: 32px; color: var(--primary-2); }
.drop-zone-text { font-size: 14px; font-weight: 500; word-break: break-word; text-align: center;}
.drop-zone-hint { font-size: 12px; color: var(--muted); }

.divider { height: 1px; background: var(--border); margin: 24px 0; }

/* App Shell (Dashboard) */
.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}
@media (max-width: 980px) { .app-shell { grid-template-columns: 1fr; } }
.sidebar {
  position: relative;
  height: 100%;
  max-height: none;
  overflow-y: auto;
  padding: 20px;
}
@media (max-width: 980px) { .sidebar { position: static; max-height: none; } }
.main { height: 100%; min-height: 0; }
.main .card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar History List */
.notes-list { display: grid; gap: 10px; margin-top: 16px; }
.note-item {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--panel);
  transition: all 0.2s ease; cursor: pointer;
}
.note-item:hover { background: var(--panel-2); transform: translateX(4px); }
.note-item.active {
  border-color: var(--primary); background: color-mix(in srgb, var(--primary) 15%, transparent);
}
.note-icon { display: grid; place-items: center; width: 32px; height: 32px; background: rgba(0,0,0,0.2); border-radius: 8px; color: var(--primary-2); }
.note-info { flex: 1; overflow: hidden; }
.note-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-date { font-size: 11px; margin-top: 2px; }

/* Tabs */
.tabs { display: flex; gap: 8px; padding: 6px; border-radius: 12px; background: rgba(0, 0, 0, 0.2); margin-bottom: 24px;}
.tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 12px; border-radius: 8px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; font-weight: 600; font-size: 14px; transition: all 0.2s ease;
}
.tab:hover { color: var(--text); background: var(--panel); }
.tab.active { color: var(--text); background: var(--panel-2); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

.tab-panels { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.tab-panel { display: none; animation: fadeIn 0.3s ease; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
.tab-panel.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; flex-shrink: 0;}
.output {
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 20px;
  min-height: 200px;
  white-space: pre-wrap;
  font-size: 15px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.output.markdown { white-space: normal; }
.output.markdown h1, .output.markdown h2, .output.markdown h3, .output.markdown h4 { margin: 12px 0 8px; }
.output.markdown p { margin: 0 0 12px; }
.output.markdown ul, .output.markdown ol { margin: 8px 0 12px 20px; padding: 0; }
.output.markdown li { margin: 4px 0; }
.output.markdown hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Chat layout */
.chat-layout { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
.chat-output { white-space: normal; flex: 1; min-height: 0; overflow-y: auto; }
.chat-messages { display: flex; flex-direction: column; gap: 10px; }
.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  white-space: pre-wrap;
}
.chat-bubble.user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--primary) 18%, rgba(0, 0, 0, 0.2));
  border-color: color-mix(in srgb, var(--primary) 45%, transparent);
}
.chat-bubble.assistant { align-self: flex-start; }
.chat-bubble.error {
  align-self: flex-start;
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.12);
}
.chat-input-row { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.chat-input-row input { flex: 1; }

/* Scrollbars (modern) */
.output { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--primary-2) 70%, transparent) rgba(255, 255, 255, 0.08); }
.output::-webkit-scrollbar { width: 10px; height: 10px; }
.output::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.06); border-radius: 999px; }
.output::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--primary-2) 55%, rgba(255, 255, 255, 0.2));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.output::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--primary-2) 70%, rgba(255, 255, 255, 0.2)); }

/* Custom Cards (Flashcards/Quiz) */
.flashcard, .quiz-item { border: 1px solid var(--border); background: var(--panel); border-radius: 12px; padding: 16px; margin-bottom: 16px; transition: transform 0.2s ease;}
.flashcard:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--primary) 50%, transparent); }
.flashcard .q { font-weight: 700; margin-bottom: 8px; font-size: 16px; color: var(--primary-2); }
.flashcard .a { color: var(--text); }

.quiz-item .q { font-weight: 700; margin-bottom: 12px; font-size: 16px;}
.option { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border); margin: 8px 0; cursor: pointer; transition: all 0.2s ease; background: rgba(0,0,0,0.1); }
.option:hover { background: var(--panel-2); border-color: rgba(255,255,255,0.3); }
.option.correct { border-color: rgba(34, 197, 94, 0.5); background: rgba(34, 197, 94, 0.15); }
.option.wrong { border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.15); }

/* Utilities */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; padding: 40px 20px; color: var(--muted); }
.empty-state i { font-size: 48px; opacity: 0.5; margin-bottom: 8px; }

.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff; border-radius: 50%; display: inline-block;
  animation: spin 0.8s linear infinite; margin-right: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

