:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #1f2422;
  --muted: #68716c;
  --line: #ded6c9;
  --accent: #d1543f;
  --accent-dark: #963827;
  --olive: #586b44;
  --blue: #2f5f82;
  --shadow: 0 18px 45px rgba(38, 35, 29, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body.is-dragging {
  user-select: none;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
  min-height: 100vh;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff8ed;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.15;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.panel-section {
  display: grid;
  gap: 10px;
}

label,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

textarea {
  width: 100%;
  min-height: 170px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffaf0;
  color: var(--ink);
  line-height: 1.5;
  outline: none;
}

textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 95, 130, 0.18);
}

input[type="file"] {
  width: 100%;
  min-height: 44px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fffaf0;
  color: var(--ink);
}

input[type="file"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 95, 130, 0.18);
}

.microcopy {
  margin: -2px 0 0;
  font-size: 12px;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--ink);
  color: white;
  font-weight: 750;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.07);
}

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

button.secondary {
  background: #e8e0d2;
  color: var(--ink);
}

.button-row,
.button-grid {
  display: grid;
  gap: 8px;
}

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

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

.current-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf6ec;
}

#currentLabel {
  font-size: 18px;
  line-height: 1.25;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e1d8ca;
}

#progressFill {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--olive), var(--accent));
  transition: width 180ms ease;
}

.placed-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.placed-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.placed-list li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--muted);
}

.placed-list .index {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e6ddd0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.placed-list .done {
  color: var(--olive);
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  padding: 22px;
}

.stage-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

#modeBadge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--olive);
  color: white;
  font-weight: 800;
}

.stage {
  position: relative;
  justify-self: center;
  align-self: start;
  width: min(100%, 1040px);
  max-height: calc(100vh - 92px);
  aspect-ratio: 1 / 1.34;
  overflow: hidden;
  border-radius: 8px;
  background: #e9e1d7;
  box-shadow: var(--shadow);
  cursor: crosshair;
}

.stage[data-step="label"] {
  cursor: cell;
}

.image-frame {
  position: absolute;
  left: 50%;
  top: 4.5%;
  height: 91%;
  max-height: 1360px;
  aspect-ratio: 940 / 1672;
  transform: translateX(-50%);
  background: #fff;
  box-shadow: 0 14px 42px rgba(38, 35, 29, 0.12);
}

.stage img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.overlay-svg,
.label-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.callout-line {
  stroke: rgba(31, 36, 34, 0.82);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 7 7;
  animation: dash 1.4s linear infinite;
}

.callout-dot-ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 1.4s ease-out infinite;
}

.callout-dot {
  fill: var(--accent);
  stroke: white;
  stroke-width: 2;
}

.target-handle {
  position: absolute;
  width: 28px;
  height: 28px;
  min-height: 0;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(209, 84, 63, 0.16), 0 8px 18px rgba(31, 36, 34, 0.22);
  cursor: grab;
  pointer-events: auto;
}

.target-handle:hover,
.target-handle.current {
  box-shadow: 0 0 0 7px rgba(209, 84, 63, 0.22), 0 8px 18px rgba(31, 36, 34, 0.22);
}

.is-dragging .target-handle,
.is-dragging .label-chip {
  cursor: grabbing;
}

.label-chip {
  position: absolute;
  max-width: min(270px, 28%);
  min-width: 118px;
  transform: translate(-50%, -50%);
  padding: 9px 11px;
  border: 1px solid rgba(31, 36, 34, 0.18);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 10px 22px rgba(31, 36, 34, 0.18);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.18;
  overflow-wrap: anywhere;
  animation: labelIn 260ms ease both;
  cursor: grab;
  pointer-events: auto;
  user-select: none;
}

.label-chip.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(209, 84, 63, 0.2), 0 10px 22px rgba(31, 36, 34, 0.18);
}

.label-chip::before {
  content: attr(data-number);
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  font-size: 11px;
}

.empty-state {
  position: absolute;
  inset: auto 24px 24px 24px;
  display: grid;
  gap: 3px;
  padding: 13px 14px;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 10px 24px rgba(31, 36, 34, 0.14);
  pointer-events: none;
}

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

@keyframes dash {
  to {
    stroke-dashoffset: -28;
  }
}

@keyframes pulse {
  0% {
    r: 7;
    opacity: 0.95;
  }
  100% {
    r: 20;
    opacity: 0;
  }
}

@keyframes labelIn {
  from {
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 14px;
  }

  .stage {
    max-height: none;
    aspect-ratio: 1 / 1.55;
  }

  .image-frame {
    height: 87%;
  }
}
