:root {
  color-scheme: light;
  --bg: #eef1f3;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #172026;
  --muted: #62707a;
  --line: #d7dde2;
  --accent: #007f8f;
  --accent-soft: #e6fbfd;
  --accent-2: #d9572b;
  --good: #18845f;
  --shadow: 0 14px 35px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 8%, rgba(0, 127, 143, 0.14), transparent 28%),
    radial-gradient(circle at 86% 18%, rgba(217, 87, 43, 0.11), transparent 28%),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

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

button.secondary,
.button-grid button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.stepbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
  background: #111827;
  color: white;
}

.stepbar span {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-right: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stepbar b {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: white;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
}

.status {
  max-width: 42vw;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(460px, 1fr) minmax(240px, 280px);
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.panel,
.workspace {
  min-height: 0;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  overflow: auto;
  padding: 14px;
}

.tool-section + .tool-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

input[type="search"],
input[type="text"] {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
}

.results,
.stencil-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.compact-list {
  max-height: 210px;
  overflow: auto;
}

.model-list {
  max-height: 260px;
  overflow: auto;
}

.result-item,
.stencil-item {
  width: 100%;
  min-height: 52px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  text-align: left;
  color: var(--text);
  display: grid;
  gap: 3px;
}

.compact-list .result-item {
  min-height: 42px;
  padding: 7px 9px;
}

.result-item:hover,
.stencil-item:hover,
.result-item.active,
.stencil-item.active {
  border-color: var(--accent);
  background: #eefafb;
}

.result-item strong,
.stencil-item strong {
  font-size: 13px;
}

.result-item span,
.stencil-item span {
  color: var(--muted);
  font-size: 12px;
}

.section-head,
.workspace-head,
.export-row,
.button-grid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.workspace-head {
  min-height: 58px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.workspace-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.export-row button {
  min-width: 54px;
  padding: 0 10px;
  background: var(--text);
}

.stage-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: 14px 28px 28px;
  background: linear-gradient(180deg, #f7fafc, #e9eef2);
}

.stage {
  width: min(38vh, 58%);
  max-width: 365px;
  min-width: 280px;
  aspect-ratio: 2 / 3;
  position: relative;
  background: white;
  border: 1px solid #c7d0d6;
  border-radius: 4px;
  box-shadow: 0 12px 28px rgba(23, 32, 38, 0.14);
  overflow: hidden;
}

.stage svg {
  width: 100%;
  height: 100%;
  display: block;
  background: white;
  touch-action: none;
  user-select: none;
}

.text-handle {
  fill: rgba(0, 127, 143, 0.18);
  stroke: var(--accent);
  stroke-width: 14;
  vector-effect: non-scaling-stroke;
  cursor: move;
}

.design-image,
.draggable-design {
  cursor: move;
}

.design-frame {
  fill: none;
  stroke: var(--accent);
  stroke-width: 22;
  stroke-dasharray: 70 45;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.resize-handle {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 20;
  vector-effect: non-scaling-stroke;
  cursor: nwse-resize;
}

.resize-handle[data-handle="ne"],
.resize-handle[data-handle="sw"] {
  cursor: nesw-resize;
}

.resize-handle:hover {
  fill: #e9fbfd;
  stroke: var(--accent-2);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.file-pick {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px dashed var(--accent);
  border-radius: 7px;
  background: #eefafb;
  color: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.text-tools,
.background-tools {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.text-tools {
  grid-template-columns: 1fr 88px;
}

.text-tools input[type="text"],
.text-tools select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.text-tools select,
.text-tools .mini-field,
.text-tools .size-field {
  grid-column: 1 / -1;
}

.mini-field {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-field input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.swatches button {
  min-height: 34px;
  border: 1px solid var(--line);
  background: var(--swatch);
}

.file-pick input {
  display: none;
}

.controls {
  display: grid;
  gap: 12px;
}

.controls label {
  display: grid;
  gap: 5px;
}

.controls span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 1040px) {
  .layout {
    grid-template-columns: 300px 1fr;
  }

  .controls-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(220px, 280px) 1fr minmax(180px, 220px);
    gap: 14px;
  }

  .controls-panel .tool-section {
    margin: 0;
    padding: 0;
    border: 0;
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
  }

  .status {
    max-width: 46vw;
  }

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

  .stepbar span {
    min-height: 38px;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .controls-panel {
    display: block;
  }

  .controls-panel .tool-section + .tool-section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
  }

  .stage {
    width: min(86%, 360px);
    min-width: 0;
  }
}
