:root {
  --stage-max: 82vmin;
  --spot-size: 34px;
  --gap: 12px;
  --card-bg: #ffffff;
  --ui-bg: #f7f7f9;
  --ink: #111827;
  --ink-2: #4b5563;
  --brand: #2563eb;
  --brand-2: #1d4ed8;
  --ok: #16a34a;
  --warn: #b45309;
  --danger: #dc2626;
  --ring: 2px solid rgba(37,99,235,0.35);
  --shadow: 0 10px 20px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.06);
}

html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--ink);
  background: linear-gradient(180deg, #f3f4f6, #e5e7eb);
}

.app {
  display: grid;
  grid-template-columns: 1fr min(380px, 32vw);
  gap: var(--gap);
  padding: clamp(12px, 3vmin, 24px);
  max-width: 1400px;
  margin: 0 auto;
}

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

.stage-wrap { display: grid; place-items: center; }

.stage {
  width: min(var(--stage-max), 100%);
  aspect-ratio: 1 / 1;
  position: relative;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  outline: 1px dashed #d1d5db;
  outline-offset: -6px;
  user-select: none;
  touch-action: manipulation;
}

.stage[data-has-image="false"]::before {
  content: "Drop an image here or use the picker";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #6b7280; font-size: clamp(12px, 2.4vmin, 14px);
  pointer-events: none;
}

.stage-img {
  position: absolute; inset: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  transition: opacity .2s ease;
  opacity: .999;
}

.hotspots { position: absolute; inset: 0; pointer-events: none; }

.spot {
  position: absolute;
  width: var(--spot-size);
  height: var(--spot-size);
  margin-left: calc(var(--spot-size) / -2);
  margin-top: calc(var(--spot-size) / -2);
  border-radius: 999px;
  border: 2px solid #fff;
  background: radial-gradient(circle at 30% 30%, #fff, #e5e7eb);
  box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 10px rgba(0,0,0,.08);
  display: grid; place-items: center;
  font-weight: 700; color: #111827;
  pointer-events: auto;
  cursor: pointer;
  transition: transform .06s ease;
}
.spot:hover { transform: translateZ(0) scale(1.06); }
.spot:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,0.5); }
.spot[data-unassigned="true"] { outline: 3px dashed #f59e0b; outline-offset: 2px; }

.toolbar, .panel {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.btn {
  appearance: none; border: none; border-radius: 10px;
  padding: 10px 12px; font-weight: 600; cursor: pointer;
  background: var(--brand); color: #fff;
}
.btn:hover { background: var(--brand-2); }
.btn.fake { background: #fff; border: 1px solid #c7d2fe; color: #1d4ed8; }
.btn.ghost { background: #eef2ff; color: #1e3a8a; }
.btn.ghost:hover { background: #e0e7ff; }
.btn.warn { background: #f59e0b; }
.btn.danger { background: var(--danger); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.file { display: inline-flex; align-items: center; gap: 8px; }
.file input[type=file] { display: none; }

.mode {
  margin-left: auto; display: inline-flex; gap: 8px;
  background: #eef2ff; border-radius: 12px; padding: 4px;
}
.mode .seg {
  padding: 8px 12px; border-radius: 8px; font-weight: 700; cursor: pointer; color: #1e3a8a;
}
.mode .seg.active { background: #fff; color: #111827; box-shadow: inset 0 0 0 2px #dbeafe; }

.sidebar { display: grid; gap: var(--gap); }
.panel h3 { margin: 0 0 8px 0; font-size: 16px; }
.panel small { color: var(--ink-2); }
.row { display: grid; gap: 8px; margin-top: 10px; }

.audio-list { display: grid; gap: 8px; }
.audio-item { background: var(--ui-bg); border-radius: 10px; padding: 8px; display: grid; gap: 6px; }
.audio-item label { font-weight: 600; font-size: 13px; }

.spot-list { display: grid; gap: 8px; }
.spot-item { background: var(--ui-bg); border-radius: 10px; padding: 10px; display: grid; gap: 6px; }
.spot-item .meta { color: var(--ink-2); font-size: 12px; }
select, input[type=text] {
  border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px; font: inherit; background: #fff;
}

.hint { color: var(--ink-2); font-size: 12px; }
.k { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; }

.drop-hint { color: var(--ink-2); font-size: 12px; text-align: center; margin-top: 6px; }

/* --- Focus heartbeat animation --- */
@keyframes heartbeat {
  0%   { transform: scale(1); box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 10px rgba(0,0,0,.08); }
  20%  { transform: scale(1.18); box-shadow: 0 0 0 4px rgba(37,99,235,0.25), 0 8px 16px rgba(0,0,0,.12); }
  40%  { transform: scale(1);   box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 10px rgba(0,0,0,.08); }
  60%  { transform: scale(1.12); box-shadow: 0 0 0 4px rgba(37,99,235,0.25), 0 8px 16px rgba(0,0,0,.12); }
  80%  { transform: scale(1);   box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 10px rgba(0,0,0,.08); }
  100% { transform: scale(1);   box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 10px rgba(0,0,0,.08); }
}
.spot.heartbeat {
  animation: heartbeat 1.1s ease-in-out 1;
}
