:root {
  color-scheme: light dark;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --stage: #e9e9e6;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --line: #dcdcd7;
  --accent: #2f5fe0;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --error: #c0392b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161617;
    --surface: #1f1f21;
    --stage: #0f0f10;
    --text: #ececea;
    --muted: #9a9a95;
    --line: #313134;
    --accent: #6f93ff;
    --accent-text: #0d1020;
    --ok: #4cc27f;
    --warn: #e0a040;
    --error: #ff7a6b;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: 0.01em; }
h2 { margin: 0; font-size: 12px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}
.status[data-state="starting"]::before { animation: pulse 1.2s ease-in-out infinite; }
.status[data-state="ready"]::before { background: var(--ok); }
.status[data-state="error"] { color: var(--error); }
.status[data-state="error"]::before { background: var(--error); }

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

.stage {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--stage);
  overflow: hidden;
}
.stage.dragover { outline: 2px dashed var(--accent); outline-offset: -10px; }

#canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 92px);
  width: auto;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.25);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}
#canvas[hidden] { display: none; }

.badge {
  position: absolute;
  top: 32px;
  left: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.empty { text-align: center; color: var(--muted); max-width: 420px; }
.empty-title { margin: 0 0 6px; font-size: 18px; color: var(--text); }
.empty-note { margin: 0; }

.busy {
  position: absolute;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
}
.busy[hidden], .badge[hidden] { display: none; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.panel {
  overflow-y: auto;
  padding: 18px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.group { display: flex; flex-direction: column; gap: 10px; }
.group[hidden] { display: none; }
.row { display: flex; align-items: baseline; justify-content: space-between; }
.hint { margin: 0; font-size: 12.5px; color: var(--muted); }

output { font-variant-numeric: tabular-nums; font-weight: 600; }

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.button:hover:not(:disabled) { border-color: var(--accent); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.small { align-self: flex-start; padding: 6px 10px; font-size: 13px; }
.button:disabled { opacity: 0.45; cursor: default; }
.button:focus-visible, .switch button:focus-visible, .sample:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.select { position: relative; }
.select select {
  width: 100%;
  padding: 9px 36px 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.select::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.select select:hover:not(:disabled) { border-color: var(--accent); }
.select select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.select select:disabled { opacity: 0.45; cursor: default; }

.switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--stage);
  border: 1px solid var(--line);
}
.switch button {
  padding: 7px 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.switch button:disabled { opacity: 0.45; cursor: default; }

.samples { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.sample {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--stage);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 3 / 4;
}
.sample img { display: block; width: 100%; height: 100%; object-fit: cover; }
.sample[aria-pressed="true"] { border-color: var(--accent); }

.message {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: 13.5px;
}
.message[data-kind="error"] { border-color: var(--error); color: var(--error); }
.message[data-kind="note"] { border-color: var(--warn); }
.message ul { margin: 6px 0 0; padding-left: 18px; }

.details { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; font-variant-numeric: tabular-nums; }

.notes { font-size: 13px; color: var(--muted); }
.notes summary { cursor: pointer; }
.notes ul { margin: 6px 0 0; padding-left: 18px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.3; } }

@media (max-width: 760px) {
  body { height: auto; }
  .layout { grid-template-columns: 1fr; }
  .stage { min-height: 46vh; padding: 12px; }
  #canvas { max-height: 62vh; }
  .badge { top: 20px; left: 20px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner, .status::before { animation: none; }
}
