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

:root {
    --ink: #18181b;
    --ink-secondary: #52525b;
    --ink-muted: #71717a;
    --surface: #ffffff;
    --surface-subtle: #f8f8f8;
    --surface-muted: #f1f2f4;
    --stage-bg: #f3f4f6;
    --stage-border: #e4e4e7;
    --border: #e4e4e7;
    --border-strong: #d4d4d8;
    --brand-muted: #666f7e;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 10px;
}

html.dark-mode {
    --ink: #f0f0f2;
    --ink-secondary: #a1a1aa;
    --ink-muted: #71717a;
    --surface: #141416;
    --surface-subtle: #1c1c1f;
    --surface-muted: #242429;
    --stage-bg: #101012;
    --stage-border: #2c2c32;
    --border: #2c2c32;
    --border-strong: #3f3f46;
    --brand-muted: #a1a1aa;
}

html, body {
    background-color: var(--surface);
    color: var(--ink);
    font-family: "Avenir Next", "Avenir", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

html.theme-ready,
html.theme-ready body {
    transition: background-color 0.25s ease, color 0.25s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

button, input {
    font-family: inherit;
}

/* Header */
.site-header {
    background-color: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
    height: 4rem;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 40;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    justify-self: start;
    gap: 0.45rem;
    font-family: Arial, sans-serif;
    font-size: 0.8rem;
    letter-spacing: 2px;
    line-height: 1;
    text-transform: uppercase;
    color: var(--brand-muted);
    transition: color 0.2s ease;
}

.back-btn:hover {
    color: var(--ink);
}

.header-brand {
    font-family: Arial, sans-serif;
    font-size: 0.9rem;
    letter-spacing: 5px;
    text-indent: 5px;
    color: var(--brand-muted);
    justify-self: center;
    text-align: center;
    line-height: 1;
    white-space: nowrap;
}

/* Theme Toggle */
.theme-toggle {
    position: relative;
    justify-self: end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    margin-right: -0.375rem;
    padding: 0;
    border: none;
    border-radius: 9999px;
    background: transparent;
    color: var(--brand-muted);
    cursor: pointer;
    z-index: 15;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.theme-toggle:hover {
    background-color: rgba(0, 0, 0, 0.06);
    color: var(--ink);
}

html.dark-mode .theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--brand-muted);
    outline-offset: 2px;
}

.theme-toggle svg {
    width: 1.75rem;
    height: 1.75rem;
}

.theme-toggle .icon-sun {
    display: block;
}

.theme-toggle .icon-moon {
    display: none;
}

html.dark-mode .theme-toggle .icon-sun {
    display: none;
}

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

/* Layout Container */
.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    flex: 1;
}

/* Page Intro & Toolbar */
.page-intro {
    margin-bottom: 1.5rem;
}

.intro-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-title {
    font-family: Arial, sans-serif;
    font-size: 1.75rem;
    font-weight: 400;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 0.25rem;
}

.page-subtitle {
    font-size: 0.9rem;
    color: var(--ink-secondary);
}

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

.trim-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: linear-gradient(90deg, #18181b 0%, #cbd5e1 50%, #18181b 100%);
    border: 1px solid var(--border-strong);
    display: inline-block;
}

.primary-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid var(--ink);
    background-color: var(--ink);
    color: var(--surface);
    padding: 0.45rem 0.95rem;
    border-radius: var(--radius-sm);
    font-family: Arial, sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.primary-btn:hover {
    opacity: 0.88;
}

.util-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid var(--border-strong);
    background-color: var(--surface);
    color: var(--ink-secondary);
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.util-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
}

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

.filter-tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}

.filter-tab {
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink-secondary);
    padding: 0.38rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.filter-tab:hover {
    color: var(--ink);
    background-color: var(--surface-subtle);
}

.filter-tab.active {
    background-color: var(--ink);
    color: var(--surface);
    border-color: var(--ink);
}

.search-wrap {
    position: relative;
    width: 240px;
}

.search-wrap input {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    color: var(--ink);
    padding: 0.4rem 1.75rem 0.4rem 0.75rem;
    font-size: 0.8rem;
    outline: none;
    transition: border-color 0.15s ease;
}

.search-wrap input::placeholder {
    color: var(--ink-muted);
}

.search-wrap input:focus {
    border-color: var(--ink);
}

.search-shortcut {
    position: absolute;
    right: 0.55rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: var(--ink-muted);
    pointer-events: none;
}

/* Main Grid */
.schematic-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

/* Canvas Card */
.canvas-card {
    background-color: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
}

.canvas-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
}

.canvas-meta-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.state-pill {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--ink-muted);
    display: inline-block;
}

.state-pill.active {
    background-color: var(--ink);
}

.state-label {
    font-family: Arial, sans-serif;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ink);
    font-size: 0.72rem;
}

.meta-divider {
    color: var(--border-strong);
}

.meta-text {
    color: var(--ink-secondary);
}

.meta-muted {
    color: var(--ink-muted);
}

.hover-readout {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--ink-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
    transition: opacity 0.15s ease;
}

.opacity-0 {
    opacity: 0;
}

.canvas-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    min-height: 360px;
    max-height: 560px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--stage-bg);
    border: 1px solid var(--stage-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

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

.canvas-hint-badge {
    position: absolute;
    bottom: 0.75rem;
    left: 0.85rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    color: var(--ink-secondary);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    pointer-events: none;
}

.hint-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--ink);
}

.jump-bar {
    margin-top: 0.9rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

.jump-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-right: 0.25rem;
}

.jump-pill {
    border: 1px solid var(--border);
    background-color: var(--surface);
    color: var(--ink-secondary);
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    font-size: 0.74rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.jump-pill:hover {
    border-color: var(--ink);
    background-color: var(--ink);
    color: var(--surface);
}

/* Sidebar & Inspector */
.sidebar-stack {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.inspector-card,
.directory-card {
    background-color: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.inspector-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.85rem;
    margin-bottom: 0.85rem;
    border-bottom: 2px solid var(--ink);
}

.part-category {
    display: block;
    font-family: Arial, sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--brand-muted);
    margin-bottom: 0.2rem;
}

.part-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.3;
}

.part-gen-pill {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--ink-secondary);
    background-color: var(--surface);
    border: 1px solid var(--border);
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
    margin-bottom: 0.9rem;
}

.meta-box {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.6rem 0.7rem;
}

.meta-box-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 0.15rem;
}

.meta-box-val {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inspector-sections {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.section-heading {
    display: block;
    font-family: Arial, sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 0.35rem;
}

.section-box {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    font-size: 0.82rem;
    color: var(--ink-secondary);
    line-height: 1.55;
}

.quirk-box {
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 0.75rem;
}

.quirk-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: Arial, sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 0.3rem;
}

.quirk-text {
    font-size: 0.78rem;
    color: var(--ink-secondary);
    line-height: 1.5;
}

.specs-list {
    list-style: none;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.65rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.spec-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.78rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--surface-muted);
}

.spec-row:last-child {
    padding-bottom: 0;
    border-bottom: none;
}

.spec-label {
    color: var(--ink-muted);
}

.spec-val {
    color: var(--ink);
    font-weight: 600;
    text-align: right;
}

.inspector-actions {
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
}

.copy-oem-btn {
    flex: 1;
}

/* Directory Card */
.directory-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.6rem;
    margin-bottom: 0.65rem;
    border-bottom: 2px solid var(--ink);
}

.directory-header .section-heading {
    margin-bottom: 0;
    color: var(--ink);
}

.count-pill {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-secondary);
    background-color: var(--surface);
    border: 1px solid var(--border);
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
}

.directory-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 0.2rem;
}

.directory-item {
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    border: 1px solid var(--border);
    background-color: var(--surface);
    color: var(--ink-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.directory-item:hover {
    border-color: var(--ink);
    color: var(--ink);
}

.directory-item.active {
    background-color: var(--ink);
    border-color: var(--ink);
    color: var(--surface);
    font-weight: 600;
}

.directory-item-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.directory-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--ink-muted);
    flex-shrink: 0;
}

.directory-item.active .directory-dot {
    background-color: var(--surface);
}

.directory-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.directory-badge {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: var(--ink-muted);
    flex-shrink: 0;
}

.directory-item.active .directory-badge {
    border-color: rgba(255, 255, 255, 0.25);
    color: var(--surface);
}

html.dark-mode .directory-item.active .directory-badge {
    border-color: rgba(0, 0, 0, 0.25);
}

/* Interactive Truck SVG Part Nodes */
.part-node {
    cursor: pointer;
    transition: transform 0.65s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.3s ease,
                filter 0.3s ease;
    transform-origin: center;
}

.part-node path,
.part-node rect,
.part-node polygon,
.part-node circle,
.part-node ellipse,
.part-node line {
    transition: stroke 0.25s ease, stroke-width 0.25s ease, fill 0.25s ease;
}

.part-node:hover {
    filter: drop-shadow(0 4px 10px rgba(24, 24, 27, 0.35));
    opacity: 1 !important;
}

html.dark-mode .part-node:hover {
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.65));
}

.part-node:hover path,
.part-node:hover rect,
.part-node:hover polygon,
.part-node:hover circle {
    stroke: var(--ink) !important;
    stroke-width: 2.2px !important;
}

.part-node.active {
    filter: drop-shadow(0 6px 14px rgba(24, 24, 27, 0.45)) !important;
    opacity: 1 !important;
}

html.dark-mode .part-node.active {
    filter: drop-shadow(0 0 14px rgba(255, 255, 255, 0.85)) !important;
}

.part-node.active path,
.part-node.active rect,
.part-node.active polygon,
.part-node.active circle {
    stroke: var(--ink) !important;
    stroke-width: 2.6px !important;
}

.exploded #part-hood { transform: translate(-35px, -95px); }
.exploded #part-bumper-front { transform: translate(-120px, 20px); }
.exploded #part-grille-lights { transform: translate(-90px, -50px); }
.exploded #part-fender-front { transform: translate(-50px, -40px); }
.exploded #part-cab { transform: translate(0px, -90px); }
.exploded #part-mirrors { transform: translate(-40px, -120px); }
.exploded #part-bed { transform: translate(90px, -75px); }
.exploded #part-tailgate-bumper { transform: translate(130px, 20px); }
.exploded #part-engine { transform: translate(-20px, 0px); }
.exploded #part-transmission { transform: translate(0px, 15px); }
.exploded #part-driveshaft { transform: translate(25px, 25px); }
.exploded #part-front-suspension { transform: translate(-20px, 60px); }
.exploded #part-rear-axle { transform: translate(35px, 65px); }
.exploded #part-fuel { transform: translate(15px, 70px); }
.exploded #part-exhaust { transform: translate(25px, 50px); }
.exploded #part-wheels { transform: translate(0px, 55px); }
.exploded #part-frame { transform: translate(0px, 0px); }

.guide-line {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    stroke-dasharray: 4 4;
}

.exploded .guide-line {
    opacity: 0.45;
}

.exploded .guide-line.active-guide {
    opacity: 0.95;
    stroke: var(--ink);
    stroke-width: 1.6;
    stroke-dasharray: none;
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 1.25rem;
    background-color: var(--surface-subtle);
    border-top: 1px solid var(--border);
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.copyright {
    font-family: Arial, sans-serif;
    font-size: 0.75rem;
    letter-spacing: 4px;
    color: var(--brand-muted);
}

/* Responsive */
@media (max-width: 980px) {
    .schematic-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .site-header {
        padding: max(env(safe-area-inset-top, 0px), 0.75rem) 1rem 0 1rem;
        height: calc(3.5rem + max(env(safe-area-inset-top, 0px), 0.75rem));
    }

    .container {
        padding: 1.5rem 1rem 3rem;
    }

    .hide-sm {
        display: none;
    }
}

@media (max-width: 580px) {
    .back-btn span {
        display: none;
    }

    .back-btn svg {
        width: 18px;
        height: 18px;
    }

    .header-brand {
        font-size: 0.75rem;
        letter-spacing: 3px;
        text-indent: 3px;
    }

    .page-title {
        font-size: 1.4rem;
    }

    .search-wrap {
        width: 100%;
    }

    .canvas-stage {
        min-height: 260px;
    }
}
