:root {
  --bg: #f3f4f6; --panel: #ffffff; --surface: #eceef2; --stage: #e4e6eb; --border: #d9dce3;
  --text: #1a1c20; --muted: #667085; --accent: #2f6bff; --accent-text: #ffffff; --danger: #d92d20;
  --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 10px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1012; --panel: #17181b; --surface: #202227; --stage: #0b0b0d; --border: #2b2d33;
  --text: #e8e9ec; --muted: #8e93a0; --accent: #5b8cff; --accent-text: #0b1020; --danger: #ff6b5e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- knoppen & velden ---------- */
.btn { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; min-height: 34px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 0; width: 34px; justify-content: center; }
.btn:focus-visible, .seg button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=text], input[type=password], input[type=number], select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-height: 34px; width: 100%;
}
input[type=color] { width: 28px; height: 28px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* ---------- topbalk ---------- */
.topbar { position: sticky; top: 0; z-index: 20; height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar .brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.topbar .brand i { width: 18px; height: 18px; border-radius: 50%; background: conic-gradient(#ff6b5e, #ffd25e, #5ed17a, #5b8cff, #b45eff, #ff6b5e); display: inline-block; }
.topbar .spacer { flex: 1; }
.topbar .title { font-weight: 600; max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar input.title { width: 260px; max-width: 40vw; }
.status { font-size: 12px; color: var(--muted); min-width: 70px; text-align: right; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 40px; min-width: 200px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; z-index: 30; }
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; }
.menu-pop button:hover { background: var(--surface); }
.menu-pop hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- inloggen ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 26px; width: 100%; max-width: 360px; }
.card h1 { margin-bottom: 4px; font-size: 22px; }
.err { color: var(--danger); min-height: 20px; margin: 4px 0 8px; font-size: 13px; }

/* ---------- bibliotheek ---------- */
.library { padding: 18px 14px 40px; max-width: 1200px; margin: 0 auto; }
.library h2 { margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.tile:hover { border-color: var(--accent); }
.tile .th { aspect-ratio: 4 / 3; background: var(--surface) center / cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.tile .meta { padding: 8px 10px; display: flex; align-items: center; gap: 8px; }
.tile .meta b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tile .meta small { color: var(--muted); }
.tile .del { margin-left: auto; background: none; border: 0; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.tile .del:hover { color: var(--danger); background: var(--surface); }
.upload { border: 2px dashed var(--border); background: transparent; color: var(--muted); aspect-ratio: auto; min-height: 150px; display: grid; place-items: center; text-align: center; padding: 16px; }
.upload.drag, .upload:hover { border-color: var(--accent); color: var(--text); }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
.stage { position: relative; background: var(--stage); overflow: hidden; touch-action: none; cursor: grab; }
.stage.crop { cursor: move; }
.stage:active { cursor: grabbing; }
.stage canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 6px 30px rgba(0, 0, 0, .25); background: #fff; image-rendering: auto; }
.stage-tools { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; }
.stage-tools .btn { background: var(--panel); box-shadow: var(--shadow); }
.stage-info { position: absolute; right: 10px; bottom: 10px; max-width: 70%; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; font-size: 12px; color: var(--muted); box-shadow: var(--shadow); text-align: right; }
.busy { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 3px 12px; font-size: 12px; color: var(--muted); }
.panel { background: var(--panel); border-left: 1px solid var(--border); overflow-y: auto; padding: 12px 14px 30px; }
.panel section { padding: 12px 0; border-bottom: 1px solid var(--border); }
.panel section:last-child { border-bottom: 0; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.panel h3 button { text-transform: none; letter-spacing: 0; font-size: 12px; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 6px; border-radius: 6px; min-height: 32px; }
.seg button[aria-pressed=true] { background: var(--panel); box-shadow: var(--shadow); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.row .x { flex: 0 0 auto; color: var(--muted); }

/* schuifregelaars */
.sl { margin-bottom: 12px; }
.sl .top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.sl .top output { color: var(--muted); font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--border); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--border); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--accent); margin-top: -8px; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--accent); }

/* legenda */
.legend { display: grid; gap: 4px; }
.leg { display: grid; grid-template-columns: 34px 28px 1fr auto; gap: 8px; align-items: center; padding: 3px 0; }
.leg .sw { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); cursor: pointer; position: relative; overflow: hidden; }
.leg .sw input { position: absolute; inset: -6px; width: 44px; height: 44px; opacity: 0; cursor: pointer; }
.leg .nr { font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.leg small { color: var(--muted); }
.leg code { color: var(--muted); font-size: 12px; }

/* dialoog */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal .card { max-width: 460px; max-height: 90vh; overflow: auto; }
.urow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.urow b { flex: 1; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 20px; z-index: 60; font-size: 13px; }

/* ---------- mobiel ---------- */
@media (max-width: 860px) {
  .editor { display: block; height: auto; }
  .stage { position: sticky; top: 52px; height: 52vh; height: 52dvh; z-index: 5; border-bottom: 1px solid var(--border); }
  .panel { border-left: 0; overflow: visible; padding-bottom: 80px; }
  .topbar input.title, .topbar .title { max-width: 30vw; }
  .status { display: none; }
  .hide-m { display: none !important; }
  .stage-info { bottom: auto; top: 8px; right: 8px; font-size: 11px; max-width: 75%; }
}

/* ---------- afdrukken ---------- */
#printArea { display: none; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block; }
  #printArea img { width: 100%; height: auto; }
  @page { margin: 10mm; }
}

.chk { display: flex; align-items: center; gap: 10px; margin: 12px 0; cursor: pointer; }
.chk input { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent); }

.btn[aria-pressed=true] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.stage canvas#ov { pointer-events: none; box-shadow: none; background: transparent; }
.stage.brush { cursor: crosshair; }
#tools { display: inline-flex; gap: 6px; }
.gutter { display: none; }
@media (max-width: 860px) {
  /* rechterstrook zonder bediening: hier kun je scrollen zonder per ongeluk iets te verstellen */
  .panel { position: relative; padding-right: 56px; }
  .gutter { display: block; position: absolute; top: 0; right: 0; bottom: 0; width: 42px; pointer-events: none;
    background: repeating-linear-gradient(135deg, transparent 0 7px, rgba(128, 135, 150, .18) 7px 8px); border-left: 1px solid var(--border); }
  .gutter span { position: sticky; top: 60vh; display: block; writing-mode: vertical-rl; margin: 0 auto; padding-top: 6px; color: var(--muted); font-size: 11px; letter-spacing: .08em; }
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 12px; }
.chip { min-height: 30px; padding: 4px 11px; }

.presets { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.preset { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 2px 7px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.preset b { font-size: 21px; line-height: 1; }
.preset span { font-size: 10px; color: var(--muted); }
.preset[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.preset[aria-pressed=true] span { color: inherit; }
