:root {
  --ink: #191c20;
  --line: #d9dcdd;
  --header-height: 76px;
  --edge: clamp(16px, 3vw, 54px);
  --surface: #f0f1f2;
  --frame-w: 16;
  --frame-h: 9;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface); overflow: hidden; }
h1, h2, p, figure { margin: 0; }
button, select, input { font: inherit; }
button, summary, select { cursor: pointer; }
a { color: inherit; text-underline-offset: .2em; }
:focus-visible { outline: 3px solid #2164a0; outline-offset: 2px; }
[hidden] { display: none !important; }

#studio-header {
  position: fixed; inset: 0 0 auto; z-index: 30;
  min-height: var(--header-height);
  padding: 10px var(--edge);
  background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.identity, .finish, .mode-switch { display: flex; align-items: center; }
/* When the tabs need the room, the paint name shortens before anything overflows. */
.identity { gap: clamp(10px, 1.5vw, 24px); min-width: 0; }
.identity h1 { font-size: clamp(18px, 2.2vw, 34px); line-height: 1.08; font-weight: 700; letter-spacing: -.042em; white-space: nowrap; }
.finish { border-left: 1px solid #afb4b6; padding-left: clamp(10px, 1.5vw, 24px); gap: 8px; font-size: 14px; font-weight: 500; min-width: 0; white-space: nowrap; }
.finish i { flex-shrink: 0; width: 17px; height: 17px; border-radius: 50%; background: #1d3257; box-shadow: inset 0 0 0 1px #0002; }
.finish span { overflow: hidden; text-overflow: ellipsis; }
.mode-switch { align-items: stretch; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.mode-switch a { min-height: 40px; display: grid; place-items: center; padding: 0 clamp(12px, 1.6vw, 26px); font-weight: 550; font-size: 14px; line-height: 1.15; text-align: center; text-decoration: none; }
.mode-switch a + a { border-left: 1px solid var(--line); }
.mode-switch a:hover { background: #eef0f1; }
.mode-switch a[aria-current="true"] { color: white; background: var(--ink); }
.mode-switch a:focus-visible { outline-offset: -4px; }
#stage, #loader { position: fixed; inset: 0; width: 100%; height: 100%; }
#stage { display: block; touch-action: none; cursor: grab; }
#stage.grabbing { cursor: grabbing; }
#stage.hover-part { cursor: pointer; }
#loader { background: #f1f2f3; z-index: 15; transition: opacity .2s ease-out, visibility 0s linear .2s; }
#loader.done { opacity: 0; pointer-events: none; visibility: hidden; }
#load-status { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); max-width: 88%; padding: 8px 14px; border-radius: 6px; background: white; font-size: 13px; text-align: center; }

#bar {
  position: fixed; z-index: 10; inset: auto 0 max(24px, env(safe-area-inset-bottom));
  display: grid; justify-items: center; gap: 9px; padding: 0 10px; pointer-events: none;
}
#drag-hint { font-size: 13px; line-height: 1.4; font-weight: 500; color: #30353a; text-shadow: 0 0 5px #fff; }
#drag-hint .touch, #drag-hint .cabin-hint { display: none; }
#bar.in-cabin #drag-hint { padding: 3px 10px; background: #fffffff2; border-radius: 4px; }
#bar.in-cabin #drag-hint > span { display: none; }
#bar.in-cabin #drag-hint .cabin-hint.mouse { display: inline; }
#tools, .photo-tools {
  position: relative; pointer-events: auto; display: flex; align-items: center;
  background: white; border: 1px solid #0002; border-radius: 10px;
  box-shadow: 0 3px 14px #18212d12; padding: 3px;
}
#tools > button, #more > summary, .photo-tools button, .photo-tools select {
  position: relative; appearance: none; list-style: none; color: var(--ink); background: transparent;
  border: 0; border-radius: 6px; display: grid; place-items: center; padding: 0 clamp(14px, 2.2vw, 36px);
  min-height: 44px; font-size: 14px; font-weight: 550; line-height: 1.15; text-align: center;
}
#tools > :not(:last-child)::after { content: ''; position: absolute; background: var(--line); right: 0; top: 30%; height: 40%; width: 1px; pointer-events: none; }
#more { position: static; }
#tools > #more::after { display: none; }
#more > summary::after { content: ''; position: absolute; background: var(--line); right: 0; top: 30%; height: 40%; width: 1px; }
#more > summary::-webkit-details-marker { display: none; }
#tools button:hover, #tools summary:hover, .photo-tools button:hover { background: #eef1f3; }
#tools button:disabled { opacity: .55; cursor: wait; }
#tools button[aria-pressed=true], #more[open] > summary { color: white; background: #23282e; }
.controls-panel {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(100% + 10px);
  width: min(410px, calc(100vw - 20px)); max-height: calc(100dvh - var(--header-height) - 104px); overflow: auto;
  padding: 22px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 35px #19252d25;
}
.controls-panel h2 { font-size: 20px; font-weight: 650; letter-spacing: -.035em; margin: 0 0 12px; }
.panel-buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.panel-buttons button { background: #f4f5f6; color: var(--ink); border: 1px solid #e0e2e4; border-radius: 5px; min-height: 44px; font-weight: 500; font-size: 14px; padding: 0 10px; }
.panel-buttons button.full-span { grid-column: 1 / -1; }
.top-view { display: inline-block; margin: 12px 0 7px; font-size: 14px; }
#info { font-size: 12px; color: #505965; margin: 5px 0 15px; }
.notes { border-top: 1px solid var(--line); padding: 2px 0; }
.notes summary { padding: 9px 2px; font-size: 14px; font-weight: 550; }
.notes p, .sources { font-size: 13px; line-height: 1.5; margin: 0 0 8px; color: #3d454d; }
.sources a { display: inline-block; margin-bottom: 5px; }

#callout { position: fixed; z-index: 9; pointer-events: none; display: none; max-width: 260px; padding: 8px 11px; background: #fffffff2; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; transform: translate(14px, -12px); }
#callout.visible { display: grid; }
#callout .sub { font-size: 11px; color: #52606d; }
.hide-hud #studio-header, .hide-hud #bar, .hide-hud #callout { visibility: hidden; }

#photo-room { position: fixed; inset: var(--header-height) 0 0; z-index: 19; display: grid; grid-template-rows: minmax(0, 1fr) auto; background: #181a1d; color: white; }
#photo-room[hidden] { display: grid !important; visibility: hidden; pointer-events: none; }
#photo-room figure { min-height: 0; position: relative; display: grid; place-items: center; touch-action: pan-y; container-type: size; overflow: hidden; }
.photo-frame {
  position: relative;
  width: min(100cqw, calc(100cqh * var(--frame-w) / var(--frame-h)));
  aspect-ratio: var(--frame-w) / var(--frame-h);
}
#photo { width: 100%; height: 100%; object-fit: contain; position: absolute; inset: 0; user-select: none; }
#photo-error { position: absolute; background: #181a1d; padding: 24px; }
#photo-footer { display: grid; justify-items: center; gap: 8px; padding: 14px var(--edge) max(16px, env(safe-area-inset-bottom)); background: #181a1d; }
#photo-footer p { font-size: 12px; color: #d7dade; text-align: center; }
.photo-tools button { min-width: 48px; padding: 0 13px; font: 28px/1 system-ui, sans-serif; }
.photo-tools select { display: block; appearance: auto; padding: 0 7px; font-size: 14px; }
.show-photos #bar, .show-photos #loader, .show-photos #callout, .show-photos #stage { visibility: hidden; }

.photo-tools #compare-view {
  font: inherit; font-weight: 550; font-size: 14px; padding-inline: 12px;
}
.photo-tools #compare-view[aria-pressed="true"] { background: var(--ink); color: white; }
.photo-tools #compare-view:disabled { color: #686c71; cursor: default; }
.photo-tools #match-view { margin-left: 4px; padding: 0 15px; font-family: inherit; font-size: 14px; font-weight: 550; line-height: 1.2; background: #252a30; color: white; }
.photo-tools #match-view:hover { background: #40464d; }
.photo-tools #match-view:disabled { background: #e1e3e5; color: #686c71; cursor: default; }

.compare-photos #stage { visibility: visible; pointer-events: none; }
.compare-photos #photo-room { background: transparent; }
.compare-photos .photo-frame { box-shadow: 0 0 0 200vmax #181a1d; }
.compare-photos #photo { clip-path: inset(0 calc(100% - var(--photo-share, 50%)) 0 0); }
.compare-photos .photo-frame::after {
  content: ''; position: absolute; inset-block: 0; left: var(--photo-share, 50%);
  width: 2px; transform: translateX(-1px); background: white;
  box-shadow: 0 0 3px #0008; pointer-events: none;
}
#comparison-controls {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; min-height: 36px;
  padding: 0 12px; border-radius: 7px; background: #191c20eb; color: white;
  font-size: 13px; white-space: nowrap;
}
#comparison-split { width: clamp(95px, 16vw, 190px); min-height: 32px; margin: 0; accent-color: #c3e4ff; }

@media (pointer: coarse) {
  #callout.visible { display: none; }
  #drag-hint .mouse, #bar.in-cabin #drag-hint .cabin-hint.mouse { display: none; }
  #drag-hint .touch, #bar.in-cabin #drag-hint .cabin-hint.touch { display: inline; }
  #drag-hint .cabin-hint.touch { display: none; }
}
@media (max-width: 640px) {
  #bar { bottom: max(14px, env(safe-area-inset-bottom)); gap: 7px; padding: 0 6px; }
  #tools { max-width: 100%; }
  #tools > button, #more > summary { padding: 0 clamp(6px, 2.2vw, 14px); font-size: 12px; min-width: 0; }
  #drag-hint { font-size: 12px; }
  #photo-footer { padding-inline: 5px; }
  .photo-tools { width: min(100%, 420px); }
  .photo-tools select { width: 0; min-width: 0; flex: 1; font-size: 12px; padding-inline: 2px; }
  .photo-tools #compare-view, .photo-tools #match-view { flex: 0 0 auto; padding-inline: 7px; font-size: 12px; }
  .photo-tools > button { min-width: 32px; padding-inline: 5px; }
}
@media (max-width: 1080px) and (orientation: portrait), (max-width: 1080px) and (min-height: 541px) {
  :root { --header-height: 98px; }
  #studio-header { flex-wrap: wrap; align-content: center; gap: 8px 12px; padding: 8px 14px; }
  .identity { gap: 10px; }
  .identity h1 { font-size: clamp(17px, 4.3vw, 24px); }
  .finish { padding-left: 10px; gap: 7px; font-size: 13px; }
  .finish i { width: 11px; height: 11px; }
  .mode-switch { flex: 1 0 100%; }
  .mode-switch a { flex: 1 1 auto; padding: 0 8px; font-size: 13px; }
}
@media (max-width: 520px) and (orientation: portrait) {
  .finish { display: none; }
  .mode-switch a { padding: 0 5px; font-size: 12px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  :root { --header-height: 48px; }
  #studio-header { min-height: var(--header-height); padding: 3px var(--edge); }
  .identity { gap: 10px; }
  .identity h1 { font-size: clamp(17px, 2.8vw, 22px); }
  .finish { padding-left: 10px; gap: 7px; font-size: 12px; }
  .finish i { width: 10px; height: 10px; }
  .mode-switch a { min-height: 36px; padding: 0 clamp(8px, 1.4vw, 18px); font-size: 13px; }
  #bar { bottom: max(5px, env(safe-area-inset-bottom)); gap: 2px; }
  #drag-hint { font-size: 11px; }
  #photo-footer { flex-direction: row; display: flex; justify-content: center; align-items: center; padding-block: 4px; gap: 16px; }
  .controls-panel { max-height: calc(100dvh - 120px); }
}
@media (orientation: landscape) and (max-height: 540px) and (max-width: 760px) {
  .finish { display: none; }
}
@media (prefers-reduced-motion: reduce) { #loader { transition: none; } }
@media (max-width: 360px) {
  #tools > button, #more > summary { padding-inline: 4px; font-size: 11px; }
  #photo-footer { padding-inline: 4px; grid-template-columns: minmax(0, 1fr); }
  .photo-tools select { min-width: 0; width: 122px; padding-inline: 2px; }
}

.cars-back { white-space: nowrap; color: #4e565c; font-size: 14px; font-weight: 550; text-underline-offset: 3px; }
#powertrain-room { position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 12; display: flex; align-items: center; gap: 10px; max-width: calc(100% - 16px); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px 5px 13px; font-size: 14px; }
#inspection-choice { font: inherit; background: white; color: var(--ink); border: 0; min-height: 36px; max-width: calc(100vw - 88px); }
.show-powertrain #bar { visibility: hidden; }
@media (max-width: 390px) {
  .identity { gap: 8px; }
  .identity h1 { font-size: 16px; }
  .cars-back { font-size: 12px; }
}
@media (orientation: landscape) and (max-height: 540px) and (max-width: 840px) { .finish { display: none; } }
