.theme-toggle {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
}
.theme-toggle:hover {
  border-color: var(--soft-red);
  color: var(--soft-red);
}
.theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle[aria-pressed=true] .theme-icon-moon,
.theme-toggle[aria-pressed=false] .theme-icon-sun { display: none; }
.header-inner > .shop-nav { min-width: 0; }
.mobile-shop-menu { display: none; }

:root[data-theme=dark],
:root[data-theme=dark] body {
  color-scheme: dark;
  --bg: #101114;
  --panel: #1b1c22;
  --line: #3c3d47;
  --ink: #f8f4f2;
  --muted: #c4bec4;
  --red: #f35b69;
  --soft-red: #ffa9b3;
}
:root[data-theme=dark] .shop-header {
  background: #15151a;
  box-shadow: 0 3px 18px #0004;
}
:root[data-theme=dark] .shop-hero {
  background: #14151a;
}
:root[data-theme=dark] .hero-count {
  border-color: #56505c;
}
:root[data-theme=dark] .home-studio-track { scrollbar-color: #a87680 #24212a; }
:root[data-theme=dark] .home-studio-controls button[aria-disabled=true] {
  border-color: var(--line);
  color: #a59da7;
}
:root[data-theme=dark] :is(.action:not(.red),.vehicle-card,.part-quick) {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
}
:root[data-theme=dark] .action.red { background: #ab2535; border-color: #df5260; }
:root[data-theme=dark] .action.red:hover { background: #952030; }
:root[data-theme=dark] .part-quick:hover { background: #2c222b; border-color: var(--red); }
:root[data-theme=dark] :is(.field input,.field select,.preview-close) { border-color: #6b6672; }
:root[data-theme=dark] body:not([data-page=studio]) :is(.filters button:not([aria-pressed=true]),.text-button) {
  border-color: #6b6672;
}
:root[data-theme=dark] .part-card { box-shadow: 0 4px 16px #0004; }
:root[data-theme=dark] .part-preview::backdrop { background: #09070bc9; }

/* Keep the render stage graphite even in the light studio. */
:root[data-theme=light] body[data-page=studio] {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #fffdf9;
  --line: #ded9cf;
  --ink: #191a1c;
  --muted: #585850;
  --red: #b51f2f;
  --soft-red: #a01728;
}
:root[data-theme=light] body[data-page=studio] .shop-header { background: #fdfbf6; }
:root[data-theme=light] #cadStudio {
  background: radial-gradient(ellipse at 23% 0, #fffdf7, #f1e9dc 75%);
  border-color: var(--line);
  color: var(--ink);
}
:root[data-theme=light] #cadStudio :is(.studio-library-header h1,.ps-status,.ps-label b,.ps-code strong,.cad-sale-status strong,.cad-details b,.cad-source summary) { color: var(--ink); }
:root[data-theme=light] #cadStudio :is(.studio-library-header p:last-child,.studio-library-filters label,#studioResults,.studio-work-card small,.ps-heading p,.ps-subtitle,.ps-facts span,.ps-label,.ps-help,.ps-code,.ps-flash,.cad-sale-status span,.cad-sale-status small,.cad-details span,.cad-source) { color: var(--muted); }
:root[data-theme=light] #cadStudio :is(.catalog-studio-kicker,.ps-eyebrow,.ps-kicker) { color: var(--soft-red); }
:root[data-theme=light] #cadStudio :is(.studio-library-filters input,.studio-library-filters select,.studio-work-card,.ps-panel,.cad-details,.cad-source) {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
}
:root[data-theme=light] #cadStudio :is(.studio-library-list,.cad-details > div,.ps-control,.ps-facts span,.cad-sale-status,.ps-status) { border-color: #b8aa99; }
:root[data-theme=light] #cadStudio .studio-work-card:hover,
:root[data-theme=light] #cadStudio .studio-work-card[aria-current=true] {
  border-color: var(--red);
  background: #fff1ee;
}
:root[data-theme=light] #cadStudio .ps-code { background: #f5ece3; }
:root[data-theme=light] #cadStudio :is(.ps-panel,.studio-library-header,.studio-library-list,.cad-source) :focus-visible { outline-color: var(--soft-red); }
:root[data-theme=light] #cadStudio .cad-viewer { color-scheme: dark; color: #f3f5f7; }

@media (max-width: 800px) {
  .shop-header { position: relative; }
  .header-inner {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto auto;
    gap: 5px;
    min-height: auto;
    padding-block: 5px 8px;
  }
  .header-inner > .wordmark {
    min-width: 0;
    min-height: 44px;
    width: min(100%, 82px);
    justify-self: start;
    padding-block: 0;
  }
  .header-inner > .shop-nav {
    display: grid;
    grid-template-columns: repeat(3,minmax(0,1fr));
    grid-row: 2;
    grid-column: 1/-1;
    gap: 6px;
    overflow: visible;
  }
  .shop-nav a {
    justify-content: center;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--panel);
    font-size: .875rem;
  }
  .shop-nav :is([data-nav=home],[data-nav=about]),
  .header-actions :is([data-nav=account],[data-nav=garage]) { display: none; }
  .header-actions {
    grid-row: 1;
    grid-column: 2;
    flex-wrap: nowrap;
    gap: 4px;
  }
  .header-actions [data-nav=cart] {
    justify-content: center;
    min-width: 44px;
    padding-inline: 7px;
    border: 1px solid var(--line);
    border-radius: 5px;
    font-size: .875rem;
  }
  .mobile-shop-menu {
    position: relative;
    display: block;
    grid-row: 1;
    grid-column: 3;
  }
  .mobile-shop-menu > summary {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 5px;
    list-style: none;
    cursor: pointer;
  }
  .mobile-shop-menu > summary::-webkit-details-marker { display: none; }
  .mobile-shop-menu > summary svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-width: 1.8;
  }
  .mobile-shop-menu[open] > summary {
    color: var(--soft-red);
    border-color: var(--soft-red);
  }
  .mobile-menu-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .mobile-shop-links {
    position: absolute;
    z-index: 1;
    inset-inline-end: 0;
    top: calc(100% + 6px);
    width: min(14rem, calc(100vw - 32px));
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 24px #0003;
  }
  .mobile-shop-links a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding-inline: 10px;
    font-size: .9rem;
    font-weight: 650;
  }
  .mobile-shop-links a + a { border-top: 1px solid var(--line); }
  .mobile-shop-links a:is(:hover,[aria-current=page]) { color: var(--soft-red); }
}
@media (max-width: 360px) {
  .header-actions [data-nav=cart] {
    gap: 3px;
    padding-inline: 5px;
    font-size: .8rem;
  }
}
