:root {
  color-scheme: dark;
  --bg: #0e1011;
  --surface: #191c1f;
  --surface-2: #22272b;
  --surface-3: #111416;
  --panel: var(--surface);
  --panel-muted: var(--surface-2);
  --ink: #f3f5f7;
  --muted: #aeb6c2;
  --line: #363d42;
  --teal: #75b7ff;
  --teal-dark: #75b7ff;
  --amber: #65d6b1;
  --matte: var(--surface-3);
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  max-width: 1540px;
  margin: 0 auto;
  padding: 0 24px 28px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  align-items: center;
  max-width: 1540px;
  margin: 0 auto;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  background: var(--matte);
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.back-link:hover {
  border-color: var(--teal);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal-dark);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 650;
  line-height: 1.2;
}

h2,
h3 {
  font-size: 1rem;
  line-height: 1.2;
}

.workspace {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 286px;
  gap: 12px;
  max-width: 1540px;
  margin: 18px auto 0;
  align-items: start;
}

.sidebar,
.analysis-panel,
.viewer-area {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar,
.analysis-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 14px;
  padding: 14px;
}

.viewer-area {
  min-width: 0;
}

.control-section,
.histogram-section {
  display: grid;
  gap: 10px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 24px;
  border-radius: 8px;
  background: var(--panel-muted);
  color: var(--amber);
  font-size: 0.72rem;
  font-weight: 900;
}

.scene-list {
  display: grid;
  gap: 6px;
}

.scene-button {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.scene-button span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-align: center;
}

.scene-button strong {
  font-size: 0.9rem;
}

.scene-button.active {
  border-color: rgba(117, 183, 255, 0.72);
  background: #182231;
  color: var(--teal-dark);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.segmented.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.segmented button.active {
  background: var(--panel);
  color: var(--teal-dark);
  box-shadow: 0 5px 16px rgba(23, 32, 42, 0.09);
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 10px;
}

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

.hidden {
  display: none;
}

.reset-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 850;
}

.reset-button:hover {
  border-color: rgba(117, 183, 255, 0.72);
  color: var(--teal-dark);
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.check-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.viewer-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  min-height: 78px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.viewer-toolbar h2 {
  font-size: clamp(1.35rem, 2.4vw, 2.2rem);
}

.viewer-status {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.scene-note {
  max-width: 430px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.image-stage {
  display: grid;
  gap: 1px;
  background: var(--line);
}

.image-stage.single-mode {
  grid-template-columns: 1fr;
  min-height: min(74vh, 820px);
}

.image-stage.compare-mode {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: auto;
}

.image-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  background: var(--matte);
}

.image-pane header {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 64px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-muted);
}

.compare-mode .image-pane header {
  min-height: 56px;
  padding: 9px 12px;
}

.image-pane p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.compare-mode .image-pane p {
  display: none;
}

.zoom-canvas {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 520px;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    var(--matte);
  background-size: 26px 26px;
  cursor: zoom-in;
  touch-action: pan-y;
}

.compare-mode .zoom-canvas {
  min-height: 0;
  aspect-ratio: var(--stage-aspect, 4 / 3);
}

.zoom-canvas img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
  user-select: none;
  will-change: transform;
}

.analysis-panel {
  gap: 16px;
}

.exr-preview {
  margin: 0;
  border: 1px solid var(--line);
  background: var(--matte);
}

.exr-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: var(--matte);
}

.exr-preview figcaption {
  min-height: 54px;
  padding: 10px 12px;
  background: var(--panel-muted);
  color: var(--muted);
  font-size: 0.82rem;
}

.source-details {
  display: grid;
  gap: 10px;
}

.source-details dl {
  display: grid;
  grid-template-columns: minmax(84px, 0.72fr) minmax(0, 1.28fr);
  gap: 1px;
  margin: 0;
  background: var(--line);
}

.source-details dt,
.source-details dd {
  min-width: 0;
  margin: 0;
  padding: 9px 10px;
  background: var(--panel);
  font-size: 0.82rem;
}

.source-details dt {
  color: var(--muted);
}

.source-details dd {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.histogram {
  display: flex;
  align-items: end;
  gap: 1px;
  height: 128px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel-muted);
}

.histogram span {
  flex: 1;
  min-width: 2px;
  background: var(--teal);
}

.axis-caption {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-align: center;
}

.range-labels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
}

.range-labels span {
  text-align: center;
}

.range-labels span:first-child {
  text-align: left;
}

.range-labels span:last-child {
  text-align: right;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .analysis-panel {
    position: static;
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  }
}

@media (max-width: 860px) {
  .topbar,
  .workspace,
  .image-stage.compare-mode {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .analysis-panel {
    grid-template-columns: 1fr;
  }

  .viewer-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .scene-note {
    max-width: none;
    text-align: left;
  }

  .zoom-canvas {
    min-height: 360px;
  }

  .compare-mode .zoom-canvas {
    min-height: 320px;
  }
}
