:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --ink: #1d2a2c;
  --muted: #647275;
  --line: #d8e1de;
  --accent: #0f7f6e;
  --accent-strong: #0a5f55;
  --accent-soft: #d8f3eb;
  --danger: #b64235;
  --shadow: 0 24px 70px rgba(21, 37, 39, 0.13);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(244, 247, 246, 0.96)),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

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

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  display: block;
  height: 42px;
  max-width: 240px;
  object-fit: contain;
}

.brand-copy {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.brand-copy strong {
  font-size: 18px;
  letter-spacing: 0;
}

.brand-copy span {
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.runtime-pill,
.ghost-button,
.primary-button,
.tool-button,
.mini-button,
.segment,
.upload-control {
  min-height: 38px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.runtime-pill {
  min-width: 76px;
  padding: 0 12px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 13px;
  font-weight: 700;
}

.ghost-button,
.tool-button,
.mini-button,
.segment {
  color: var(--ink);
  background: #e7eeee;
  cursor: pointer;
}

.ghost-button,
.tool-button {
  padding: 0 14px;
}

.primary-button {
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.ghost-button:hover:not(:disabled),
.tool-button:hover:not(:disabled),
.mini-button:hover:not(:disabled),
.segment:hover {
  background: #dbe6e4;
}

button:disabled,
.upload-control:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.52;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
}

.stage-area {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: clamp(18px, 2.4vw, 32px);
  gap: 14px;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: 8px;
  background: #e3ebea;
}

.segment {
  min-width: 70px;
  min-height: 34px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

.segment.active {
  color: var(--ink);
  background: var(--surface-strong);
  box-shadow: 0 1px 4px rgba(29, 42, 44, 0.08);
}

.swatch-label {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #e7eeee;
  padding: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.swatch-label input {
  width: 28px;
  height: 28px;
  border: 0;
  padding: 0;
  background: transparent;
}

.stage {
  min-width: 0;
  min-height: 420px;
  display: grid;
}

.canvas-frame {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: #f6faf9;
}

.canvas-frame.drag-over {
  border-color: var(--accent);
  box-shadow: 0 24px 80px rgba(15, 127, 110, 0.22);
}

.canvas-frame.checker {
  background-color: #f6faf9;
  background-image:
    linear-gradient(45deg, #d5dfdc 25%, transparent 25%),
    linear-gradient(-45deg, #d5dfdc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d5dfdc 75%),
    linear-gradient(-45deg, transparent 75%, #d5dfdc 75%);
  background-size: 28px 28px;
  background-position:
    0 0,
    0 14px,
    14px -14px,
    -14px 0;
}

.canvas-frame.white {
  background: #fff;
}

.canvas-frame.charcoal {
  background: #1e2424;
}

.canvas-frame.color {
  background: var(--preview-color, #62c9aa);
}

#previewCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 22px;
}

.empty-icon {
  width: 76px;
  height: 54px;
  border: 2px solid #b7b0a4;
  border-radius: 8px;
  position: relative;
  background:
    linear-gradient(135deg, transparent 45%, rgba(15, 127, 110, 0.24) 46% 58%, transparent 59%),
    #ffffff;
}

.empty-icon::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 10px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e0b84d;
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(29, 42, 44, 0.42);
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.control-panel {
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  padding: clamp(18px, 2vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.upload-control {
  min-height: 48px;
  width: 100%;
  border: 1px dashed #a8a195;
  color: var(--ink);
  background: #f2f7f6;
  font-weight: 800;
  cursor: pointer;
}

.upload-control input {
  width: 1px;
  height: 1px;
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.wide {
  width: 100%;
  min-height: 48px;
}

.status-panel,
.control-group,
.meta-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.status-panel {
  padding: 14px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-row span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  height: 8px;
  margin-top: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #e2eae7;
}

.progress-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

.control-group {
  padding: 16px;
  display: grid;
  gap: 15px;
}

.control-heading {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 850;
}

.mini-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.range-row,
.select-row,
.toggle-row {
  display: grid;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.range-row {
  grid-template-columns: 66px minmax(0, 1fr) 30px;
}

.range-row input {
  width: 100%;
  accent-color: var(--accent);
}

.range-row output {
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.select-row {
  grid-template-columns: 74px minmax(0, 1fr);
}

.select-row select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #ffffff;
  padding: 0 10px;
}

.toggle-row {
  grid-template-columns: 18px minmax(0, 1fr);
}

.toggle-row input {
  accent-color: var(--accent);
}

.meta-panel {
  padding: 14px;
}

.meta-panel dl {
  margin: 0;
  display: grid;
  gap: 12px;
}

.meta-panel dl > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.meta-panel dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-panel dd {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }

  .stage {
    min-height: 54vh;
  }
}

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

  .topbar-actions,
  .stage-toolbar {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .segmented {
    width: 100%;
  }

  .segment {
    flex: 1;
    min-width: 0;
    padding: 0 6px;
  }

  .stage-area {
    padding: 14px;
  }

  .control-panel {
    padding: 14px;
  }
}
