:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --primary: #0f3460;
  --accent: #e94560;
  --text: #eee;
  --text-muted: #aaa;
  --radius: 12px;
}

[hidden] { display: none !important; }

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--surface);
}
header h1 { font-size: 1.2rem; }
#version { color: var(--text-muted); font-size: .8rem; flex: 1; }
header button { padding: 6px 12px; font-size: .9rem; white-space: nowrap; }

main { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); max-width: 900px; margin: 0 auto; }

button {
  font: inherit; color: var(--text); border: 0; cursor: pointer;
  border-radius: var(--radius); padding: 12px 16px;
  background: var(--primary);
}
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border: 1px solid #ffffff33; }
button.big { font-size: 1.2rem; padding: 20px 28px; background: var(--accent); font-weight: 600; }

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }

.empty {
  min-height: calc(100dvh - 90px); cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; text-align: center;
}

#stage {
  position: relative; margin: 0 auto; width: fit-content; max-width: 100%;
  touch-action: none; user-select: none; -webkit-user-select: none;
  border-radius: 8px; overflow: hidden; background: #000;
}
#photo { display: block; max-width: 100%; max-height: 65dvh; } /* max-height wordt door fitPhoto() overschreven */
#sig {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -50%);
  cursor: grab; outline: 1px dashed #ffffffaa; outline-offset: 4px;
  touch-action: none;
}
#sig.dragging { cursor: grabbing; }
#stage.export #sig { outline: none; }

#sig-controls {
  display: grid; gap: 6px; margin-top: 10px;
}
#sig-controls label, .thick {
  display: flex; align-items: center; gap: 12px; font-size: .9rem;
}
input[type=range] { flex: 1; accent-color: var(--accent); }

.actions {
  display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap;
}
.actions button { flex: 1; min-width: 0; }
#editor .actions button { padding: 10px 8px; white-space: nowrap; }

dialog {
  margin: auto; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 16px; width: min(600px, calc(100vw - 24px));
}
dialog::backdrop { background: #000a; }
.pad-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.colors { display: flex; gap: 8px; }
.colors button {
  width: 30px; height: 30px; padding: 0; border-radius: 50%;
  background: var(--c); border: 2px solid #ffffff44;
}
.colors button.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

#pad {
  display: block; width: 100%; height: 220px; touch-action: none;
  border-radius: 8px;
  background-color: #f4f4f4;
  background-image: linear-gradient(#0000 calc(75% - 1px), #0003 calc(75% - 1px), #0003 75%, #0000 75%);
}
#pad.dark { background-color: #555; }
.thick { margin-top: 10px; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #000d; padding: 10px 18px; border-radius: 999px; font-size: .9rem;
}

/* Bibliotheek */
.lib-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; max-height: 50dvh; overflow-y: auto;
}
.lib-item { position: relative; }
.lib-pick {
  width: 100%; height: 90px; padding: 8px; display: flex;
  align-items: center; justify-content: center;
  background: #f4f4f4; border: 2px solid transparent;
}
.lib-item.sel .lib-pick { border-color: var(--accent); }
.lib-pick img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lib-del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px;
  padding: 0; border-radius: 50%; font-size: .8rem; background: #000a;
}

/* Datumkeuze */
select {
  flex: 1; font: inherit; color: var(--text); background: var(--primary);
  border: 0; border-radius: 8px; padding: 8px 10px;
}
.lib-pick { position: relative; }
.lib-badge {
  position: absolute; left: 6px; bottom: 4px; font-size: .7rem;
  background: #000b; color: #fff; padding: 2px 6px; border-radius: 999px;
}

/* Handschriftlettertypen (zelf gehost) */
@font-face { font-family: 'Great Vibes'; src: url('/fonts/great-vibes.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Dancing Script'; src: url('/fonts/dancing-script.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Allura'; src: url('/fonts/allura.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Caveat'; src: url('/fonts/caveat.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Sacramento'; src: url('/fonts/sacramento.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Homemade Apple'; src: url('/fonts/homemade-apple.woff2') format('woff2'); font-display: swap; }

/* Typ-dialoog */
.text-input {
  width: 100%; font: inherit; font-size: 1.1rem; padding: 12px 14px;
  border-radius: 8px; border: 1px solid #ffffff33; background: var(--bg); color: var(--text);
}
.font-list {
  display: grid; gap: 8px; margin-top: 12px; max-height: 45dvh; overflow-y: auto;
}
.font-opt {
  background: #f4f4f4; font-size: 2rem; line-height: 1.3; padding: 10px 16px;
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border: 2px solid transparent;
}
.font-opt.dark { background: #555; }
.font-opt.sel { border-color: var(--accent); }
