/* ═══════════════════════════════════════════════════════════════════════════
   Design system — ML Browser Benchmark
   Colors mirror the architecture diagram:
     Blue   = Shell/Router
     Green  = Tutorial Engine
     Yellow = Playground Engine
     Purple = Block Runtime Layer
     Red    = ML Execution Layer
     Pink   = Benchmarking Layer
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
    /* Layer colours */
    --layer-shell: #dbeafe; /* blue-100  */
    --layer-shell-dk: #3b82f6; /* blue-500  */
    --layer-tutorial: #dcfce7; /* green-100 */
    --layer-tutorial-dk: #22c55e; /* green-500 */
    --layer-playground: #fef9c3; /* yellow-100*/
    --layer-playground-dk: #eab308; /* yellow-500*/
    --layer-blockruntime: #ede9fe; /* purple-100*/
    --layer-blockruntime-dk: #8b5cf6; /* purple-500*/
    --layer-mlexec: #fee2e2; /* red-100   */
    --layer-mlexec-dk: #ef4444; /* red-500   */
    --layer-bench: #fce7f3; /* pink-100  */
    --layer-bench-dk: #ec4899; /* pink-500  */

    /* Block registry colours (also used in JS via CSS vars) */
    --color-block-task: #f59e0b;    /* amber-500  - Task block */
    --color-block-dataset: #22c55e;
    --color-block-model: #8b5cf6;
    --color-block-runtime: #ef4444;
    --color-block-backend: #3b82f6;

    /* Semantic */
    --color-primary: #3b82f6;
    --color-primary-dk: #1d4ed8;
    --color-secondary: #6b7280;
    --color-success: #22c55e;
    --color-warn: #eab308;
    --color-error: #ef4444;
    --color-text: #111827;
    --color-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-bg: #f9fafb;
    --color-surface: #ffffff;
    --color-surface-2: #f3f4f6;
    --color-bg-hover: rgba(0, 0, 0, 0.04);

    /* Typography */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: "Cascadia Code", "Fira Code", "Courier New", monospace;
    --text-sm: 0.85rem;
    --text-base: 1rem;
    --text-lg: 1.15rem;
    --text-xl: 1.35rem;
    --text-2xl: 1.75rem;
    --text-3xl: 2.25rem;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Radii / shadows */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    --header-h: 56px;
    --layerbar-h: 36px;
}

/* ── Dark theme ──────────────────────────────────────────────────────────── */
[data-theme="dark"] {
    --color-text: #f9fafb;
    --color-muted: #9ca3af;
    --color-border: #374151;
    --color-bg: #111827;
    --color-surface: #1f2937;
    --color-surface-2: #374151;
    --color-bg-hover: rgba(255, 255, 255, 0.06);
    --layer-shell: #1e3a5f;
    --layer-tutorial: #14532d;
    --layer-playground: #713f12;
    --layer-blockruntime: #3b0764;
    --layer-mlexec: #7f1d1d;
    --layer-bench: #831843;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html {
    scroll-behavior: smooth;
}
body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    padding-top: calc(var(--header-h) + var(--layerbar-h));
    transition:
        background 0.25s,
        color 0.25s;
}
a {
    color: var(--color-primary);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}
img {
    max-width: 100%;
    display: block;
}
p {
    margin-bottom: var(--space-4);
}
h1,
h2,
h3,
h4 {
    line-height: 1.25;
    margin-bottom: var(--space-3);
}
h1 {
    font-size: var(--text-2xl);
}
h2 {
    font-size: var(--text-xl);
}
h3 {
    font-size: var(--text-lg);
}
code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: var(--color-surface-2);
    padding: 2px 5px;
    border-radius: 4px;
}

/* ── Shell header ────────────────────────────────────────────────────────── */
.shell-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--layer-shell);
    border-bottom: 1px solid var(--layer-shell-dk);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    z-index: 100;
    box-shadow: var(--shadow-sm);
}
.logo {
    font-weight: 700;
    font-size: var(--text-lg);
    color: var(--color-text);
}
.main-nav {
    display: flex;
    gap: var(--space-2);
    margin-left: var(--space-5);
}
.nav-link {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-weight: 500;
    color: var(--color-text);
    transition: background 0.15s;
}
.nav-link:hover {
    background: rgba(0, 0, 0, 0.07);
    text-decoration: none;
}
.nav-link.active {
    background: var(--layer-shell-dk);
    color: #fff;
}
.header-left {
    display: flex;
    align-items: center;
}
.header-right {
    display: flex;
    gap: var(--space-2);
}

/* ── Layer indicator bar ─────────────────────────────────────────────────── */
.layer-bar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    height: var(--layerbar-h);
    background: var(--color-surface-2);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 var(--space-6);
    gap: var(--space-2);
    font-size: var(--text-sm);
    overflow-x: auto;
    z-index: 99;
}
.layer-sep {
    color: var(--color-muted);
}
.layer-badge {
    padding: 2px var(--space-2);
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.75rem;
    white-space: nowrap;
}
.layer-shell {
    background: var(--layer-shell);
    color: var(--layer-shell-dk);
}
.layer-tutorial {
    background: var(--layer-tutorial);
    color: var(--layer-tutorial-dk);
}
.layer-playground {
    background: var(--layer-playground);
    color: var(--layer-playground-dk);
}
.layer-blockruntime {
    background: var(--layer-blockruntime);
    color: var(--layer-blockruntime-dk);
}
.layer-mlexec {
    background: var(--layer-mlexec);
    color: var(--layer-mlexec-dk);
}
.layer-bench {
    background: var(--layer-bench);
    color: var(--layer-bench-dk);
}

/* ── Main outlet ─────────────────────────────────────────────────────────── */
#outlet {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition:
        background 0.15s,
        transform 0.1s;
    text-decoration: none;
}
.btn:hover {
    background: var(--color-surface-2);
    text-decoration: none;
}
.btn:active {
    transform: scale(0.97);
}
.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    /* keep pointer-events so the title tooltip is still visible on hover */
    pointer-events: auto;
}
.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary-dk);
}
.btn-primary:hover {
    background: var(--color-primary-dk);
}
.btn-secondary {
    background: var(--color-surface-2);
}
.btn-ghost {
    border-color: transparent;
    background: transparent;
}
.btn-ghost:hover {
    background: var(--color-surface-2);
}
.btn-danger {
    background: var(--color-error);
    color: #fff;
    border-color: #b91c1c;
}
.btn-danger:hover {
    background: #b91c1c;
}
.btn-hint {
    background: var(--layer-playground);
    border-color: var(--layer-playground-dk);
}
.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: 0.8rem;
}
.btn-large {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-base);
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

/* ── Spinners / loading ──────────────────────────────────────────────────── */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-12);
    color: var(--color-muted);
}
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
.loading-msg {
    font-size: var(--text-sm);
    color: var(--color-muted);
}

/* ── Error card ──────────────────────────────────────────────────────────── */
.error-card {
    background: #fee2e2;
    border: 1px solid #f87171;
    border-radius: var(--radius-md);
    padding: var(--space-5);
    color: #7f1d1d;
    margin: var(--space-6) 0;
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.toast {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    background: var(--color-text);
    color: var(--color-bg);
    font-size: var(--text-sm);
    box-shadow: var(--shadow-md);
    animation: slideIn 0.25s ease;
    transition: opacity 0.3s;
}
.toast-hide {
    opacity: 0;
}
.toast-success {
    background: #166534;
}
.toast-error {
    background: #7f1d1d;
}
.toast-warn {
    background: #713f12;
}
@keyframes slideIn {
    from {
        transform: translateX(40px);
        opacity: 0;
    }
    to {
        transform: none;
        opacity: 1;
    }
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.muted {
    color: var(--color-muted);
}
.badge {
    display: inline-block;
    padding: 2px var(--space-2);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--color-surface-2);
}
.badge-best {
    background: #dcfce7;
    color: #166534;
}
.hidden {
    display: none !important;
}
.section {
    margin-bottom: var(--space-10);
}

/* ── Image grids ───────────────────────────────────────────────────────────
   Shared by tutorial step 2 and playground dataset selection.
   ═══════════════════════════════════════════════════════════════════════════ */
.image-grid {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-top: var(--space-4);
}
.image-thumb {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: var(--space-2);
    transition: border-color 0.15s;
}
.image-thumb:hover {
    border-color: var(--color-primary);
}
.image-thumb.selected {
    border-color: var(--color-success);
    background: var(--layer-tutorial);
}
.image-label {
    font-size: 0.8rem;
    color: var(--color-muted);
    text-align: center;
}

/* ── HW pills ──────────────────────────────────────────────────────────────
   Shared by option cards (playground) and runtime compat tables.
   ═══════════════════════════════════════════════════════════════════════════ */
.hw-pill {
    display: inline-block;
    font-size: 0.68rem;
    padding: 1px 6px;
    border-radius: 999px;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1.6;
}
.hw-cpu {
    background: #dbeafe;
    color: #1e40af;
}
.hw-gpu {
    background: #fce7f3;
    color: #9d174d;
}
[data-theme="dark"] .hw-cpu {
    background: #1e3a5f;
    color: #93c5fd;
}
[data-theme="dark"] .hw-gpu {
    background: #831843;
    color: #f9a8d4;
}

/* ── Result card ───────────────────────────────────────────────────────────
   Shared by playground showResult() and results comparison.
   ═══════════════════════════════════════════════════════════════════════════ */
.result-card {
    background: var(--color-surface);
    border: 1px solid var(--color-success);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}
.result-header {
    font-size: var(--text-sm);
    color: var(--color-muted);
    margin-bottom: var(--space-3);
}
.result-label {
    font-size: var(--text-xl);
    font-weight: 700;
    margin-bottom: var(--space-3);
}
.result-score {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}
.confidence-bar {
    flex: 1;
    height: 10px;
    background: var(--color-border);
    border-radius: 999px;
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    background: var(--color-success);
    border-radius: 999px;
    transition: width 0.5s ease;
}
.result-metrics {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    font-size: var(--text-sm);
    color: var(--color-muted);
}

/* ── Benchmark table ───────────────────────────────────────────────────────
   Shared by results page, research docs, and playground inline comparison.
   ═══════════════════════════════════════════════════════════════════════════ */
.bench-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.bench-table th {
    background: var(--color-surface-2);
    text-align: left;
    padding: var(--space-3) var(--space-4);
    font-weight: 600;
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}
.bench-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.bench-table tr:last-child td {
    border-bottom: none;
}
.bench-table tr:hover td {
    background: var(--color-surface-2);
}
.bench-table td.best {
    background: #dcfce7;
    color: #166534;
    font-weight: 700;
}

/* ── Hamburger / menu-toggle button ─────────────────────────────────────── */
.menu-toggle {
    display: none; /* hidden on desktop */
    padding: var(--space-2);
    background: transparent;
    border: none;
    cursor: pointer;
    line-height: 1;
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 20px;
    height: 16px;
    pointer-events: none;
}

.hamburger-icon span {
    display: block;
    width: 100%;
    height: 2px;
    border-radius: 2px;
    background: var(--color-text);
    transition:
        transform 0.25s ease,
        opacity 0.2s ease;
    transform-origin: center;
}

/* ✕ state when menu is open */
.menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}
.menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ── Mobile nav drawer ───────────────────────────────────────────────────── */
.mobile-nav {
    display: none; /* only shown via media query */
    position: fixed;
    top: var(--header-h);
    right: 0;
    width: min(280px, 80vw);
    height: calc(100dvh - var(--header-h));
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    flex-direction: column;
    padding: var(--space-4) 0;
    z-index: 200;
    overflow-y: auto;
    /* slide-in animation */
    transform: translateX(110%);
    transition:
        transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.28s;
    visibility: hidden;
}

.mobile-nav.open {
    transform: translateX(0);
    visibility: visible;
}

.mobile-nav-link {
    display: block;
    padding: var(--space-4) var(--space-6);
    font-size: var(--text-base);
    font-weight: 500;
    color: var(--color-text);
    border-left: 3px solid transparent;
    transition:
        background 0.15s,
        border-color 0.15s;
}

.mobile-nav-link:hover {
    background: var(--color-surface-2);
    text-decoration: none;
}

.mobile-nav-link.active {
    background: var(--layer-shell);
    border-color: var(--layer-shell-dk);
    color: var(--layer-shell-dk);
}

.mobile-nav-actions {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    margin-top: auto;
    border-top: 1px solid var(--color-border);
    flex-wrap: wrap;
}

/* ── Backdrop ────────────────────────────────────────────────────────────── */
.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    transition: opacity 0.28s ease;
    pointer-events: none;
}

.nav-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Hide desktop nav links, show hamburger */
    .main-nav {
        display: none;
    }
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Show mobile drawer and backdrop as flex/block (visibility/transform handle open state) */
    .mobile-nav {
        display: flex;
    }
    .nav-backdrop {
        display: block;
    }

    /* Shrink header action buttons so they fit */
    #role-toggle {
        display: none;
    }
}

@media (max-width: 600px) {
    .shell-header {
        padding: 0 var(--space-4);
    }
    #outlet {
        padding: var(--space-5) var(--space-4);
    }
    .hero h1 {
        font-size: var(--text-2xl);
    }
    .stat-val {
        font-size: var(--text-xl);
    }
    .layer-bar {
        display: none;
    }
    body {
        padding-top: var(--header-h);
    }
}
