@font-face {
    font-family: 'Geist';
    src: url('../assets/fonts/Geist-Variable.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Geist';
    src: url('../assets/fonts/Geist-VariableItalic.woff2') format('woff2');
    font-weight: 100 900;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: 'Geist Mono';
    src: url('../assets/fonts/GeistMono-Variable.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Geist Mono';
    src: url('../assets/fonts/GeistMono-VariableItalic.woff2') format('woff2');
    font-weight: 100 900;
    font-style: italic;
    font-display: swap;
}

/* Metric-compatible fallbacks to reduce font-swap layout shifts. */
@font-face {
    font-family: 'Geist Fallback';
    src: local('Segoe UI'), local('Helvetica Neue'), local('Arial');
    ascent-override: 90%;
    descent-override: 22%;
    line-gap-override: 0%;
    size-adjust: 104%;
}

@font-face {
    font-family: 'Geist Mono Fallback';
    src: local('SFMono-Regular'), local('Cascadia Code'), local('Consolas'), local('Liberation Mono'), local('Courier New');
    ascent-override: 88%;
    descent-override: 22%;
    line-gap-override: 0%;
    size-adjust: 100%;
}

:root {
    /* Dark Theme (Default) */
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    /* More opaque background to mitigate blur lag */
    --text-color: #e2e8f0;
    --text-muted: #94a3b8;
    --text-heading: #f8fafc;
    --accent-color: #38bdf8;
    --accent-hover: #0ea5e9;
    --accent-bg-hover: rgba(56, 189, 248, 0.1);
    --border-color: rgba(255, 255, 255, 0.1);
    --border-subtle: rgba(255, 255, 255, 0.05);

    --highlight-default-bg: rgba(255, 255, 0, 0.2);
    --highlight-default-border: rgba(255, 255, 0, 0.5);

    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.15);
    --card-shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);

    --prism-bg: rgba(0, 0, 0, 0.3);
    --prism-border: rgba(255, 255, 255, 0.05);

    --panel-bg: rgba(0, 0, 0, 0.2);
    --panel-header-border: rgba(255, 255, 255, 0.1);

    --empty-state-color: #94a3b8;
    --var-value-color: #e2e8f0;

    --btn-reset-border: #64748b;
    --btn-reset-color: #94a3b8;
    --btn-reset-hover-border: #94a3b8;
    --btn-reset-hover-color: #f8fafc;
    --btn-reset-hover-bg: rgba(255, 255, 255, 0.05);

    --btn-text-color: var(--bg-color);
    /* For buttons with accent background */
    --btn-hover-text: white;

    /* Scrollbar */
    --scrollbar-track: #1e293b;
    --scrollbar-thumb: #334155;
    --scrollbar-thumb-hover: #475569;

    /* Fixed height panel measurements */
    /* 0.9rem font × 1.5 line-height + 0.8rem padding */
    --var-row-height: 2.2rem;
    /* default, overridden by JS */
    --max-var-rows: 3;
}

html.light-theme {
    /* Light Theme Overrides */
    --bg-color: #f8fafc;
    /* Slate 50 */
    --card-bg: #ffffff;
    --text-color: #334155;
    /* Slate 700 */
    --text-muted: #64748b;
    /* Slate 500 */
    --text-heading: #1e293b;
    /* Slate 800 */
    --accent-color: #0369a1;
    /* Sky 700 - darker for contrast on white */
    --accent-hover: #075985;
    /* Sky 800 */
    --accent-bg-hover: rgba(3, 105, 161, 0.1);
    --border-color: #e2e8f0;
    /* Slate 200 */
    --border-subtle: #f1f5f9;
    /* Slate 100 */

    --highlight-default-bg: rgba(255, 215, 0, 0.2);
    --highlight-default-border: rgba(218, 165, 32, 0.5);

    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --card-shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --prism-bg: #f1f5f9;
    --prism-border: #e2e8f0;

    --panel-bg: #f8fafc;
    --panel-header-border: #e2e8f0;

    --empty-state-color: #64748b;
    --var-value-color: #334155;

    --btn-reset-border: #cbd5e1;
    --btn-reset-color: #64748b;
    --btn-reset-hover-border: #94a3b8;
    --btn-reset-hover-color: #475569;
    --btn-reset-hover-bg: #f1f5f9;

    --btn-text-color: white;
    /* Contrast against accent color */

    /* Scrollbar */
    --scrollbar-track: #f1f5f9;
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-thumb-hover: #94a3b8;
}

/* Modern Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Custom Scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
    border: 2px solid var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}


* {
    margin: 0;
}

ul,
ol {
    padding-inline-start: 1rem;
}

html,
body {
    height: 100%;
}

body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
}

input,
button,
textarea,
select {
    font: inherit;
}

code,
pre {
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0;
}

/* Accessibility */
:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Geist', 'Geist Fallback', 'Segoe UI', 'Helvetica Neue', 'Noto Sans', 'Liberation Sans', sans-serif;
    margin: 0;
    padding: 2rem;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#app {
    max-width: 1200px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header & Theme Toggle */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.back-link:hover {
    color: var(--accent-color);
}

h1 {
    text-align: left;
    /* Changed from center to accommodate button */
    color: var(--accent-color);
    font-size: 2.5rem;
    margin-bottom: 0;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    min-width: 42px;
    min-height: 42px;
}

.theme-toggle:hover {
    background: var(--card-bg);
    color: var(--accent-color);
    border-color: var(--accent-color);
}

.theme-toggle svg {
    display: none;
}

/* Show Sun in Dark Mode (Default) */
.theme-toggle .icon-sun {
    display: block;
}

/* Show Moon in Light Mode */
html.light-theme .theme-toggle .icon-sun {
    display: none;
}

html.light-theme .theme-toggle .icon-moon {
    display: block;
}

.example-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    contain: paint;
    /* Isolate paint to improve tiling performance */
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s ease, border-color 0.3s ease;
}

.example-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--card-shadow-hover);
}

.example-card h2 {
    margin-top: 0;
    color: var(--text-heading);
    font-size: 1.5rem;
}

.example-card p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* Prism Overrides & Custom Highlights */
pre.language-javascript,
pre.language-javascript code.language-javascript {
    font-family: 'Geist Mono', 'Geist Mono Fallback', 'SFMono-Regular', 'Cascadia Code', 'Menlo', 'Consolas', 'Liberation Mono', 'Courier New', monospace;
    border-radius: 8px;
    /* border: 1px solid var(--prism-border); */
    margin: 0 !important;
    height: 100%;
    /* Fill panels */
}

pre.language-javascript {
    background: var(--prism-bg) !important;
}

pre.language-javascript code.language-javascript {
    background: transparent !important;
}

/* Fix Prism line-numbers alignment drift */
pre.line-numbers,
pre.line-numbers code {
    line-height: 1.5;
}

.line-numbers .line-numbers-rows>span {
    line-height: 1.5;
}

.code-toolbar .toolbar .toolbar-item button {
    background: var(--card-bg);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.code-toolbar .toolbar .toolbar-item button:hover,
.code-toolbar .toolbar .toolbar-item button:focus {
    color: var(--text-heading);
    border-color: var(--accent-color);
    background: var(--accent-bg-hover);
}

/* Layout */
.content-grid {
    display: grid;
    grid-template-columns: 60% 40%;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: stretch;
}

code-explainer aside {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    min-width: 0;
}

.code-panel {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
}

.code-figure {
    margin: 0;
}

.step-description {
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    line-height: 1.6;
    /* Fixed height for 3 lines: (3 × 1.6rem line-height) + (2 × 0.75rem padding) */
    height: calc(3 * 1.6rem + 2 * 0.75rem);
    overflow-y: auto;
    /* Firefox */
    scrollbar-width: none;
}

.step-description::-webkit-scrollbar {
    /* Chrome, Safari, Edge */
    display: none;
}

.step-description-placeholder {
    font-style: italic;
}

.data-panel {
    background: var(--panel-bg);
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    padding: 1rem;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 0.75rem;
}

.data-panel h3 {
    margin-top: 0;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--panel-header-border);
    padding-bottom: 0.5rem;
}

.variables-container {
    font-family: 'Geist Mono', 'Geist Mono Fallback', 'SFMono-Regular', 'Cascadia Code', 'Menlo', 'Consolas', 'Liberation Mono', 'Courier New', monospace;
    font-size: 0.9rem;
    margin: 0;
    /* border: 1px solid var(--border-subtle); */
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    /* Fixed height based on max variable rows */
    height: calc(var(--max-var-rows) * var(--var-row-height));
    /* Hide scrollbar but keep scroll functionality */
    /* Firefox */
    scrollbar-width: none;
}

.variables-container::-webkit-scrollbar {
    /* Chrome, Safari, Edge */
    display: none;
}

.empty-state,
.variables-container {
    grid-row: 2;
    grid-column: 1;
}

.empty-state {
    color: var(--empty-state-color);
    font-style: italic;
    padding: 0.4rem 0;
}

.variable-item {
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border-subtle);
}

.variable-item:last-child {
    border-bottom: none;
}

.variables-container dt,
.variables-container dd {
    margin: 0;
}

.variables-container dt::after {
    content: ':';
}

.var-name {
    color: var(--accent-color);
}

.var-value {
    color: var(--var-value-color);
    white-space: nowrap;
}

/* Controls */
.controls {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 1rem;
}

button {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-family: inherit;
}

button:hover {
    background: var(--accent-bg-hover);
}

.btn-next {
    background: var(--accent-color);
    color: var(--btn-text-color);
}

.btn-next:hover {
    background: var(--accent-hover);
    color: white;
}

.btn-reset {
    border-color: var(--btn-reset-border);
    color: var(--btn-reset-color);
}

.btn-reset:hover {
    border-color: var(--btn-reset-hover-border);
    color: var(--btn-reset-hover-color);
    background: var(--btn-reset-hover-bg);
}

/* Summary Section */
.summary-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    line-height: 1.6;
}

.summary-section strong {
    color: var(--text-heading);
}

.summary-section ul {
    margin: 0.5rem 0 0 1.5rem;
    padding: 0;
}

.summary-section li {
    margin-bottom: 0.5rem;
}

h2 code,
p code,
.summary-section code,
.summary-section var,
.step-description code,
.step-description var {
    font-family: 'Geist Mono', 'Geist Mono Fallback', 'SFMono-Regular', 'Cascadia Code', 'Menlo', 'Consolas', 'Liberation Mono', 'Courier New', monospace;
    font-style: normal;
    background: var(--prism-bg);
    color: var(--text-color);
    padding: 0.1rem 0.2rem;
    border-radius: 4px;
    font-size: 0.9em;
    border: 1px solid var(--prism-border);
}

/* Custom Highlight styles (fallback or addition to Prism) */
/* Note: Prism Line Highlight uses .line-highlight class */
.line-highlight {
    background: linear-gradient(to right, var(--accent-bg-hover) 70%, rgba(56, 189, 248, 0));
    width: auto !important;
    margin-block-start: calc(1rem - 1px);
}

mark.custom-highlight {
    background: transparent;
    color: inherit;
    border: 1px solid var(--accent-color);
    border-radius: 4px;
    padding: 0 2px;
    box-shadow: 0 0 5px rgba(56, 189, 248, 0.5);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.4);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(56, 189, 248, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(56, 189, 248, 0);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        padding: 1.5rem;
    }

    .app-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        column-gap: 1rem;
        align-items: start;
    }

    .header-content,
    .app-header>h1 {
        min-width: 0;
    }

    .theme-toggle {
        justify-self: end;
        align-self: start;
    }

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

    .controls {
        justify-content: flex-start;
    }

    h1 {
        font-size: 2rem;
    }

    .example-card {
        padding: 1.5rem;
    }

    .example-card h2 {
        font-size: 1.35rem;
    }
}

@media (max-width: 640px) {
    pre.line-numbers {
        /* remove extra gutter space */
        padding: 0.75rem 1rem !important;
    }

    .line-numbers .line-numbers-rows {
        opacity: 0;
        pointer-events: none;
    }

    div.line-highlight {
        margin-block-start: 0.7rem;
    }
}