:root {
  --ink: #191c20;
  --line: #d9dcdd;
  --header-height: 76px;
  --edge: clamp(16px, 3vw, 54px);
  --surface: #f0f1f2;
  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 #be0102; 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(14px, 2vw, 32px); min-width: 0; }
.identity h1 { font-size: clamp(24px, 3.1vw, 46px); line-height: 1.08; font-weight: 700; letter-spacing: -.052em; white-space: nowrap; }
.finish { border-left: 1px solid #afb4b6; padding-left: clamp(14px, 2vw, 32px); gap: 9px; font-size: 15px; font-weight: 500; min-width: 0; white-space: nowrap; }
.finish i { flex-shrink: 0; width: 17px; height: 17px; border-radius: 50%; background: #be0102; 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(14px, 1.8vw, 28px); 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; }
#linkage-labels { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
#linkage-labels span {
  position: absolute; transform: translate(-50%, calc(-100% - 25px)); white-space: nowrap;
  background: #fffffff2; border-radius: 4px; padding: 3px 7px; color: var(--ink); font-size: 12px;
}
#linkage-labels span::after { content: ''; position: absolute; top: 100%; left: 50%; height: 25px; border-left: 1px solid #42474b; }
#linkage-labels span:last-child { transform: translate(-50%, 25px); }
#linkage-labels span:last-child::after { top: auto; bottom: 100%; }
.show-photos #linkage-labels, .hide-hud #linkage-labels { visibility: hidden; }
#loader { display: grid; place-items: center; background: var(--surface); z-index: 15; }
#loader.done { display: none; }
#load-status { max-width: 32em; margin: 0 20px; color: var(--ink); 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(420px, 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; padding: 4px 10px; font-weight: 500; font-size: 14px; line-height: 1.2; }
#info { font-size: 12px; color: #505965; margin: 12px 0 15px; }
#info .accent { font-weight: 600; color: var(--ink); }
.controls-panel > p > a { display: inline-block; margin-bottom: 12px; }
.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: 270px; 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 .title { font-weight: 600; }
#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 figure { min-height: 0; position: relative; display: grid; place-items: center; touch-action: pan-y; }
#photo { width: 100%; height: 100%; object-fit: contain; position: absolute; inset: 0; user-select: none; }
#photo-error { padding: 24px; text-align: center; }
#photo-footer { display: grid; justify-items: center; gap: 8px; padding: 14px var(--edge) max(16px, env(safe-area-inset-bottom)); }
#full-photo[hidden] { display: inline !important; visibility: hidden; }
#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; max-width: min(290px, 52vw); }
.show-photos #bar, .show-photos #loader, .show-photos #callout, .show-photos #stage { visibility: hidden; }

@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(10px, 3vw, 18px); font-size: 13px; min-width: 0; }
  #drag-hint { font-size: 12px; }
}
/* Below 800 px on portrait screens, give the mode switch its own clean row. */
@media (max-width: 800px) and (orientation: portrait), (max-width: 800px) and (min-height: 541px) {
  :root { --header-height: 98px; }
  #studio-header { flex-wrap: wrap; align-content: center; gap: 8px 12px; padding: 8px 14px; }
  .identity { gap: 12px; }
  .identity h1 { font-size: 23px; }
  .finish { padding-left: 12px; gap: 7px; font-size: 13px; }
  .finish i { width: 12px; height: 12px; }
  .mode-switch { flex: 1 0 100%; }
  .mode-switch a { flex: 1 1 auto; padding: 0 10px; font-size: 13px; }
}
@media (max-width: 440px) and (orientation: portrait) {
  .identity h1 { font-size: 21px; }
  .mode-switch a { padding: 0 6px; font-size: 13px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  :root { --header-height: 48px; }
  #studio-header { min-height: var(--header-height); padding: 3px var(--edge); }
  .identity { gap: 12px; }
  .identity h1 { font-size: 22px; }
  .finish { padding-left: 12px; gap: 7px; font-size: 12px; }
  .finish i { width: 10px; height: 10px; }
  .mode-switch a { min-height: 36px; padding: 0 clamp(10px, 1.5vw, 20px); 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: 660px) {
  .finish { display: none; }
}

@media (max-width: 360px) {
  #tools > button, #more > summary { padding-inline: 7px; font-size: 12px; }
}
.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; white-space: nowrap; }
.photo-tools #match-view:hover { background: #40464d; }
.photo-tools #match-view:disabled { background: #e1e3e5; color: #686c71; cursor: default; }
@media (max-width: 640px) {
  .photo-tools #match-view { padding-inline: 10px; font-size: 12px; }
  .photo-tools button { min-width: 38px; }
  .photo-tools select { max-width: 44vw; font-size: 13px; }
}
@media (max-width: 360px) {
  #photo-footer { padding-inline: 4px; grid-template-columns: minmax(0, 1fr); }
  .photo-tools select { min-width: 0; width: 130px; padding-inline: 2px; }
}

#photo-tools-3d {
  position: fixed; top: calc(var(--header-height) + 12px); left: var(--edge); z-index: 8;
  display: flex; align-items: center; gap: 6px;
}
#photo-tools-3d a, #photo-tools-3d button, #overlay-error {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  color: var(--ink); background: #fffffff5; font-size: 13px;
}
#overlay-opacity { width: min(90px, 18vw); accent-color: #ac1821; }
#overlay-toggle[aria-pressed="true"] { background: var(--ink); color: white; }
#reference-overlay { position: fixed; pointer-events: none; z-index: 5; object-fit: contain; }
.show-photos :is(#photo-tools-3d,#reference-overlay), .hide-hud :is(#photo-tools-3d,#reference-overlay) { visibility: hidden; }
@media (max-width: 480px) {
  #photo-tools-3d { top: calc(var(--header-height) + 8px); left: 10px; }
}

/* Keep the gallery image rectangle measurable when fitting the 3D camera. */
#photo-room[hidden] { display: grid !important; visibility: hidden; pointer-events: none; }
