.workspace-dock {
  flex-shrink: 0;
}

.app-shell {
  container-type: inline-size;
}

@media (min-width: 1041px) {
  .settings-panel {
    left: 0;
    right: auto;
  }
}

@media (min-width: 601px) and (max-width: 1040px) {
  .settings-panel {
    position: fixed;
    top: 72px;
    left: 12px;
    right: auto;
  }
}

.dock-toolbar,
.dock-actions,
.sidebar-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dock-toolbar {
  justify-content: space-between;
  padding: 7px 10px;
}

.dock-actions button[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-strong);
}

.workspace-dock .workspace-bottom-grid {
  display: block;
}

.workspace-dock .surface-head {
  margin: -14px -14px 10px;
}

.workspace-dock .eyebrow {
  display: none;
}

.sidebar {
  gap: 0;
  padding: 0;
}

.sidebar-tabs {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  padding: 9px;
  border-bottom: 1px solid var(--line-pale);
  background: var(--paper-soft);
}

.sidebar-tabs button {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  box-shadow: none;
  font-size: 0.86rem;
}

.sidebar-tabs button[aria-selected="true"] {
  border-color: var(--line-pale);
  background: var(--paper);
  color: var(--ink);
}

.sidebar-section {
  gap: 10px;
}

.sidebar-section .surface-head {
  flex-shrink: 0;
  margin-bottom: 0;
}

.sidebar-section .control-group {
  flex-shrink: 0;
  padding: 12px;
}

.sidebar-section .group-title {
  margin-bottom: 9px;
  letter-spacing: 0.03em;
  font-size: 0.76rem;
}

.sidebar-section .range-field {
  gap: 6px;
  margin-block: 5px;
}

.sidebar-section .range-field > span {
  justify-content: space-between;
}

.sidebar-section .field span strong {
  flex-shrink: 0;
  min-width: 44px;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.sidebar-section .inline-field span {
  font-size: 0.82rem;
}

.sidebar-section .stack-list {
  max-height: none;
  overflow: visible;
}

.sidebar-section .quick-preset-grid {
  grid-template-columns: 1fr;
}

.sidebar-section .quick-preset-card {
  gap: 8px;
}

.viewport-canvas {
  position: relative;
  min-height: 0;
  min-width: 0;
}

.viewport-canvas > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.viewport-help {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 3;
  padding: 5px 9px;
  border-radius: 6px;
  background: #0d1820c9;
  color: #cedbe4;
  font-size: 0.7rem;
  pointer-events: none;
}

.viewport-zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  display: flex;
  gap: 6px;
}

.viewport-zoom button {
  width: 36px;
  min-height: 34px;
  padding: 0;
  border: 1px solid #566e7d;
  background: #162b37;
  color: #fff;
  font-size: 1.25rem;
  box-shadow: none;
}

.app-footer {
  flex-shrink: 0;
  min-height: 26px;
  padding: 4px 10px;
  border: none;
  background: transparent;
  box-shadow: none;
  font-size: 0.72rem;
}

.app-footer::before {
  display: none;
}

.progress-panel {
  position: absolute;
  inset: auto 100px 24px 24px;
  z-index: 4;
  margin: 0;
  pointer-events: none;
}

body[data-theme="modern"] .app-footer {
  border: none;
  background: transparent;
  box-shadow: none;
  color: #465e6c;
}

body[data-theme="modern"] .app-footer a {
  color: #176389;
}

body[data-theme="modern"] .sidebar-tabs {
  background: #eaf0f4;
}

body[data-theme="modern"] .surface .tiny-note {
  color: #526c7b;
}

body[data-theme="modern"] .sidebar-tabs button[aria-selected="true"] {
  border-color: #b9cdd8;
  background: #fff;
  color: #144963;
}

body[data-theme="modern"] button.secondary {
  border: 1px solid #aebfc9;
  background: #f0f5f7;
  box-shadow: none;
}

body[data-theme="modern"] input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border: none;
  background: #cfdae1;
}

body[data-theme="modern"] input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #2783a8;
  box-shadow: 0 0 0 1px #227a9e;
}

body[data-theme="modern"] input[type="range"]::-moz-range-track {
  height: 6px;
  border: none;
  background: #cfdae1;
}

body[data-theme="modern"] input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #2783a8;
  box-shadow: 0 0 0 1px #227a9e;
}

@media (min-width: 1041px) {
  html {
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 0;
    overflow: hidden;
  }

  .app-shell {
    height: calc(100dvh / var(--ui-scale, 1));
    min-height: 0;
    gap: 10px;
    padding: 10px;
  }

  .topbar {
    flex-shrink: 0;
  }

  .workspace-grid {
    flex: 1;
    min-height: 0;
    align-items: stretch;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 10px;
  }

  .workspace-main {
    min-height: 0;
    gap: 10px;
  }

  .stage-surface {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
  }

  .stage-head,
  .stage-assets {
    flex-shrink: 0;
  }

  .viewport-layout {
    flex: 1;
    height: auto;
    min-height: 0;
  }

  .viewport-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .viewport-canvas {
    flex: 1;
    min-height: 0;
  }

  .sidebar {
    position: relative;
    top: auto;
    max-height: none;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar-section {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .workspace-dock[data-panel="none"] .workspace-bottom-grid {
    display: none;
  }

  .workspace-dock .workspace-bottom-grid {
    height: clamp(180px, 28dvh, 260px);
    overflow: auto;
    overscroll-behavior: contain;
  }

  .texture-preview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace-dock .preview-panel {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 8px;
  }

  .workspace-dock .preview-stage {
    height: clamp(90px, 15dvh, 140px);
    min-height: 0;
    margin: 0;
    aspect-ratio: auto;
  }

  .workspace-dock .preview-stage canvas {
    object-fit: contain;
  }

  .workspace-dock .preview-empty {
    padding: 8px;
  }

  .workspace-dock .summary-grid {
    margin-top: 12px;
  }
}

@media (max-width: 1040px) {
  .sidebar-section {
    max-height: 70dvh;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .viewport-layout.compare {
    height: max(550px, 75dvh);
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .app-footer .tiny-note {
    display: none;
  }
}

body.fullscreen-mode .workspace-dock,
body.fullscreen-mode .stage-assets {
  display: none;
}

body.fullscreen-mode .app-shell {
  height: calc(100dvh / var(--ui-scale, 1));
  min-height: 0;
  gap: 0;
}

body.fullscreen-mode .workspace-main,
body.fullscreen-mode .workspace-grid {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

body.fullscreen-mode .stage-surface {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

body.fullscreen-mode .stage-head { flex-shrink: 0; }

body.fullscreen-mode .viewport-layout {
  flex: 1;
  height: auto;
  min-height: 0;
}

body.fullscreen-mode .viewport-card,
body.fullscreen-mode .viewport-canvas {
  min-height: 0;
}

body.fullscreen-mode .viewport-card {
  display: flex;
  flex-direction: column;
}

body.fullscreen-mode .viewport-canvas {
  flex: 1;
  height: auto;
}

@container (max-width: 1050px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .topbar-actions {
    flex: 1 1 100%;
    justify-content: flex-start;
  }

  .stage-head {
    flex-wrap: wrap;
  }

  .stage-head-actions {
    justify-content: flex-start;
  }
}
.recovery-link {
  display: inline-block;
  margin: 12px 8px 0;
  color: #164f77;
  text-decoration: underline;
  font-size: 14px;
}

/* A desktop-height lock can collapse the 3D view when browser/UI zoom enlarges the toolbars. */
@media (min-width: 1041px) and (max-height: 650px) {
  html, body {
    height: auto;
    overflow: auto;
  }
  .app-shell {
    height: auto;
    min-height: calc(100dvh / var(--ui-scale, 1));
  }
  .stage-surface { flex: none; }
  .viewport-layout { flex: none; height: 300px; }
  .sidebar { max-height: 600px; }
  body.fullscreen-mode .app-shell { height: calc(100dvh / var(--ui-scale, 1)); }
  body.fullscreen-mode .viewport-layout { flex: 1; height: auto; }
}
/* The mascot keeps its alpha channel on both editor themes. */
body .topbar .brand-mark.brand-logo {
  display: block;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  object-fit: contain;
  image-rendering: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 10000;
  transform: translateY(-200%);
  padding: 12px 16px;
  background: #fff;
  color: #17191d;
  border: 2px solid #17191d;
  border-radius: 8px;
}
.skip-link:focus { transform: none; }
.app-footer .app-summary { display: block; margin: 0; max-width: 65ch; color: var(--ink-soft); }
.app-footer { gap: 8px 18px; flex-shrink: 0; color: var(--ink); background: var(--paper-soft); }
.app-footer a { color: #254f68; }
.app-footer > a { flex-shrink: 0; }
.no-script-note {
  position: relative;
  z-index: 100;
  padding: 18px;
  margin: 0;
  background: #fff;
  color: #17191d;
}
.no-script-note a { color: #254f68; }
@media (max-width: 1040px) {
  .app-footer { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

.file-drop-hint { margin: 3px 0 0; font-size: 0.72rem; line-height: 1.3; color: var(--ink-soft); }
.stage-surface.is-dragging { outline: 3px solid #2589a9; outline-offset: -3px; }
.stage-surface.is-dragging::after { content: "Drop model or texture here"; position: absolute; inset: 0; z-index: 25; display: grid; place-items: center; padding: 20px; text-align: center; background: #f3f4f5e8; color: #17191d; font-size: 1.3rem; font-weight: 700; pointer-events: none; border-radius: inherit; }

/* Appearance controls use panel colors rather than inheriting the dark topbar. */
.settings-panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
body .topbar .settings-panel { color: var(--ink); }
body .topbar #settingsPanel button {
  color: var(--ink); background: var(--paper-soft); border: 1px solid var(--line-soft); box-shadow: none;
}
body .topbar #settingsPanel .theme-option.is-active {
  border: 2px solid var(--ink); background: var(--paper-strong); color: var(--ink);
}
.settings-panel .theme-option { grid-template-columns: 18px minmax(0, 1fr); gap: 4px 8px; }
.settings-panel .theme-option > span:last-child { grid-column: 2; }
.settings-panel .settings-close { width: 36px; min-width: 36px; min-height: 36px; padding: 0; font-size: 1.4rem; }
.settings-note { margin: 0; color: var(--ink-soft); font-size: .74rem; line-height: 1.5; }
.settings-motion { display: flex; gap: 10px; align-items: center; font-size: .85rem; min-height: 44px; cursor: pointer; }
.settings-motion input { width: 18px; height: 18px; margin: 0; accent-color: var(--ink); }
.settings-panel { overscroll-behavior: contain; scrollbar-width: thin; }
.theme-option[data-theme-choice="contrast"] .theme-chip { background: linear-gradient(90deg, #000 50%, #fff 50%); border-color: #888; }
.settings-toggle { min-height: 44px; min-width: 44px; width: 44px; }
.settings-toggle-icon { width: 21px; height: 21px; stroke-width: 1.7; }
body[data-reduce-motion="true"] *, body[data-reduce-motion="true"] *::before, body[data-reduce-motion="true"] *::after {
  animation: none !important; transition: none !important; scroll-behavior: auto !important;
}

/* Neutral light skin follows the PPH palette without changing the saved default. */
body[data-theme="clean"] { --paper: #f3f4f5; --paper-soft: #fff; --paper-strong: #e5e7eb; --ink: #17191d; --ink-soft: #535963; --line-soft: #8b929c; background: #f3f4f5; }
body[data-theme="clean"] :is(.surface, .surface-head, .topbar) { background: var(--paper-soft); color: var(--ink); border-color: var(--line-pale); box-shadow: 0 4px 20px #17191d0a; }
body[data-theme="clean"] :is(button.secondary, select, textarea, input[type="text"]) { background: #fff; color: var(--ink); }
body[data-theme="clean"] .app-footer { color: var(--ink); }
body[data-theme="clean"] .app-footer a { color: #254f68; }
body[data-theme="clean"] .topbar .eyebrow { color: var(--ink-soft); }
body[data-theme="clean"] :is(.surface-head-copy h2, .surface-head-copy h3)::after { display: none; }

/* Complete the existing dark skin's secondary surfaces. */
body[data-theme="dark"] :is(.field span strong, .quick-preset-card > span, .settings-scale-readout) { background: #242a39; color: var(--ink); }
body[data-theme="dark"] :is(.stage-callout, .progress-panel, .info-strip, .subtle-strip) { background: #242a39; color: var(--ink); }
body[data-theme="dark"] .sidebar-tabs { background: var(--paper-strong); }
body[data-theme="dark"] .file-drop-hint { color: #d8d0ff; }

body[data-theme="contrast"] {
  --paper: #080808; --paper-soft: #111; --paper-strong: #242424;
  --ink: #fff; --ink-soft: #eee; --ink-faint: #ddd;
  --line: #fff; --line-soft: #ccc; --line-pale: #888;
  --accent: #fff; --accent-strong: #333; --accent-blue: #ffea00; --accent-blue-strong: #333;
  --shadow: none; background: #000; color-scheme: dark;
}
body[data-theme="contrast"]::before, body[data-theme="contrast"]::after { display: none; }
body[data-theme="contrast"] :is(.surface, .topbar, .surface-head, .sidebar-tabs, .settings-panel, .preview-panel, .control-group, .summary-card, .list-card, .quick-preset-card, .stage-callout, .progress-panel, .info-strip, .subtle-strip, .consent-banner, .project-more-menu) {
  background: #080808; color: #fff; border-color: #aaa; box-shadow: none;
}
body[data-theme="contrast"] :is(button, select, textarea, input[type="text"], .stat-chip, .pill, .settings-scale-readout, .field span strong, .quick-preset-card > span) {
  background: #111; color: #fff; border-color: #ccc; box-shadow: none;
}
body[data-theme="contrast"] :is(.eyebrow, .tiny-note, .file-drop-hint, .workspace-picker span, .stat-chip span, .consent-copy span, .consent-copy strong, .app-footer) { color: #eee; }
body[data-theme="contrast"] :is(a, .app-footer a) { color: #ffea00; }
body[data-theme="contrast"] button:disabled { opacity: .65; }
body[data-theme="contrast"] :is([aria-selected="true"], [aria-pressed="true"]) { outline: 2px solid #ffea00; outline-offset: -2px; }
body[data-theme="contrast"] :focus-visible { outline: 3px solid #ffea00; }

/* Tablet: retain the preview beside a narrower inspector in landscape. */
@media (min-width: 900px) and (max-width: 1040px) {
  body:not(.fullscreen-mode) .workspace-grid { grid-template-columns: minmax(0, 1fr) 300px; gap: 10px; align-items: start; }
  body:not(.fullscreen-mode) .sidebar { position: sticky; top: 10px; }
  body:not(.fullscreen-mode) .sidebar-section { max-height: calc(100dvh - 80px); }
}
@media (min-width: 601px) and (max-width: 1040px) {
  body:not(.fullscreen-mode) .viewport-layout { height: clamp(360px, 52dvh, 560px); min-height: 0; }
  body:not(.fullscreen-mode) .viewport-layout.compare { height: clamp(560px, 80dvh, 800px); }
  body:not(.fullscreen-mode) :is(.viewport-card, .viewport-canvas) { min-height: 0; }
  .topbar-stats { display: none; }
}
@media (max-width: 600px) {
  .topbar { padding: 10px; }
  .brand-cluster { width: 100%; min-width: 0; }
  .brand-copy { flex: 1; min-width: 0; }
  .brand-title-row { justify-content: space-between; }
  .brand-heading h1 { font-size: clamp(1rem, 5vw, 1.3rem); }
  .topbar-stats { display: none; }
  .topbar-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .topbar-actions .workspace-picker { grid-column: 1 / -1; width: 100%; max-width: none; }
  .topbar-actions > * { min-width: 0; }
  .topbar-actions .project-more > summary { min-height: 44px; }
  .settings-panel { position: fixed; top: calc(80px / var(--ui-scale, 1)); left: 12px; right: 12px; width: auto; max-height: calc((100dvh - 96px) / var(--ui-scale, 1)); }
  .settings-scale-row { grid-template-columns: 40px minmax(0, 1fr) 40px; }
  .settings-scale-row > #scaleResetButton { grid-column: 1 / -1; }
  .settings-panel .theme-option { padding: 10px 8px; }
  body:not(.fullscreen-mode) .viewport-layout { height: clamp(280px, 48svh, 440px); min-height: 0; }
  body:not(.fullscreen-mode) .viewport-layout.compare { height: clamp(560px, 88svh, 800px); }
  body:not(.fullscreen-mode) :is(.viewport-card, .viewport-canvas) { min-height: 0; }
  .stage-head-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .stage-head-actions > button { width: 100%; min-width: 0; padding-inline: 8px; }
  .sidebar-tabs { position: sticky; top: 0; }
  .sidebar-tabs button, .viewport-zoom button { min-height: 44px; }
  .viewport-zoom button { min-width: 44px; }
  .viewport-help { max-width: calc(100% - 126px); }
}
@media (pointer: coarse) {
  button, select, .sidebar-tabs button, .dock-actions button { min-height: 44px; }
  input[type="range"] { min-height: 32px; }
}

.settings-panel button { transition: transform 120ms ease; }
/* Keep all skins visible without scrolling through six full-width rows. */
.settings-panel .theme-option-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 600px) {
  .stage-head-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* Keep the selected tool tab legible in the dark skin. */
body[data-theme="dark"] .sidebar-tabs button[aria-selected="true"] { background: var(--paper-strong); color: var(--ink); border-color: var(--line-soft); }
@media (min-width: 601px) {
  .settings-panel { max-height: min(680px, calc((100dvh - 110px) / var(--ui-scale, 1))); }
}
.sidebar-tabs button { transition: transform 120ms ease; }

/* Additional export options remain reachable on short and touch screens. */
.project-more-menu { width: min(300px, calc(100vw - 32px)); max-height: 62dvh; overflow-y: auto; overscroll-behavior: contain; }
.project-more-menu button { white-space: normal; min-height: 42px; padding-block: 8px; }

/* Header branding stays left; appearance follows More at the far right. */
.topbar .brand-cluster, .topbar .brand-title-row { align-items: center; }
.topbar .brand-copy { align-self: center; }
.topbar .brand-heading h1 { margin-block: 0; line-height: 1.2; }
.topbar .settings-panel { left: auto; right: 0; }
.topbar-actions > .settings-anchor { flex: 0 0 44px; align-self: center; }
@media (max-width: 1040px), (max-height: 600px) {
  .topbar .settings-panel { position: fixed; top: var(--settings-top, 80px); left: auto; right: 12px; max-height: calc(100dvh / var(--ui-scale, 1) - var(--settings-top, 80px) - 12px); }
}
@media (max-width: 600px) {
  .topbar-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .topbar-actions .workspace-picker { grid-column: 1 / -1; }
  .topbar-actions > #newProjectButton, .topbar-actions > #saveProjectButton, .topbar-actions > #exportPngButton { grid-column: span 2; }
  .topbar-actions > .settings-anchor { justify-self: end; }
  .topbar .settings-panel { left: 12px; right: 12px; }
}

@media (max-width: 600px) {
  .project-more-menu { position: fixed; left: 12px; right: 12px; top: var(--project-menu-top, 220px); width: auto; max-height: min(62dvh, calc(100dvh / var(--ui-scale, 1) - var(--project-menu-top, 220px) - 12px)); }
}
@media (min-width: 601px) and (max-height: 600px) {
  .project-more-menu { position: fixed; top: var(--project-menu-top, 80px); right: 12px; max-height: calc(100dvh / var(--ui-scale, 1) - var(--project-menu-top, 80px) - 12px); }
}
@media (min-width: 601px) and (max-width: 1040px) {
  .topbar-actions .workspace-picker { flex: 1 1 140px; }
  .topbar-actions .project-more { margin-left: auto; }
}
@media (min-width: 601px) and (max-width: 899px) {
  .topbar-actions .workspace-picker { flex: 1 1 100%; max-width: none; }
  .topbar-actions > button, .topbar-actions > .project-more > summary { font-size: .8rem; padding-inline: 8px; }
}
