:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: rgba(37, 99, 235, 0.1);
    --accent: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --purple: #8b5cf6;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --radius: 14px;
    --radius-sm: 9px;
    --font-sans: 'Cairo', 'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1e293b;
    --border: #273449;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: rgba(59, 130, 246, 0.15);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Header & Navigation */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.7rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}

.brand-badge {
    background: linear-gradient(135deg, var(--primary), var(--purple));
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 1.1rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.18s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons & Inputs */
.btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-purple { background: var(--purple); color: #fff; border-color: var(--purple); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary-soft);
    border-color: var(--primary);
}

/* Layout */
.container {
    max-width: 1380px;
    margin: 0 auto;
    padding: 1.5rem;
}

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.stat-value {
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--primary);
}
.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-success { background: rgba(16, 185, 129, 0.14); color: var(--success); border-color: transparent; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); border-color: transparent; }
.badge-danger { background: rgba(239, 68, 68, 0.14); color: var(--danger); border-color: transparent; }
.badge-purple { background: rgba(139, 92, 246, 0.15); color: var(--purple); border-color: transparent; }

/* Studio & Rozan Note-Taking Pad */
.studio-layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 1.25rem;
    align-items: start;
}
@media (max-width: 1024px) {
    .studio-layout { grid-template-columns: 1fr; }
}

.pad-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.pad-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.pad-canvas-container {
    position: relative;
    background: #fffdf7;
    overflow: auto;
    display: flex;
    justify-content: center;
    padding: 0.5rem;
}

canvas.rozan-canvas {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
    cursor: crosshair;
    touch-action: none;
    max-width: 100%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.symbols-dock {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
}

.symbol-section-title {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.symbol-palette {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 0.4rem;
    padding: 0.25rem 0;
}

.pad-wrapper:fullscreen,
.pad-wrapper.is-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    display: flex !important;
    flex-direction: column !important;
    border-radius: 0 !important;
    border: none !important;
    background: var(--surface) !important;
}

.pad-wrapper:fullscreen .pad-toolbar,
.pad-wrapper.is-fullscreen .pad-toolbar {
    order: 1;
    flex-shrink: 0;
}

.pad-wrapper:fullscreen .symbols-dock,
.pad-wrapper.is-fullscreen .symbols-dock {
    order: 2;
    flex-shrink: 0;
    max-height: 128px;
    overflow-y: auto;
    padding: 0.35rem 0.75rem;
    border-top: none;
    border-bottom: 1px solid var(--border);
    gap: 0.25rem;
}

.pad-wrapper:fullscreen .symbol-section,
.pad-wrapper.is-fullscreen .symbol-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pad-wrapper:fullscreen .symbol-section-title,
.pad-wrapper.is-fullscreen .symbol-section-title {
    margin-bottom: 0;
    white-space: nowrap;
    min-width: 92px;
}

.pad-wrapper:fullscreen .symbol-palette,
.pad-wrapper.is-fullscreen .symbol-palette {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.35rem;
    padding: 0.15rem 0;
    flex: 1;
}

.pad-wrapper:fullscreen .symbol-chip,
.pad-wrapper.is-fullscreen .symbol-chip {
    min-width: 58px;
    flex-shrink: 0;
    padding: 0.25rem 0.4rem;
}

.pad-wrapper:fullscreen .pad-canvas-container,
.pad-wrapper.is-fullscreen .pad-canvas-container {
    order: 3;
    flex: 1 1 auto;
    min-height: 0;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
}

.pad-wrapper:fullscreen canvas.rozan-canvas,
.pad-wrapper.is-fullscreen canvas.rozan-canvas {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain;
}

.symbol-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.25rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}
.symbol-chip:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    background: var(--primary-soft);
}
.symbol-chip .sym-glyph { font-size: 1.15rem; font-weight: 800; display: block; }
.symbol-chip .sym-name { font-size: 0.68rem; color: var(--text-muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td {
    padding: 0.75rem 0.85rem;
    border-bottom: 1px solid var(--border);
    text-align: start;
}
th {
    background: var(--surface-2);
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
}
tr:hover td { background: var(--surface-2); }

/* Timeline & Audio Bar */
.audio-panel {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.9rem;
    margin-bottom: 1rem;
}

.progress-bar-wrap {
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin: 0.6rem 0;
    cursor: pointer;
}
.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    width: 0%;
    transition: width 0.15s linear;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

/* Auth Screen */
.auth-hero {
    max-width: 920px;
    margin: 2.5rem auto;
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 2rem;
    align-items: center;
}
@media (max-width: 820px) {
    .auth-hero { grid-template-columns: 1fr; }
}

.toast {
    position: fixed;
    bottom: 1.5rem;
    inset-inline-end: 1.5rem;
    background: #0f172a;
    color: #fff;
    padding: 0.75rem 1.2rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 200;
    box-shadow: var(--shadow-md);
    display: none;
}
.toast.show { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); font-size: 0.88rem; }

/* Cognitive Load Timeline */
.cog-timeline {
    position: relative;
    height: 28px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin: 0.5rem 0;
}
.cog-tick-stroke {
    position: absolute;
    top: 4px;
    bottom: 4px;
    width: 4px;
    background: var(--primary);
    border-radius: 2px;
    cursor: pointer;
    opacity: 0.85;
}
.cog-tick-pause {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(239, 68, 68, 0.28);
    border-inline: 1px solid var(--danger);
    cursor: pointer;
}

/* Numbers & Connectors Radar */
.radar-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.radar-pill-ok {
    background: rgba(16, 185, 129, 0.14);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.35);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}
.radar-pill-miss {
    background: rgba(245, 158, 11, 0.14);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.35);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

/* Print / Academic PDF Report */
@media print {
    .topbar, .pad-toolbar, #backDashBtn, #replayNotesBtn, #toggleRedPenBtn, #toggleGhostBtn, #saveIdealBtn, #printReportBtn, #corpusTagForm, .btn {
        display: none !important;
    }
    body { background: #fff; color: #000; }
    .card, .pad-wrapper { box-shadow: none; border-color: #cbd5e1; break-inside: avoid; }
}
