:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #6b7385;
  --border: #e1e4ea;
  --accent: #e8590c;
  --stage: #e9ecf1;
  --error: #c92a2a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121419;
    --surface: #1a1d24;
    --text: #e7e9ee;
    --muted: #9aa1b0;
    --border: #2b303b;
    --stage: #0c0e12;
    --error: #ff8787;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Balk bovenaan */
.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.status { color: var(--muted); font-size: 13px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 6px; align-items: center; }

button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  padding: 7px 14px;
  border: 1px solid transparent;
  color: var(--text);
  background: transparent;
  user-select: none;
  -webkit-user-select: none;
}
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #fff; }
button.primary:not(:disabled):hover { filter: brightness(1.08); }
button.ghost { border-color: var(--border); }
button.ghost:not(:disabled):hover, button.ghost.active { background: var(--bg); }
button.icon { font-size: 18px; padding: 4px 8px; color: var(--muted); }
button.icon[aria-expanded="true"] { color: var(--accent); }

.settings {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.settings label { display: flex; flex-direction: column; gap: 6px; max-width: 560px; }
.settings textarea {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; resize: vertical;
}
.settings p { margin: 6px 0 0; }

main { flex: 1; min-height: 0; display: flex; }

/* Lege staat */
.drop {
  flex: 1;
  margin: 24px;
  border: 2px dashed var(--border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px 16px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop strong { font-size: 20px; }
.drop small { margin-top: 12px; }
.drop:hover, .drop:focus-visible, .drop.over { border-color: var(--accent); background: var(--surface); outline: none; }
.drop-key {
  font-size: 13px; font-weight: 700; letter-spacing: .04em;
  padding: 4px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}

/* Beeld */
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--stage); }
.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
  cursor: crosshair;
  touch-action: none;
}
.hint { margin: 0; padding: 0 16px 10px; text-align: center; font-size: 12px; color: var(--muted); }

.busy {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: color-mix(in srgb, var(--stage) 70%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-weight: 600;
}
.busy progress { width: 200px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translate(-50%, 20px);
  background: #1d2433; color: #fff;
  padding: 10px 16px; border-radius: 10px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--error); }

@media (max-width: 720px) {
  .bar { flex-wrap: wrap; }
  .status { order: 3; flex-basis: 100%; }
  .actions { flex-wrap: wrap; }
  #peek, #undo { display: none; }
  .drop { margin: 12px; }
}

.settings label.inline { flex-direction: row; align-items: flex-start; gap: 8px; margin-top: 10px; }
.settings label.inline input { margin-top: 3px; }
.settings a { color: var(--accent); }

.hotkey { margin-top: 10px; max-width: 640px; }
.hotkey summary { cursor: pointer; font-weight: 600; }
.hotkey ol { margin: 8px 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.script-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.script-row code {
  flex: 1; min-width: 0; padding: 6px 8px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  font-size: 12px; word-break: break-all; user-select: all;
}
.small-btn { padding: 4px 10px; font-size: 12px; }

/* Versie-update en veiligheid */
.update {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 5px 10px;
  font-size: 13px;
}
.foot {
  padding: 4px 16px 6px;
  font-size: 11px;
  text-align: center;
  color: var(--muted);
}
.foot .link { font-size: 11px; color: var(--muted); text-decoration: underline; font-weight: 400; }
.dialog {
  max-width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 20px 24px;
  line-height: 1.5;
}
.dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog ul { padding-left: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
