:root {
  color-scheme: light;
  --paper: #f4f5f1;
  --panel: #fcfbf7;
  --panel-soft: #f5f6f1;
  --ink: #1c2528;
  --muted: #687176;
  --line: #d9ddd6;
  --line-strong: #9ba6a7;
  --accent: #a54e3d;
  --accent-dark: #743328;
  --steel: #315f71;
  --green: #4e7660;
  --gold: #b3842d;
  --focus: 0 0 0 3px rgba(49, 95, 113, 0.18);
  --shadow: 0 16px 46px rgba(28, 37, 40, 0.12);
  --shadow-soft: 0 10px 28px rgba(28, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--panel);
  color: var(--ink);
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, color 140ms ease;
}

button:hover,
button:focus-visible {
  border-color: var(--steel);
  box-shadow: var(--focus);
  outline: none;
}

button:hover {
  background: #f2f5f3;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 382px;
  min-height: 100vh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns 180ms ease;
}

.app-shell.settings-closed {
  grid-template-columns: minmax(0, 1fr) 0;
}

.viewer {
  position: relative;
  min-height: 100vh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 252, 0.94), rgba(232, 238, 236, 0.88)),
    var(--paper);
}

#model-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
}

.model-badge,
.status-strip {
  position: absolute;
  left: 24px;
  border: 1px solid rgba(124, 134, 132, 0.42);
  border-radius: 6px;
  background: rgba(252, 251, 247, 0.88);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.model-badge {
  top: 24px;
  display: grid;
  gap: 4px;
  padding: 13px 15px;
}

.badge-kicker {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.model-badge strong {
  font-size: 18px;
  line-height: 1;
}

.model-badge span:not(.badge-kicker),
.status-strip {
  color: var(--muted);
  font-size: 12px;
}

.status-strip {
  bottom: 20px;
  min-width: 214px;
  padding: 9px 12px;
}

.settings-toggle {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 118px;
  min-height: 42px;
  border-color: rgba(55, 110, 131, 0.42);
  background: rgba(252, 251, 247, 0.92);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
  font-size: 13px;
  font-weight: 800;
}

.settings-toggle-mark {
  position: relative;
  display: inline-block;
  width: 17px;
  height: 13px;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.settings-toggle-mark::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 0;
  width: 17px;
  border-top: 2px solid currentColor;
}

.settings-toggle.is-open {
  border-color: rgba(28, 37, 40, 0.72);
  background: rgba(28, 37, 40, 0.92);
  color: #fffdf7;
}

.controls {
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  padding: 22px 22px 24px;
  border-left: 1px solid var(--line);
  background: rgba(252, 251, 247, 0.98);
  box-shadow: -18px 0 48px rgba(28, 37, 40, 0.08);
  overflow-y: auto;
  transition: transform 180ms ease, opacity 180ms ease, visibility 180ms ease, padding 180ms ease, border-color 180ms ease;
}

.app-shell.settings-closed .controls {
  width: 0;
  min-width: 0;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(100%);
  padding-inline: 0;
  border-left-color: transparent;
  overflow: hidden;
}

.settings-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -22px -22px 18px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(252, 251, 247, 0.95);
  backdrop-filter: blur(10px);
}

.settings-bar strong {
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.close-settings {
  min-height: 34px;
  padding-inline: 11px;
  border-color: rgba(55, 110, 131, 0.28);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.control-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
p,
dl,
dd {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.08;
}

h2 {
  margin-bottom: 10px;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.quick-metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 15px;
}

.quick-metrics div {
  display: grid;
  grid-template-columns: 88px 1fr;
  align-items: center;
  min-height: 38px;
  border-top: 1px solid var(--line);
}

.quick-metrics dt {
  color: var(--muted);
  font-size: 12px;
}

.quick-metrics dd {
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.control-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.segmented button {
  min-width: 0;
  padding: 0 8px;
  border-color: transparent;
  background: #eef1ed;
  box-shadow: inset 0 0 0 1px rgba(28, 37, 40, 0.05);
  color: #344044;
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.segmented button.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fffdf7;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(28, 37, 40, 0.12);
}

.layer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.layer-grid label {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 44px 0 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(245, 246, 241, 0.86);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 700;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.layer-grid input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.layer-grid span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.layer-grid label::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 10px;
  width: 28px;
  height: 15px;
  margin-top: -7.5px;
  border: 1px solid #c2cbc7;
  border-radius: 999px;
  background: #dfe5e1;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.layer-grid label::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 24px;
  z-index: 1;
  width: 11px;
  height: 11px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: #fffef9;
  box-shadow: 0 1px 4px rgba(28, 37, 40, 0.2);
  transition: right 140ms ease, background-color 140ms ease;
}

.layer-grid label:has(input:checked) {
  border-color: rgba(49, 95, 113, 0.42);
  background: #eef4f0;
}

.layer-grid label:has(input:checked)::after {
  border-color: rgba(49, 95, 113, 0.5);
  background: var(--steel);
}

.layer-grid label:has(input:checked)::before {
  right: 12px;
}

.layer-grid label:focus-within {
  box-shadow: var(--focus);
}

.slider-stack {
  display: grid;
  gap: 16px;
}

.slider-stack label {
  display: grid;
  gap: 7px;
}

.slider-stack span {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="range"]:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.action-row button {
  padding: 0 8px;
  border-color: rgba(155, 166, 167, 0.72);
  background: #f4f5f0;
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.action-row button.is-active,
button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fffdf7;
}

.selection-panel {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(248, 249, 244, 0.98), rgba(252, 251, 247, 0.98));
  box-shadow: 0 12px 34px rgba(28, 37, 40, 0.07);
}

.selection-panel h2 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  text-transform: none;
}

.selection-panel p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.source-note {
  color: var(--accent-dark) !important;
  font-weight: 700;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: 100vh;
    height: 100svh;
    overflow: hidden;
  }

  .viewer {
    min-height: 100vh;
    min-height: 100svh;
    height: 100vh;
    height: 100svh;
  }

  #model-canvas {
    height: 100vh;
    height: 100svh;
    min-height: 100vh;
    min-height: 100svh;
  }

  .controls {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 18;
    height: auto;
    max-height: min(80vh, 760px);
    max-height: min(80svh, 760px);
    min-height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -24px 60px rgba(28, 37, 40, 0.18);
    overflow-y: auto;
    transform: translateY(0);
  }

  .app-shell.settings-closed .controls {
    transform: translateY(105%);
    padding-inline: 22px;
    border-top-color: transparent;
  }

  .settings-bar {
    top: 0;
  }

  .settings-bar::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: rgba(104, 113, 118, 0.34);
    transform: translateX(-50%);
  }
}

@media (max-width: 560px) {
  .controls {
    padding: 16px;
    max-height: min(82vh, 720px);
    max-height: min(82svh, 720px);
  }

  .model-badge,
  .status-strip {
    left: 12px;
    right: 12px;
  }

  .model-badge {
    top: 12px;
    padding: 10px 11px;
    max-width: calc(100% - 132px);
  }

  .model-badge strong {
    font-size: 15px;
  }

  .badge-kicker {
    font-size: 9px;
  }

  .status-strip {
    bottom: 12px;
  }

  .settings-toggle {
    top: 12px;
    right: 12px;
    min-width: 98px;
    min-height: 40px;
    padding: 0 10px;
  }

  .settings-bar {
    top: 0;
    margin: -16px -16px 16px;
    padding: 12px 16px;
  }

  .segmented,
  .action-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  button {
    min-height: 42px;
  }

  .layer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layer-grid label {
    min-height: 40px;
    padding-right: 42px;
  }

  h1 {
    font-size: 26px;
  }

  .quick-metrics div {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .quick-metrics dd {
    font-size: 13px;
  }

  .control-section {
    padding: 16px 0;
  }

  .selection-panel {
    margin-top: 16px;
  }
}

@media (max-width: 380px) {
  .settings-toggle-label {
    display: none;
  }

  .settings-toggle {
    min-width: 42px;
  }

  .model-badge {
    max-width: calc(100% - 74px);
  }

  .layer-grid {
    grid-template-columns: 1fr;
  }
}
