/* ================================================================
   Simulations - Shared Stylesheet
   ----------------------------------------------------------------
   Used by: linux/, md/, python/, sql/ tutorials.
   Each tutorial's own styles.css handles specialized components.

   Fonts:   Atkinson Hyperlegible (body) · Comfortaa (headings)
   Primary: #0046ad
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400;1,700&family=Comfortaa:wght@400;600;700&display=swap');


/* ============================================================
   1. CSS Variables & Theme System
   ============================================================ */

:root {
    --color-primary:      #0046ad;
    --color-primary-dark: #003388;
    --color-success:      #16a34a;
    --color-warning:      #f59e0b;
    --color-error:        #dc2626;

    /* Light mode surfaces */
    --bg-primary:    #ffffff;
    --bg-secondary:  #f8f9fa;
    --bg-tertiary:   #e8ecf1;
    --text-primary:  #1f2937;
    --text-secondary:#6b7280;
    --text-tertiary: #9ca3af;
    --border-color:  #d1d5db;
    --border-light:  #e5e7eb;
    --editor-bg:     #f3f4f6;
    --editor-border: #d1d5db;
    --preview-bg:    #ffffff;

    /* Spacing scale */
    --spacing-xs:  0.25rem;
    --spacing-sm:  0.5rem;
    --spacing-md:  1rem;
    --spacing-lg:  1.5rem;
    --spacing-xl:  2rem;
    --spacing-2xl: 3rem;

    /* Typography */
    --font-sans:    "Atkinson Hyperlegible", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-heading: "Comfortaa", "Segoe UI", sans-serif;
    --font-mono:    "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-primary:      #5c9ee8;
        --color-primary-dark: #4480cc;
        --bg-primary:    #1a1a1a;
        --bg-secondary:  #2d2d2d;
        --bg-tertiary:   #3a3a3a;
        --text-primary:  #edf0f4;
        --text-secondary:#c1c9d4;
        --text-tertiary: #8f9aaa;
        --border-color:  #4b5563;
        --border-light:  #3a3a3a;
        --editor-bg:     #2a2a2a;
        --editor-border: #3a3a3a;
        --preview-bg:    #242424;
    }
}

body.dark-mode {
    --color-primary:      #5c9ee8;
    --color-primary-dark: #4480cc;
    --bg-primary:    #1a1a1a;
    --bg-secondary:  #2d2d2d;
    --bg-tertiary:   #3a3a3a;
    --text-primary:  #edf0f4;
    --text-secondary:#c1c9d4;
    --text-tertiary: #8f9aaa;
    --border-color:  #4b5563;
    --border-light:  #3a3a3a;
    --editor-bg:     #2a2a2a;
    --editor-border: #3a3a3a;
    --preview-bg:    #242424;
}

body.light-mode {
    --bg-primary:    #ffffff;
    --bg-secondary:  #f8f9fa;
    --bg-tertiary:   #e8ecf1;
    --text-primary:  #1f2937;
    --text-secondary:#6b7280;
    --text-tertiary: #9ca3af;
    --border-color:  #d1d5db;
    --border-light:  #e5e7eb;
    --editor-bg:     #f3f4f6;
    --editor-border: #d1d5db;
    --preview-bg:    #ffffff;
}


/* ============================================================
   2. Base / Reset
   ============================================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    height: 100%;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    line-height: 1.6;
    transition: background-color 0.2s ease, color 0.2s ease;
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 2px;
}

button {
    font-family: var(--font-sans);
    cursor: pointer;
}


/* ============================================================
   3. Header
   ============================================================ */

header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    padding: var(--spacing-md) 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--spacing-md);
}

.header-left {
    flex: 1;
    min-width: 0;
}

header h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: -0.3px;
    margin-bottom: var(--spacing-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-container {
    width: 100%;
    height: 6px;
    background: var(--border-light);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: var(--spacing-xs);
}

#progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-primary-dark));
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: block;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.15s ease, transform 0.15s ease;
    flex-shrink: 0;
    color: var(--text-primary);
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    transform: translateY(-1px);
}


/* ============================================================
   4. Main Two-Pane Layout
   ============================================================ */

.main-container {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--spacing-lg);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-lg);
    width: 100%;
    min-height: 0;
}

.pane {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: var(--spacing-xl);
    overflow: auto;
    min-height: 500px;
    box-shadow: var(--shadow-sm);
}

.instruction-pane {
    background: var(--bg-secondary);
}

.interactive-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}


/* ============================================================
   5. Instruction Pane Content
   ============================================================ */

/* lesson-* classes (used by python / linux JS rendering) */

.lesson-meta {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--spacing-xs);
}

.lesson-title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1.3;
    margin-bottom: var(--spacing-md);
}

.lesson-body p {
    line-height: 1.7;
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.lesson-body h3 {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-primary);
    margin-top: var(--spacing-lg);
    margin-bottom: var(--spacing-sm);
}

.lesson-body ul,
.lesson-body ol {
    padding-left: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
    line-height: 1.8;
}

.lesson-body li {
    margin-bottom: var(--spacing-xs);
    color: var(--text-primary);
}

.lesson-body code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--bg-tertiary);
    color: var(--color-primary);
    padding: 0.1em 0.4em;
    border-radius: 3px;
}

.lesson-body pre {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: 8px;
    overflow-x: auto;
    margin: var(--spacing-md) 0;
    border-left: 3px solid var(--color-primary);
}

.lesson-body pre code {
    background: none;
    color: inherit;
    padding: 0;
}

/* Direct selectors used by md / sql JS rendering (h2 title + injected HTML) */

.instruction-pane h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: var(--spacing-md);
}

.instruction-pane h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-primary);
    margin-top: var(--spacing-lg);
    margin-bottom: var(--spacing-sm);
}

.instruction-pane p {
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
    line-height: 1.7;
}

.instruction-pane code {
    background: var(--bg-tertiary);
    padding: 0.125rem 0.4rem;
    border-radius: 0.25rem;
    font-family: var(--font-mono);
    font-size: 0.9em;
    color: var(--color-primary);
}

.instruction-pane pre {
    background: var(--bg-tertiary);
    padding: var(--spacing-md);
    border-radius: 0.5rem;
    overflow-x: auto;
    margin-bottom: var(--spacing-md);
    border-left: 3px solid var(--color-primary);
}

.instruction-pane pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.instruction-pane ul,
.instruction-pane ol {
    margin-bottom: var(--spacing-md);
    padding-left: var(--spacing-xl);
}

.instruction-pane li {
    margin-bottom: var(--spacing-xs);
    color: var(--text-secondary);
}

.instruction-pane strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Callout boxes */
.callout {
    background: rgba(0, 70, 173, 0.06);
    border-left: 3px solid var(--color-primary);
    padding: var(--spacing-md);
    border-radius: 0 6px 6px 0;
    margin: var(--spacing-md) 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.callout strong        { color: var(--text-primary); }
.callout.note          { border-left-color: var(--color-primary); background: rgba(0, 70, 173, 0.06); }
.callout.warning       { border-left-color: var(--color-warning); background: rgba(245, 158, 11, 0.06); }
.callout.danger        { border-left-color: var(--color-error);   background: rgba(220, 38, 38, 0.06); }


/* ============================================================
   6. Buttons
   ============================================================ */

.primary-btn,
.secondary-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.55rem 1.25rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.primary-btn:active,
.secondary-btn:active {
    transform: scale(0.97);
}

.primary-btn:focus-visible,
.secondary-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.primary-btn {
    background: var(--color-primary);
    color: white;
}

.primary-btn:hover:not(:disabled) { background: var(--color-primary-dark); }
.primary-btn:disabled              { opacity: 0.4; cursor: not-allowed; }

.secondary-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.secondary-btn:hover:not(:disabled) { background: var(--border-color); }
.secondary-btn:disabled              { opacity: 0.4; cursor: not-allowed; }


/* ============================================================
   7. Footer
   ============================================================ */

footer {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    padding: var(--spacing-md) var(--spacing-lg);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: var(--spacing-md);
    flex-shrink: 0;
}


/* ============================================================
   8. Debug Menu
   ============================================================ */

.debug-menu {
    position: fixed;
    bottom: var(--spacing-md);
    right: var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: var(--spacing-md);
    box-shadow: var(--shadow-lg);
    max-width: 260px;
    z-index: 200;
    font-size: 0.8rem;
}

.debug-header {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--spacing-sm);
}

.debug-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}

.debug-grid button {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.15s;
}

.debug-grid button:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}


/* ============================================================
   9. Utilities
   ============================================================ */

.hidden      { display: none !important; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-secondary); }
.mt-lg       { margin-top: var(--spacing-lg); }
.mb-lg       { margin-bottom: var(--spacing-lg); }


/* ============================================================
   10. Scrollbars
   ============================================================ */

::-webkit-scrollbar              { width: 8px; height: 8px; }
::-webkit-scrollbar-track        { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb        { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover  { background: var(--text-tertiary); }


/* ============================================================
   11. Responsive - stack panes on small screens
   ============================================================ */

@media (max-width: 900px) {
    .main-container {
        grid-template-columns: 1fr;
        padding: var(--spacing-md);
        gap: var(--spacing-md);
    }

    .pane {
        padding: var(--spacing-lg);
        min-height: auto;
    }

    .header-content {
        padding: 0 var(--spacing-md);
    }

    header h1 {
        font-size: 1.2rem;
    }
}


/* ============================================================
   12. Accessibility - reduced motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}


/* ============================================================
   Lucide icons
   ============================================================ */

/* Inline icons inside body text / callouts */
svg.lucide {
    display: inline-block;
    vertical-align: middle;
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}

/* Slightly larger in headings */
h1 svg.lucide, h2 svg.lucide, h3 svg.lucide {
    width: 1.1em;
    height: 1.1em;
}

/* Theme toggle and debug header icons sit flush */
.theme-toggle svg.lucide,
.debug-header svg.lucide {
    width: 1.25rem;
    height: 1.25rem;
    display: block;
}


/* ============================================================
   Collapsible video panel (shared across all tutorials)
   ============================================================ */

.video-panel {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--spacing-md) var(--spacing-lg) 0;
    width: 100%;
    display: none;
    /* DRG */
}

.video-panel-toggle {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: var(--spacing-md) var(--spacing-xl);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
    transition: background 0.15s ease, border-radius 0.15s ease;
    text-align: left;
}

.video-panel-toggle:hover {
    background: var(--bg-secondary);
}

.video-panel[data-open="true"] .video-panel-toggle {
    border-radius: 12px 12px 0 0;
}

.toggle-chevron {
    margin-left: auto;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.video-panel[data-open="true"] .toggle-chevron {
    transform: rotate(180deg);
}

.video-panel-body {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 12px 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.video-embed-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
}

.video-embed-wrapper iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}
