/* Base CSS Variable Tokens */
html {
    font-size: 18px; /* M→L: ~12.5% over browser 16px default; rem scales app-wide */
}

:root {
    --bg-main: #0a0a0f;
    --bg-card: #12121e;
    --bg-sidebar: #0e0e16;
    --bg-input: #1a1a29;
    
    --border-color: #242438;
    --border-glow: rgba(139, 92, 246, 0.15);
    --border-glow-focus: rgba(6, 182, 212, 0.4);
    
    --accent-primary: #8b5cf6; /* Violet */
    --accent-primary-glow: rgba(139, 92, 246, 0.35);
    --accent-secondary: #06b6d4; /* Teal */
    --accent-secondary-glow: rgba(6, 182, 212, 0.35);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #626773;
    
    --color-success: #10b981;
    --color-success-bg: rgba(16, 185, 129, 0.1);
    --color-danger: #ef4444;
    --color-danger-bg: rgba(239, 68, 68, 0.1);
    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.1);
    
    --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --card-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
    --glow-shadow: 0 0 20px rgba(139, 92, 246, 0.15);
}

/* Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body.dark-theme {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem; /* inherits html 18px */
    line-height: 1.6;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: -0.02em;
}

a {
    color: var(--accent-secondary);
    text-decoration: none;
    transition: var(--transition-smooth);
}
a:hover {
    color: var(--text-primary);
    text-shadow: 0 0 8px var(--accent-secondary-glow);
}

/* App Container Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: 320px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.user-session {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 10px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.user-session-label {
    grid-column: 1 / -1;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.user-session strong {
    overflow: hidden;
    color: var(--accent-secondary);
    font-size: 0.84rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-session-change {
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font: inherit;
    font-size: 0.72rem;
    padding: 0;
}

.user-session-change:hover { color: var(--accent-secondary); }

.app-container--blocked { visibility: hidden; }

.login-gate {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(6, 182, 212, 0.13), transparent 30%),
        radial-gradient(circle at 80% 75%, rgba(139, 92, 246, 0.18), transparent 35%),
        var(--bg-main);
}

.login-card {
    width: min(100%, 440px);
    padding: 38px;
    border: 1px solid rgba(139, 92, 246, 0.38);
    border-radius: 20px;
    background: rgba(18, 18, 30, 0.94);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), 0 0 38px rgba(139, 92, 246, 0.12);
}

.login-mark { font-size: 2.3rem; }
.login-kicker {
    margin-top: 10px;
    color: var(--accent-secondary);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}
.login-card h2 { margin-top: 5px; font-size: 1.7rem; }
.login-card > p:not(.login-kicker):not(.login-error) {
    margin: 10px 0 24px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.login-card label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.82rem;
}
.login-card input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    outline: none;
    padding: 12px 14px;
    background: var(--bg-input);
    color: var(--text-primary);
    font: inherit;
}
.login-card input:focus {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.12);
}
.login-help { display: block; margin-top: 7px; color: var(--text-muted); font-size: 0.7rem; }
.login-error { min-height: 1.3em; margin-top: 10px; color: #fca5a5; font-size: 0.78rem; }
.login-submit { width: 100%; margin-top: 8px; }

.app-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-emoji {
    font-size: 2.2rem;
    animation: pulse 3s infinite ease-in-out;
}

.logo-text h1 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text p {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent-secondary);
    font-weight: 600;
}

/* Stats Widget */
.stats-widget {
    margin: 16px 24px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.stats-widget h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.progress-bar-container {
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    box-shadow: 0 0 10px var(--accent-secondary-glow);
    transition: width 0.5s ease-out;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.nav-section {
    margin-bottom: 24px;
}

.section-title {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 700;
}

.nav-section-collapsible .section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 8px;
    padding: 4px 0;
    border: none;
    background: transparent;
    cursor: pointer;
    color: inherit;
    text-align: left;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.nav-section-collapsible .section-toggle:hover {
    background: rgba(255, 255, 255, 0.04);
}

.nav-section-collapsible .section-toggle .section-title {
    margin-bottom: 0;
}

.nav-section-collapsible .section-chevron {
    flex-shrink: 0;
    margin-left: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.nav-section-collapsible.collapsed .section-chevron {
    transform: rotate(-90deg);
}

.nav-section-collapsible.collapsed .section-body {
    display: none;
}

.nav-section-collapsible .section-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.precedence-graph-root {
    min-height: 380px;
}

.nav-section-learning .section-title {
    color: var(--accent-secondary);
}

.section-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin: -4px 0 14px 0;
}

.learning-unit-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.learning-unit {
    border: 1px solid rgba(6, 182, 212, 0.18);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.18);
    overflow: hidden;
}

.learning-unit-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
}

.learning-unit-toggle:hover {
    background: rgba(6, 182, 212, 0.08);
}

.learning-unit-toggle-main {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
}

.learning-unit-icon {
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1.4;
}

.learning-unit-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.learning-unit-title {
    font-size: 0.86rem;
    font-weight: 650;
    color: var(--text-primary);
}

.learning-unit-sub {
    font-size: 0.68rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.learning-unit-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.learning-unit-progress {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--accent-secondary);
    background: rgba(6, 182, 212, 0.12);
    border-radius: 999px;
    padding: 2px 8px;
}

.learning-unit .section-chevron {
    transition: transform 0.2s ease;
}

.learning-unit:not(.open) .section-chevron {
    transform: rotate(-90deg);
}

.learning-unit:not(.open) .learning-unit-body {
    display: none;
}

.learning-unit-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 10px 12px;
    border-top: 1px solid rgba(6, 182, 212, 0.1);
}

.learning-topic-group {
    margin-bottom: 0;
    padding-top: 8px;
}

.learning-topic-group:last-child {
    margin-bottom: 0;
}

.learning-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 2px 4px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
}

.learning-group-toggle:hover {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}

.learning-topic-label {
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0;
    padding-left: 0;
    font-weight: 600;
}

.learning-group-toggle .section-chevron {
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.learning-topic-group.collapsed .learning-group-toggle .section-chevron {
    transform: rotate(-90deg);
}

.learning-topic-group.collapsed .learning-group-body {
    display: none;
}

.learning-group-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.nav-btn-tutorial {
    border-left: 2px solid rgba(6, 182, 212, 0.3);
}

.nav-btn-tutorial:hover {
    background: rgba(6, 182, 212, 0.08);
}

.nav-btn-tutorial.active {
    border-left-color: var(--accent-secondary);
    background: linear-gradient(90deg, rgba(6, 182, 212, 0.12) 0%, rgba(139, 92, 246, 0.05) 100%);
}

.nav-btn-label {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.nav-btn--completed {
    color: rgba(167, 243, 208, 0.85);
}

.nav-btn--completed .tutorial-step {
    background: rgba(16, 185, 129, 0.25);
    color: #6ee7b7;
}

.nav-btn--completed .nav-completed-mark {
    margin-left: auto;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #6ee7b7;
    background: rgba(16, 185, 129, 0.18);
    border: 1px solid rgba(110, 231, 183, 0.35);
}

.nav-btn-tutorial.nav-btn--completed:not(.active) {
    opacity: 0.82;
}

.tutorial-step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(6, 182, 212, 0.2);
    color: var(--accent-secondary);
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.tutorial-banner {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 20px;
    margin-bottom: 16px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.1) 0%, rgba(139, 92, 246, 0.08) 100%);
    border: 1px solid rgba(6, 182, 212, 0.25);
}

.tutorial-banner-icon {
    font-size: 1.8rem;
    line-height: 1;
}

.tutorial-banner-text strong {
    display: block;
    color: var(--accent-secondary);
    margin-bottom: 4px;
}

.tutorial-banner-text p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

.walkthrough-card {
    margin-bottom: 16px;
    border-color: rgba(6, 182, 212, 0.2);
}

.walkthrough-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 4px 0 12px;
    background: linear-gradient(180deg, var(--bg-card, #121826) 70%, transparent);
}

.walkthrough-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--accent-secondary);
}

.walkthrough-progress {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.walkthrough-pill {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.walkthrough-pill:hover {
    border-color: var(--accent-secondary);
    color: var(--text-primary);
}

.walkthrough-pill.active {
    background: var(--accent-secondary);
    color: #0a0e17;
    border-color: var(--accent-secondary);
}

.walkthrough-pill.completed {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4);
    color: #4ade80;
}

.walkthrough-steps-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.walkthrough-step-card {
    padding: 16px 18px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.18);
    scroll-margin-top: 72px;
}

.walkthrough-step-card.completed {
    border-color: rgba(34, 197, 94, 0.28);
}

.walkthrough-step-heading {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.walkthrough-step-badge {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-secondary);
}

.walkthrough-step-title {
    margin: 0;
    font-size: 1.05rem;
    color: var(--text-primary);
    line-height: 1.35;
}

.walkthrough-theory {
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 8px;
    background: rgba(6, 182, 212, 0.06);
    border-left: 3px solid var(--accent-secondary);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.walkthrough-instruction {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin: 0 0 14px 0;
    line-height: 1.5;
}

.walkthrough-step-question {
    margin-top: 4px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.walkthrough-step-actions {
    margin-top: 12px;
}

.walkthrough-step-feedback {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 8px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.25);
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.walkthrough-step-feedback.incorrect {
    background: rgba(248, 113, 113, 0.08);
    border-color: rgba(248, 113, 113, 0.28);
}

.walkthrough-feedback-icon {
    flex-shrink: 0;
    line-height: 1.4;
}

.tutorial-hint {
    font-size: 0.85rem;
    color: var(--accent-secondary);
    font-style: italic;
    margin-top: 8px;
}

.tutorial-no-question {
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 12px;
    text-align: center;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
}

.nav-btn {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 10px 14px;
    text-align: left;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition-smooth);
    margin-bottom: 4px;
}

.nav-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.nav-btn.active {
    color: var(--text-primary);
    background: linear-gradient(90deg, rgba(139, 92, 246, 0.15) 0%, rgba(6, 182, 212, 0.05) 100%);
    border-left: 3px solid var(--accent-primary);
    box-shadow: inset 0 0 10px rgba(139, 92, 246, 0.05);
}

.btn-icon {
    font-size: 1.1rem;
}

.sidebar-footer {
    padding: 24px;
    border-top: 1px solid var(--border-color);
}

/* Main Content Workspace */
.main-content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    background-color: var(--bg-main);
    padding: 40px;
}

/* Content Views Management */
.content-view {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.content-view.active {
    display: block;
}

/* Cards & Layout Modules */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--card-shadow);
    transition: var(--transition-smooth);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.06);
}

.card-glow {
    position: relative;
    border-color: var(--border-glow);
    box-shadow: var(--glow-shadow), var(--card-shadow);
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    padding-bottom: 12px;
}

.card-header-flex h3 {
    margin-bottom: 0;
}

/* Dashboard View Specifics */
.welcome-header {
    margin-bottom: 32px;
}

.welcome-header h2 {
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #fff 40%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

.dashboard-progress-stats {
    display: flex;
    align-items: center;
    gap: 32px;
    margin-top: 16px;
}

.stat-circle {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.progress-ring {
    transform: rotate(-90deg);
}

.progress-ring-circle {
    transition: stroke-dashoffset 0.5s ease;
}

.ring-value {
    position: absolute;
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
}

.stats-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stats-list p {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.text-glow {
    color: var(--accent-secondary);
    text-shadow: 0 0 10px var(--accent-secondary-glow);
}

.grid-title {
    font-size: 1.3rem;
    margin-bottom: 16px;
    padding-left: 4px;
}

.exercise-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.ex-summary-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 180px;
}

.ex-summary-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-primary);
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.1);
}

.ex-summary-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.ex-summary-badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-secondary);
}

.ex-summary-card h4 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 6px;
    line-height: 1.3;
}

.ex-summary-card p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.ex-summary-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.02);
    padding-top: 10px;
    margin-top: auto;
}

.ex-attempts {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Badge Pills */
.status-pill {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.status-pill.not-started {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
}

.status-pill.completed {
    background-color: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid rgba(16, 185, 129, 0.2);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.1);
}

.status-pill.failed {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-pill.in-progress {
    background-color: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Workspace Interactive Layout */
.workspace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}

.exercise-badge {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--accent-secondary);
}

.workspace-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 32px;
}

.workspace-left {
    display: flex;
    flex-direction: column;
}

.workspace-right {
    display: flex;
    flex-direction: column;
}

/* Statement Card & Schedule block */
.statement-card h3 {
    margin-bottom: 12px;
}

.statement-body {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 16px;
}

.schedule-display {
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-x: auto;
}

.schedule-display.hide {
    display: none;
}

.schedule-linear {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.schedule-section-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.schedule-display code {
    font-family: var(--font-mono);
    color: var(--accent-secondary);
    font-size: 1rem;
    white-space: nowrap;
    text-shadow: 0 0 8px rgba(6, 182, 212, 0.2);
}

.schedule-table-wrap,
.recovery-txn-table-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.schedule-table-scroll {
    overflow-x: auto;
    /* Soft frame — exam tables are open, not Excel cards */
    border: none;
    border-radius: 0;
    padding: 2px 0 4px;
}

/* FIUBA exam-style schedule: txn columns, sparse H-rules, vertical separators */
.schedule-txn-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 0.88rem;
    min-width: 280px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.32);
}

.schedule-txn-table th,
.schedule-txn-table td {
    border: none;
    border-left: 1px solid rgba(255, 255, 255, 0.28);
    padding: 7px 16px;
    text-align: left;
    vertical-align: middle;
    background: transparent;
}

.schedule-txn-table th:last-child,
.schedule-txn-table td:last-child {
    border-right: 1px solid rgba(255, 255, 255, 0.28);
}

.schedule-txn-table thead th {
    text-align: center;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    padding-top: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.32);
    letter-spacing: 0.01em;
}

.schedule-txn-table tbody td {
    /* No per-row horizontal rules — time order is vertical position only */
    border-top: none;
    border-bottom: none;
}

.schedule-txn-table .paso-num {
    width: 2.25rem;
    min-width: 2.25rem;
    max-width: 2.75rem;
    padding-left: 8px;
    padding-right: 8px;
    text-align: center;
    color: rgba(255, 255, 255, 0.28);
    font-size: 0.68rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.schedule-txn-table thead .paso-num {
    font-size: 0.68rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.35);
}

.schedule-txn-table .sys-col,
.schedule-txn-table .sys-op {
    color: var(--text-secondary);
}

.schedule-txn-table .txn-empty {
    /* Keep column width with empty cells */
    min-width: 7rem;
}

.schedule-txn-table .txn-op {
    font-family: var(--font-mono);
    font-size: 0.84rem;
    white-space: nowrap;
}

.schedule-txn-table .txn-t1 { color: #7dd3fc; }
.schedule-txn-table .txn-t2 { color: #f9a8d4; }
.schedule-txn-table .txn-t3 { color: #86efac; }
.schedule-txn-table .txn-t4 { color: #fcd34d; }
.schedule-txn-table .txn-ckpt { color: #c4b5fd; font-style: italic; }
.schedule-txn-table .sys-op {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* Pure concurrency schedule: equal txn columns, no Paso */
.schedule-txn-table--exam {
    table-layout: fixed;
}

.schedule-txn-table--exam .txn-col,
.schedule-txn-table--exam td {
    width: auto;
}

.schedule-table-caption {
    margin: 0;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.recovery-txn-table-wrap {
    margin-bottom: 14px;
}

/* Interactive Card & SVGs */
.interactive-workspace-area {
    margin-top: 16px;
}

.canvas-wrapper {
    background-color: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    cursor: crosshair;
    height: 320px;
}

#graph-svg {
    display: block;
    user-select: none;
    width: 100%;
    height: 100%;
}

/* Graph Node & Edge styles */
.graph-node {
    cursor: grab;
    transition: filter 0.2s;
}
.graph-node:active {
    cursor: grabbing;
}
.graph-node circle {
    fill: var(--bg-card);
    stroke: var(--accent-primary);
    stroke-width: 3;
    transition: var(--transition-smooth);
}
.graph-node:hover circle {
    stroke: var(--accent-secondary);
    filter: drop-shadow(0 0 6px var(--accent-secondary-glow));
}
.graph-node text {
    fill: var(--text-primary);
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    pointer-events: none;
}

.graph-edge {
    stroke: var(--accent-primary);
    stroke-width: 2.5;
    fill: none;
    marker-end: url(#arrow);
    transition: var(--transition-smooth);
}
.graph-edge:hover {
    stroke: var(--accent-secondary);
    stroke-width: 4;
}
.graph-edge.selected {
    stroke: var(--accent-secondary);
    marker-end: url(#arrow-selected);
}

.graph-edge-label {
    fill: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    background: var(--bg-main);
    cursor: pointer;
}

.graph-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.toolbar-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Edge modal */
.edge-creator-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border: 1px solid var(--accent-primary);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.8), 0 0 30px rgba(139, 92, 246, 0.2);
    border-radius: 12px;
    padding: 20px;
    z-index: 100;
    width: 280px;
}

.edge-creator-modal h4 {
    margin-bottom: 12px;
    font-size: 1rem;
    color: var(--accent-secondary);
}

/* Log Recovery Panel */
.log-console-wrapper {
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.log-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.log-table th {
    background-color: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    text-align: left;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
}

.log-table td {
    padding: 8px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.log-row-interactive {
    cursor: pointer;
    transition: var(--transition-smooth);
}

.log-row-interactive:hover {
    background-color: rgba(139, 92, 246, 0.05);
}

.log-row-interactive.selected-rollback {
    background-color: rgba(239, 68, 68, 0.15) !important;
    border-left: 4px solid var(--color-danger);
}

.log-row-interactive.rollback-correct {
    background-color: rgba(16, 185, 129, 0.14) !important;
    border-left: 4px solid var(--color-success);
}

.log-row-interactive.rollback-correct.selected-rollback {
    background-color: rgba(16, 185, 129, 0.22) !important;
    border-left: 4px solid var(--color-success);
}

.log-row-interactive.rollback-incorrect {
    background-color: rgba(239, 68, 68, 0.18) !important;
    border-left: 4px solid var(--color-danger);
}

.rollback-marker-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 2px 8px;
    font-size: 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.log-row-interactive:hover .rollback-marker-btn {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.selected-rollback .rollback-marker-btn {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}

.rollback-correct .rollback-marker-btn,
.rollback-correct.selected-rollback .rollback-marker-btn {
    background: var(--color-success);
    color: #fff;
    border-color: var(--color-success);
}

.rollback-incorrect .rollback-marker-btn {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}

/* Timestamp Simulator Card */
.timestamp-simulator-card {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    margin-top: 12px;
}

.slider-wrapper {
    margin-bottom: 24px;
}

.slider-wrapper label {
    display: block;
    margin-bottom: 12px;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--bg-input);
    outline: none;
    margin-bottom: 8px;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-secondary);
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-secondary-glow);
    transition: transform 0.1s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.slider-ticks {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0 4px;
}

.simulator-responses {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.sim-pill {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: var(--font-heading);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
}

.badge-success {
    background-color: var(--color-success-bg);
    color: var(--color-success);
}

.badge-danger {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
}

/* Quiz questions formatting */
.quiz-card h3 {
    margin-bottom: 20px;
}

.quiz-question-block {
    margin-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    padding-bottom: 20px;
}

.quiz-question-block:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.question-text {
    font-weight: 500;
    font-size: 1rem;
    margin-bottom: 12px;
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.option-item:hover {
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.01);
}

.option-item input[type="radio"],
.option-item input[type="checkbox"] {
    accent-color: var(--accent-secondary);
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.option-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.form-control-text {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition-smooth);
}

.form-control-text:focus {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 10px var(--accent-secondary-glow);
}

.quiz-footer {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    align-items: center;
}

.quiz-footer-reset {
    margin-left: auto;
}

/* Notes Text Area */
.notes-card {
    height: 380px;
    display: flex;
    flex-direction: column;
}

.notes-help {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

#notes-textarea {
    flex: 1;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    resize: none;
    outline: none;
    transition: var(--transition-smooth);
}

#notes-textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px var(--accent-primary-glow);
}

.save-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    padding: 2px 8px;
    border-radius: 4px;
}

.save-status.saving {
    color: var(--color-warning);
}

.save-status.saved {
    color: var(--color-success);
}

/* Attempt history */
.history-card {
    flex: 1;
    min-height: 200px;
    display: flex;
    flex-direction: column;
}

.history-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.history-card-header h3 {
    margin: 0;
}

.history-export-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.history-export-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0 0 10px;
    line-height: 1.4;
}

.panel-actions-inner {
    display: flex;
    align-items: center;
    gap: 12px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    max-height: 250px;
}

.no-history-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 24px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 12px;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    font-size: 0.8rem;
    background: transparent;
    color: inherit;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.15s ease;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.history-item--active {
    background: rgba(139, 92, 246, 0.12);
    outline: 1px solid rgba(139, 92, 246, 0.25);
}

.history-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-action {
    color: var(--accent-primary);
    font-size: 0.72rem;
    font-weight: 600;
    opacity: 0.85;
}

.history-time {
    color: var(--text-muted);
}

.history-status-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
}

.history-status-badge.correct {
    background-color: var(--color-success-bg);
    color: var(--color-success);
}

.history-status-badge.incorrect {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
}

/* Graded feedback panel styles */
.feedback-card {
    border-left: 4px solid var(--color-success);
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.05) 0%, transparent 100%);
    animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.feedback-card.incorrect {
    border-left-color: var(--color-danger);
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.05) 0%, transparent 100%);
}

.feedback-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.feedback-icon {
    font-size: 1.5rem;
}

.feedback-body p {
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.feedback-body code {
    font-family: var(--font-mono);
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent-secondary);
}

/* Buttons Styles */
.btn {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.85rem;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary) 0%, #7c3aed 100%);
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-primary-glow);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
}

.btn-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.75rem;
}

.btn-danger-outline {
    background: transparent;
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--color-danger);
    width: 100%;
}
.btn-danger-outline:hover {
    background: var(--color-danger-bg);
    border-color: var(--color-danger);
}

/* Form Styles */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.form-control {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 6px;
    color: #fff;
    outline: none;
}
.form-control:focus {
    border-color: var(--accent-primary);
}
.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* Cheat Sheet Tabs Styling */
.cheat-sheet-tabs {
    display: flex;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 24px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    font-family: var(--font-heading);
    font-weight: 500;
    cursor: pointer;
    font-size: 1rem;
    border-radius: 6px;
    transition: var(--transition-smooth);
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
}

.tab-btn.active {
    color: var(--accent-secondary);
    background: rgba(6, 182, 212, 0.05);
    border: 1px solid rgba(6, 182, 212, 0.15);
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.05);
}

.tab-contents .tab-pane {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.tab-contents .tab-pane.active {
    display: block;
}

/* Tables styling */
.simple-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 0.9rem;
}

.simple-table th {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    text-align: left;
}

.simple-table td {
    border: 1px solid var(--border-color);
    padding: 10px 14px;
}

.formula-block {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 16px;
    border-radius: 8px;
    text-align: center;
    font-family: var(--font-mono);
    color: var(--accent-secondary);
    margin: 16px 0;
    font-size: 1.1rem;
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 16px 0;
    font-size: 0.9rem;
}

.alert-info {
    background: rgba(139, 92, 246, 0.05);
    border: 1px solid rgba(139, 92, 246, 0.15);
    color: var(--text-primary);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.05);
    border: 1px solid rgba(245, 158, 11, 0.15);
    color: var(--text-primary);
}

.rec-comparison {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-top: 16px;
}

.rec-column {
    background-color: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    padding: 16px;
    border-radius: 12px;
}

.rec-column h4 {
    color: var(--accent-secondary);
    margin-bottom: 12px;
}

.styled-list {
    margin-left: 20px;
    margin-top: 10px;
    margin-bottom: 10px;
}

.styled-list li {
    margin-bottom: 8px;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.4)); }
}

.hide {
    display: none !important;
}

/* Utility Helpers */
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }

/* Position containment for modal dialogs */
.interactive-card {
    position: relative;
}

/* ========================================== */
/* RESPONSIVE LAYOUT & MOBILE CUSTOMIZATION */
/* ========================================== */

/* Mobile Navbar - Hidden by default on Desktop */
.mobile-navbar {
    display: none;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    height: 56px;
    background-color: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    padding: 0 16px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 8;
}

.mobile-menu-toggle {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-navbar-title {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.open {
    display: block;
    opacity: 1;
}

/* ── Tall / vertical desktop (2K+ height) — desktop widths only ── */
@media (min-width: 769px) and (min-height: 1200px) {
    .main-content {
        padding: 28px 40px 48px;
    }

    .welcome-header h2 {
        font-size: 2rem;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 20px;
        margin-bottom: 24px;
    }

    .dashboard-progress-stats {
        gap: 40px;
    }

    .exercise-cards-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .ex-summary-card {
        height: auto;
        min-height: 150px;
    }

    /* Vertical-first exercise layout: main column, then notes/history row */
    .workspace-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .workspace-right {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        align-items: start;
    }

    .workspace-right .card {
        margin-bottom: 0;
        height: 100%;
    }

    .notes-card {
        height: auto;
        min-height: clamp(280px, 28vh, 420px);
    }

    .history-card {
        min-height: clamp(280px, 28vh, 420px);
    }

    .history-list {
        max-height: clamp(220px, 22vh, 360px);
    }

    .log-console-wrapper {
        max-height: clamp(360px, 40vh, 680px);
    }

    .canvas-wrapper {
        height: clamp(360px, 36vh, 520px);
    }

    .workspace-header {
        position: sticky;
        top: 0;
        z-index: 5;
        background: linear-gradient(180deg, var(--bg-main) 70%, transparent);
        padding: 12px 0 20px;
        margin-bottom: 8px;
    }

    .walkthrough-card {
        margin-bottom: 20px;
    }

    .walkthrough-steps-list {
        gap: 28px;
    }

    .walkthrough-step-card {
        padding: 20px 22px;
    }

    .tutorial-banner {
        margin-bottom: 20px;
    }

    .card {
        margin-bottom: 20px;
    }

    .workspace-left .card:last-child {
        margin-bottom: 0;
    }
}

@media (min-width: 769px) and (min-height: 1600px) {
    .main-content {
        padding: 32px 48px 56px;
    }

    .exercise-cards-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .log-console-wrapper {
        max-height: clamp(440px, 44vh, 780px);
    }

    .canvas-wrapper {
        height: clamp(420px, 40vh, 580px);
    }

    .notes-card,
    .history-card {
        min-height: clamp(320px, 30vh, 480px);
    }

    .history-list {
        max-height: clamp(260px, 26vh, 420px);
    }

    .sidebar-nav {
        padding: 12px 20px;
    }

    .nav-section {
        margin-bottom: 18px;
    }

    .nav-btn {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .nav-section-learning {
        padding: 14px;
    }
}

@media (min-width: 769px) and (min-height: 2000px) {
    .log-console-wrapper {
        max-height: clamp(520px, 46vh, 900px);
    }

    .canvas-wrapper {
        height: clamp(480px, 42vh, 640px);
    }

    .notes-card,
    .history-card {
        min-height: clamp(360px, 32vh, 540px);
    }
}

/* Portrait desktop monitors (rotated 2K/QHD) */
@media (orientation: portrait) and (min-width: 1000px) and (min-height: 1400px) {
    .sidebar {
        width: 280px;
    }

    .main-content {
        padding: 24px 32px 40px;
    }

    .workspace-grid {
        grid-template-columns: 1fr;
    }

    .workspace-right {
        grid-template-columns: 1fr;
    }

    .exercise-cards-container {
        grid-template-columns: 1fr;
    }

    .dashboard-progress-stats {
        flex-direction: row;
    }
}

/* Wide + short: keep classic side-by-side workspace */
@media (min-width: 1280px) and (max-height: 1199px) {
    .workspace-grid {
        grid-template-columns: 1.6fr 1fr;
    }

    .workspace-right {
        display: flex;
        flex-direction: column;
    }
}

/* Tablet & Smaller Layout Breakpoints — overrides tall-desktop when narrower */
@media (max-width: 1024px) {
    .workspace-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .workspace-right {
        display: flex;
        flex-direction: column;
        grid-template-columns: unset;
        gap: 0;
    }

    .workspace-right .card {
        height: auto;
        margin-bottom: 24px;
    }

    .workspace-right .card:last-child {
        margin-bottom: 0;
    }

    .notes-card {
        height: auto;
        min-height: unset;
    }

    .history-card {
        min-height: unset;
    }

    .history-list {
        max-height: 220px;
    }

    .log-console-wrapper {
        max-height: 280px;
    }

    .canvas-wrapper {
        height: 300px;
    }

    .workspace-header {
        position: static;
        background: none;
        padding: 0;
        margin-bottom: 28px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .exercise-cards-container {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    }
}

/* Mobile Layout Breakpoints */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        position: fixed;
        left: -320px;
        top: 0;
        bottom: 0;
        height: 100vh;
        width: 290px;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 10;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.8);
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .mobile-navbar {
        display: flex;
    }
    
    .main-content {
        padding: 72px 16px 32px 16px;
        height: auto;
        min-height: 100vh;
    }
    
    .welcome-header h2 {
        font-size: 1.8rem;
    }
    
    .dashboard-progress-stats {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    
    .rec-comparison {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .rules-block {
        grid-template-columns: 1fr !important;
    }

    .workspace-right {
        display: flex;
        flex-direction: column;
    }

    .notes-card,
    .history-card {
        min-height: unset;
    }

    .history-list {
        max-height: 180px;
    }

    .log-console-wrapper {
        max-height: 240px;
    }

    .canvas-wrapper {
        height: 260px;
    }

    .exercise-cards-container {
        grid-template-columns: 1fr;
    }

    .workspace-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .exercise-actions {
        width: 100%;
    }

    .tutorial-banner {
        flex-direction: column;
        gap: 10px;
        padding: 14px 16px;
    }

    .walkthrough-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .walkthrough-step-card {
        padding: 14px 16px;
    }

    .graph-toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .quiz-footer {
        flex-direction: column;
    }

    .quiz-footer .btn {
        width: 100%;
    }

    .card {
        padding: 18px;
        border-radius: 12px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .main-content {
        padding: 68px 12px 24px 12px;
    }

    .welcome-header h2 {
        font-size: 1.5rem;
    }

    .walkthrough-pill {
        width: 24px;
        height: 24px;
        font-size: 0.7rem;
    }

    .log-table {
        font-size: 0.8rem;
    }

    .log-table th,
    .log-table td {
        padding: 6px 10px;
    }

    .rollback-marker-btn {
        font-size: 0.65rem;
        padding: 4px 6px;
    }

    .nav-section-learning {
        padding: 10px;
    }

    .section-subtitle {
        font-size: 0.7rem;
    }
}

/* Clickable Attempts History Items */
.clickable-attempt {
    cursor: pointer;
    transition: var(--transition-smooth);
    border: 1px solid transparent;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.01) !important;
}

.clickable-attempt:hover {
    background: rgba(139, 92, 246, 0.05) !important;
    border-color: rgba(139, 92, 246, 0.15);
}

.active-attempt {
    background: rgba(139, 92, 246, 0.1) !important;
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.15);
}

.attempt-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.load-prompt {
    font-size: 0.65rem;
    color: var(--accent-secondary);
    font-weight: 700;
    text-transform: uppercase;
    display: block;
    text-align: right;
    margin-top: 4px;
    letter-spacing: 0.02em;
}

.badge-alert-pulse {
    font-size: 0.7rem;
    font-weight: 700;
    background-color: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 8px;
    display: inline-block;
    animation: alertPulse 2s infinite;
}

@keyframes alertPulse {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.02); }
}

/* ========================================== */
/* AI TUTOR CHAT MODAL                       */
/* ========================================== */

.ai-insights-modal {
    position: fixed;
    top: auto;
    left: auto;
    right: 24px;
    bottom: 96px;
    transform: none;
    background:
        radial-gradient(1200px 400px at 0% 0%, rgba(6, 182, 212, 0.08), transparent 55%),
        radial-gradient(900px 360px at 100% 0%, rgba(139, 92, 246, 0.14), transparent 50%),
        rgba(14, 14, 22, 0.96);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 28px 70px -20px rgba(0, 0, 0, 0.85),
        0 0 0 1px rgba(139, 92, 246, 0.12),
        0 0 40px rgba(139, 92, 246, 0.12);
    border-radius: 18px;
    z-index: 120;
    width: min(920px, calc(100vw - 24px));
    height: min(88vh, 920px);
    max-height: min(88vh, 920px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiPanelIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-modal-shell {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100%;
}

.ai-thread-sidebar {
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.ai-thread-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 10px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ai-thread-sidebar-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.ai-thread-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-thread-item {
    appearance: none;
    width: 100%;
    text-align: left;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 10px;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.ai-thread-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.ai-thread-item.is-active {
    background: rgba(139, 92, 246, 0.14);
    border-color: rgba(139, 92, 246, 0.35);
    color: var(--text-primary);
}

.ai-thread-item-title {
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-thread-item-meta {
    font-size: 0.7rem;
    opacity: 0.75;
}

.ai-thread-empty {
    padding: 16px 10px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-align: center;
}

.ai-modal-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ai-insights-modal.is-dragging {
    animation: none;
    cursor: grabbing;
    user-select: none;
}

@keyframes aiPanelIn {
    from { opacity: 0; transform: translateY(14px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-tutor-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 119;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    border: 1px solid rgba(139, 92, 246, 0.45);
    background: linear-gradient(145deg, #8b5cf6, #06b6d4);
    color: #fff;
    box-shadow: 0 12px 28px rgba(139, 92, 246, 0.35);
    cursor: grab;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-tutor-fab:hover:not(.is-dragging) {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 16px 34px rgba(139, 92, 246, 0.45);
}

.ai-tutor-fab:active:not(.is-dragging) { transform: scale(0.97); }
.ai-tutor-fab.is-dragging {
    cursor: grabbing;
    transition: none;
    transform: none;
}

.ai-tutor-fab-icon {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1;
}

.ai-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 14px 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    cursor: grab;
    touch-action: none;
    flex-shrink: 0;
}

.ai-insights-modal.is-dragging .ai-modal-header { cursor: grabbing; }

.ai-modal-title-block {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.ai-modal-avatar {
    width: 36px;
    height: 36px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: linear-gradient(145deg, rgba(139, 92, 246, 0.95), rgba(6, 182, 212, 0.85));
    color: #fff;
    font-weight: 700;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.ai-modal-title-text { min-width: 0; }

.ai-modal-title-text h3 {
    margin: 0;
    font-size: 1.05rem;
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.ai-modal-subtitle {
    margin: 2px 0 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.ai-modal-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: default;
    flex-shrink: 0;
}

.ai-modal-drag-handle { cursor: grab; }

.ai-icon-btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    border-radius: 10px;
    padding: 7px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ai-icon-btn:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.16);
}

.ai-icon-btn.is-active,
.ai-icon-btn.btn-primary {
    background: rgba(6, 182, 212, 0.16);
    border-color: rgba(6, 182, 212, 0.4);
    color: #67e8f9;
}

.ai-icon-btn--close {
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 1.35rem;
    line-height: 1;
    display: grid;
    place-items: center;
}

.ai-icon-btn--close:hover {
    color: var(--color-danger);
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.08);
}

.ai-context-strip {
    padding: 10px 14px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.18);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-context-exercise {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ai-context-kicker,
.ai-selected-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.ai-context-exercise strong {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-selected-bar {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.ai-selected-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.ai-chip {
    border: 1px solid rgba(6, 182, 212, 0.28);
    background: rgba(6, 182, 212, 0.1);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.72rem;
    cursor: pointer;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.ai-chip:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
}

.ai-chip--active {
    border-color: rgba(16, 185, 129, 0.45);
    background: rgba(16, 185, 129, 0.14);
}

.ai-activity-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-bottom: 1px solid rgba(6, 182, 212, 0.18);
    background: rgba(6, 182, 212, 0.08);
    color: #a5f3fc;
    font-size: 0.8rem;
    line-height: 1.35;
    flex-shrink: 0;
    min-height: 36px;
}

.ai-activity-bar[hidden] { display: none !important; }

.ai-activity-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-activity-dot {
    width: 7px;
    height: 7px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #22d3ee;
    box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.45);
    animation: aiPulse 1.4s ease-out infinite;
}

@keyframes aiPulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.45); }
    70% { box-shadow: 0 0 0 8px rgba(34, 211, 238, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
}

.ai-modal-body {
    padding: 14px 14px 8px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    color: var(--text-secondary);
    line-height: 1.65;
    font-size: 0.92rem;
    scroll-behavior: smooth;
}

.ai-modal-body p { margin-bottom: 12px; }
.ai-modal-body strong { color: var(--text-primary); font-weight: 600; }
.ai-modal-body ul, .ai-modal-body ol { margin-bottom: 14px; padding-left: 20px; }
.ai-modal-body li { margin-bottom: 6px; }
.ai-modal-body h1, .ai-modal-body h2, .ai-modal-body h3, .ai-modal-body h4 {
    color: var(--text-primary);
    font-family: var(--font-heading);
    font-weight: 700;
    margin-top: 16px;
    margin-bottom: 8px;
}
.ai-modal-body h2 {
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 4px;
    color: var(--accent-secondary);
}
.ai-modal-body h3 { font-size: 1.02rem; }
.ai-modal-body h4 { font-size: 0.95rem; color: var(--accent-primary); }
.ai-modal-body hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin: 14px 0;
}
.ai-modal-body blockquote {
    border-left: 3px solid var(--accent-primary);
    background: rgba(139, 92, 246, 0.06);
    padding: 10px 14px;
    margin: 12px 0;
    border-radius: 0 8px 8px 0;
    color: var(--text-primary);
}
.ai-modal-body code {
    font-family: var(--font-mono);
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.84em;
    color: #e0a7ff;
}
.ai-modal-body pre {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 12px;
    overflow-x: auto;
    margin-bottom: 12px;
}
.ai-modal-body pre code { background: none; padding: 0; color: #f1f1f1; }

.ai-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.ai-chat-empty-state {
    margin: auto 0;
    text-align: center;
    padding: 28px 12px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.ai-empty-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(145deg, rgba(139, 92, 246, 0.35), rgba(6, 182, 212, 0.25));
    color: #fff;
    font-weight: 700;
    margin-bottom: 4px;
}

.ai-chat-empty-state h4 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.05rem;
}

.ai-chat-empty-state p {
    margin: 0;
    max-width: 300px;
    color: var(--text-secondary);
    font-size: 0.84rem;
    line-height: 1.5;
}

.ai-suggestion-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.ai-suggestion {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 0.76rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.ai-suggestion:hover {
    background: rgba(139, 92, 246, 0.16);
    border-color: rgba(139, 92, 246, 0.35);
    transform: translateY(-1px);
}

.ai-chat-bubble {
    max-width: 94%;
    padding: 11px 13px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    animation: aiMsgIn 0.22s ease-out;
}

@keyframes aiMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-chat-bubble--user {
    align-self: flex-end;
    background: linear-gradient(160deg, rgba(139, 92, 246, 0.28), rgba(139, 92, 246, 0.12));
    border-color: rgba(139, 92, 246, 0.28);
    border-bottom-right-radius: 5px;
}

.ai-chat-bubble--assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.035);
    border-bottom-left-radius: 5px;
}

.ai-chat-bubble--pending .ai-chat-bubble-content:has(.ai-live-status-inline) {
    min-height: 1.2em;
}

.ai-live-status-inline {
    color: #a5f3fc;
    font-size: 0.84rem;
    font-style: italic;
    line-height: 1.45;
    opacity: 0.95;
}

/* Caret only while tokens stream — never on an empty pending bubble */
.ai-stream-cursor:not(:empty)::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 1.05em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: rgba(34, 211, 238, 0.85);
    border-radius: 1px;
    animation: aiCaret 0.9s steps(1) infinite;
}

@keyframes aiCaret {
    50% { opacity: 0; }
}

.ai-chat-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.ai-chat-avatar {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    display: grid;
    place-items: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.ai-chat-bubble--user .ai-chat-avatar {
    background: rgba(139, 92, 246, 0.45);
    color: #fff;
}

.ai-chat-bubble--assistant .ai-chat-avatar {
    background: linear-gradient(145deg, #8b5cf6, #06b6d4);
    color: #fff;
}

.ai-chat-bubble-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    text-transform: none;
    margin: 0;
}

.ai-chat-bubble-content {
    color: var(--text-primary);
    line-height: 1.55;
    font-size: 0.9rem;
}

.ai-chat-bubble-content p:last-child { margin-bottom: 0; }

.ai-chat-error {
    margin: 0;
    text-align: center;
    font-size: 0.85rem;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--color-danger-bg);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #fca5a5;
}

.ai-chat-bubble--trace {
    align-self: stretch;
    max-width: 100%;
    background: rgba(0, 0, 0, 0.28);
    border-style: dashed;
    border-color: rgba(255, 255, 255, 0.1);
    padding: 10px 12px;
}

.ai-agent-trace {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

.ai-trace-row { color: var(--text-secondary); }
.ai-trace-row--tool { color: #7dd3fc; }
.ai-trace-row--tool-end { color: #86efac; }
.ai-trace-row--status { color: #c4b5fd; }

.ai-modal-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(0, 0, 0, 0.22);
    flex-shrink: 0;
}

.ai-chat-composer { display: flex; flex-direction: column; gap: 8px; }

.ai-composer-shell {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-composer-shell:focus-within {
    border-color: rgba(6, 182, 212, 0.45);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.12);
}

.ai-chat-input {
    flex: 1;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 8px 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.45;
    outline: none;
}

.ai-chat-input:disabled { opacity: 0.55; }

.ai-send-btn {
    appearance: none;
    border: none;
    border-radius: 11px;
    min-width: 42px;
    height: 42px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(145deg, #8b5cf6, #06b6d4);
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
}

.ai-send-btn:hover:not(:disabled) {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.ai-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.ai-send-label { display: none; }
.ai-send-arrow { font-size: 1.1rem; line-height: 1; }

.ai-composer-hint {
    margin: 0;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
}

body.ai-select-mode { cursor: crosshair; }

body.ai-select-mode .nav-btn[data-target],
body.ai-select-mode #view-exercise[data-exercise-id],
body.ai-select-mode #ex-title,
body.ai-select-mode #ex-badge {
    outline: 2px dashed rgba(6, 182, 212, 0.6);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.08);
}

body.ai-select-mode .nav-btn[data-target]:hover,
body.ai-select-mode #view-exercise[data-exercise-id]:hover {
    outline-color: rgba(16, 185, 129, 0.85);
}

body.ai-select-mode #ai-modal {
    outline: 2px solid rgba(6, 182, 212, 0.35);
}

.ai-spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    gap: 14px;
}

.ai-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(139, 92, 246, 0.15);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.85s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
    .ai-insights-modal {
        right: 8px;
        left: 8px;
        bottom: 8px;
        width: auto;
        height: min(92vh, 860px);
        max-height: min(92vh, 860px);
        border-radius: 16px;
    }

    .ai-modal-subtitle { max-width: 140px; }
    .ai-icon-btn { padding: 6px 8px; font-size: 0.7rem; }
    .ai-send-label { display: none; }
}
