:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --ink: #18211f;
  --muted: #60706b;
  --line: #d8ded9;
  --teal: #1b6f69;
  --teal-2: #e3f4f1;
  --amber: #b77818;
  --rose: #a8485d;
  --canvas: #090d0f;
  --canvas-line: rgba(255, 255, 255, 0.16);
  --shadow: 0 18px 40px rgba(27, 41, 36, 0.12);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.topbar {
  min-height: 76px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 260px;
}

.brand-mark {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  display: block;
  object-fit: cover;
}

.brand h1,
.pane-header h2 {
  margin: 0;
  font-size: clamp(18px, 2vw, 24px);
  line-height: 1.1;
}

.brand p,
.pane-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.empty-state button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 10px 22px rgba(27, 111, 105, 0.2);
}

.empty-state button svg,
.segmented svg,
.preset-grid svg,
.slice-controls svg,
.toggle svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 292px) 1fr;
  overflow: hidden;
}

.control-rail {
  min-height: 0;
  padding: 18px;
  background: #fbfcfb;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
}

.control-group {
  display: grid;
  gap: 10px;
}

.control-title {
  color: #3d4d49;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.segmented,
.preset-grid {
  display: grid;
  gap: 6px;
}

.segmented {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 4px;
  border-radius: 8px;
  background: var(--surface-2);
}

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

.segmented button,
.preset-grid button,
.toggle,
.slice-controls button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 7px;
  color: #30403c;
  background: transparent;
}

.segmented button.active,
.preset-grid button:hover,
.toggle.active,
.slice-controls button:hover {
  background: #fff;
  color: var(--teal);
  box-shadow: 0 1px 0 rgba(17, 63, 59, 0.08), 0 8px 18px rgba(20, 50, 45, 0.08);
}

.muted {
  opacity: 0.56;
}

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

.preset-grid button {
  background: #f8f9f7;
  border: 1px solid var(--line);
}

.range-field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.range-field span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.range-field strong {
  color: var(--ink);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

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

.switch-row {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #384844;
  font-size: 14px;
}

.toggle {
  width: 42px;
  border: 1px solid var(--line);
  background: #f9faf8;
}

.workspace {
  min-width: 0;
  min-height: 0;
  padding: 9px;
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  grid-template-rows: minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}

.viewer-pane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pane-header {
  min-width: 0;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.pane-kicker {
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.pane-header h2,
.pane-header p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pane-header h2 {
  font-size: 18px;
}

.canvas-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    var(--canvas);
  background-size: 32px 32px;
}

.canvas-stage.dragging {
  outline: 3px solid rgba(27, 111, 105, 0.55);
  outline-offset: -8px;
}

.canvas-stage canvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.canvas-stage::before,
.canvas-stage::after {
  content: "";
  position: absolute;
  pointer-events: none;
  background: var(--canvas-line);
  opacity: 0;
}

.has-volume .canvas-stage::before,
.has-volume .canvas-stage::after {
  opacity: 1;
}

.canvas-stage::before {
  width: 1px;
  top: 0;
  bottom: 0;
  left: 50%;
}

.canvas-stage::after {
  height: 1px;
  left: 0;
  right: 0;
  top: 50%;
}

.empty-state,
.loading-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: #d8e3df;
  text-align: center;
  background: rgba(7, 11, 13, 0.68);
}

.empty-state button {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 8px;
}

.empty-state span,
.loading-state strong {
  max-width: 220px;
  font-size: 14px;
  line-height: 1.35;
}

.loader-ring {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #87d8cf;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.progress-track {
  width: min(260px, 68%);
  height: 7px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.17);
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #87d8cf;
  transition: width 140ms ease;
}

.canvas-overlay {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: none;
}

.canvas-overlay span {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border-radius: 6px;
  color: #e9f2ef;
  background: rgba(9, 13, 15, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  line-height: 1.2;
}

.slice-controls {
  min-width: 0;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--line);
}

.slice-controls button {
  border: 1px solid var(--line);
  background: #f8faf8;
}

.metrics {
  min-height: 43px;
  padding: 0 14px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.metrics span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  color: #4c5d58;
  background: #f2f5f2;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.metrics .metric-error {
  color: #7e2638;
  background: #fae9ee;
}

.file-input,
.hidden {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

  .control-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    align-items: start;
  }

}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .control-rail {
    grid-template-columns: 1fr;
    max-height: 34dvh;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, minmax(0, 1fr));
    padding: 6px;
  }

  .pane-header {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .brand {
    align-items: flex-start;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    display: none;
  }

  .workspace,
  .control-rail,
  .topbar {
    padding-left: 10px;
    padding-right: 10px;
  }
  .segmented button span,
  .preset-grid button span {
    font-size: 12px;
  }
}
