:root {
  --bg-stage: #111113;
  --bg-chrome: #18181b;
  --bg-surface: #202024;
  --bg-input: #101012;
  --border: #2b2b31;
  --border-strong: #3c3c44;
  --text-primary: #f4f4f2;
  --text-secondary: #a4a4ad;
  --text-muted: #71717a;
  --accent: #e07a2f;
  --accent-hover: #c96922;
  --accent-ink: #120b05;
  --accent-soft: rgba(224, 122, 47, 0.14);
  --success: #34b36d;
  --warning: #e5a024;
  --danger: #e05252;
  --radius-sm: 5px;
  --radius-md: 8px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-stage);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.flex-grow {
  flex: 1;
}

.full-width {
  width: 100%;
}

/* Application Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.subtitle {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

/* Studio Split Layout */
.studio {
  display: grid;
  grid-template-columns: 348px 1fr;
  flex: 1;
  min-height: 0;
}

/* Left Inspector Rail */
.inspector {
  background: var(--bg-chrome);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inspector-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.inspector-scroll::-webkit-scrollbar {
  width: 6px;
}

.inspector-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.inspector-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.inspector-section:last-child {
  border-bottom: none;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-head h2 {
  margin: 0;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.meta-tag {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--text-muted);
}

.control-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Fields & Inputs */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.field-hint {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
}

.field-hint.hint-warn {
  color: var(--warning);
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mono-val {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-primary);
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-family: inherit;
  font-size: 12.5px;
  transition: border-color 0.15s;
}

input[type="number"]:hover,
input[type="text"]:hover,
select:hover {
  border-color: var(--border-strong);
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="number"] {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

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

.dim-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.dim-row .field {
  flex: 1;
  min-width: 0;
}

.field-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.target-input-group {
  display: flex;
  gap: 8px;
}

.unit-field {
  width: 80px;
  flex-shrink: 0;
}

.color-picker-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  height: 33px;
}

.color-picker-wrap input[type="color"] {
  border: none;
  background: transparent;
  width: 22px;
  height: 22px;
  padding: 0;
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox-row input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  margin-top: 2px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Segmented Controls */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.segmented.compact {
  grid-auto-columns: auto;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.seg-btn:hover {
  color: var(--text-primary);
}

.seg-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

/* Chips */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 4px 9px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 9px 14px;
  font-size: 13px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

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

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: #29292f;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  text-decoration: underline;
}

.icon-toggle {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.icon-toggle.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.transform-toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.tool-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 4px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tool-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface);
}

/* Export Dock */
.export-dock {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-chrome);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.download-row {
  display: flex;
  gap: 6px;
}

/* Right Workspace */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-stage);
}

/* Telemetry Bar */
.telemetry-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.telemetry-metrics {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.metric {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.metric-val {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.metric-val.saved-good {
  color: var(--success);
}

.metric-val.saved-warn {
  color: var(--warning);
}

.metric-sep {
  color: var(--text-muted);
}

.metric-divider {
  width: 1px;
  height: 14px;
  background: var(--border);
}

.view-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.view-controls select {
  width: auto;
  padding: 5px 8px;
  font-size: 12px;
}

/* Stage (margin: auto on child prevents overflow clipping when zoomed) */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: auto;
  padding: 24px;
}

.stage.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -12px;
  background-color: rgba(224, 122, 47, 0.05);
}

.dropzone {
  margin: auto;
  width: 100%;
  max-width: 520px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-chrome);
  padding: 40px 28px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: #1c1c20;
}

.drop-icon {
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.dropzone h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.dropzone p {
  margin: 0 0 18px;
  color: var(--text-secondary);
  font-size: 12.5px;
}

.dropzone code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.drop-specs {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Preview Comparison */
.preview-viewport {
  margin: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.compare-container {
  position: relative;
  display: inline-block;
  border: 1px solid var(--border-strong);
  overflow: hidden;
  user-select: none;
  background-color: #161619;
  background-image:
    linear-gradient(45deg, #1d1d22 25%, transparent 25%),
    linear-gradient(-45deg, #1d1d22 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1d1d22 75%),
    linear-gradient(-45deg, transparent 75%, #1d1d22 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.preview-canvas {
  display: block;
}

.after-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.split-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 26px;
  transform: translateX(-50%);
  cursor: ew-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.split-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
}

.split-knob {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-chrome);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--text-primary);
}

.corner-tag {
  position: absolute;
  top: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(17, 17, 19, 0.82);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  pointer-events: none;
  z-index: 8;
}

.tag-left {
  left: 10px;
}

.tag-right {
  right: 10px;
}

/* Crop Overlay */
.crop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 15;
}

.crop-box {
  position: absolute;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  cursor: move;
}

.crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--text-primary);
  border: 1.5px solid var(--accent);
}

.crop-handle.nw { top: -5px; left: -5px; cursor: nwse-resize; }
.crop-handle.ne { top: -5px; right: -5px; cursor: nesw-resize; }
.crop-handle.sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.crop-handle.se { bottom: -5px; right: -5px; cursor: nwse-resize; }

.crop-dims-label {
  position: absolute;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  border: 1px solid var(--border-strong);
}

/* Processing Pill & Notice Bar */
.loading-overlay {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-chrome);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  z-index: 30;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.status-banner {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  border-top: 1px solid var(--border);
  background: #231d12;
  color: #f3c46b;
}

.status-banner.info {
  background: #191d24;
  color: #b7c8e0;
}

.status-banner.success {
  background: #13221a;
  color: #84dfa9;
}

/* Batch Queue Strip */
.batch-strip {
  background: var(--bg-chrome);
  border-top: 1px solid var(--border);
  padding: 8px 16px 10px;
  flex-shrink: 0;
}

.batch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.batch-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.batch-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  min-width: 190px;
  max-width: 240px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s;
}

.batch-item:hover {
  border-color: var(--border-strong);
}

.batch-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.batch-thumb {
  width: 34px;
  height: 34px;
  border-radius: 3px;
  object-fit: cover;
  background: var(--bg-stage);
  flex-shrink: 0;
}

.batch-meta {
  min-width: 0;
  flex: 1;
}

.batch-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.batch-size {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.batch-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
}

.batch-remove:hover {
  color: var(--danger);
}

/* Tablet & Laptop Breakpoint */
@media (max-width: 960px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

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

  .inspector {
    order: 2;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  .inspector-scroll {
    overflow: visible;
  }

  .workspace {
    order: 1;
  }

  .stage {
    min-height: 360px;
    max-height: 62vh;
  }
}

/* Mobile Breakpoint */
@media (max-width: 560px) {
  .topbar {
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .status-pill {
    display: none;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .telemetry-bar {
    padding: 8px 12px;
  }

  .metric-divider {
    display: none;
  }

  .view-controls {
    width: 100%;
    justify-content: space-between;
  }

  .stage {
    padding: 12px;
    min-height: 280px;
  }

  .dropzone {
    padding: 28px 16px;
  }

  .field-row-2 {
    grid-template-columns: 1fr;
  }
}
