:root {
  --green-900: #0e2a1c;
  --green-800: #16402a;
  --green-700: #1f5132;
  --green-500: #2f7a4d;
  --gold: #c9a227;
  --gold-soft: #e7cf7a;
  --bg: #0b100d;
  --panel: #141b17;
  --panel-2: #1c2520;
  --line: #2a3530;
  --text: #eef3ef;
  --muted: #9aaba1;
  --danger: #e5484d;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .35; cursor: default; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.svg-ico { display: block; flex: none; }

/* --- topbalk --- */
#topbar { flex: none; display: flex; align-items: center; gap: 6px;
  padding: calc(6px + var(--safe-top)) calc(8px + var(--safe-right)) 6px calc(8px + var(--safe-left));
  background: linear-gradient(180deg, var(--green-800), var(--green-900)); border-bottom: 1px solid #0006; }
#title-wrap { flex: 1; min-width: 0; padding-left: 4px; }
#title { font-weight: 700; font-size: 17px; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#title span { color: var(--gold-soft); font-weight: 600; }
#subtitle { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle:empty { display: none; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; }
.icon-btn:active { background: #ffffff14; }

main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; }

/* --- knoppen --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 11px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; }
.btn .ico svg { width: 20px; height: 20px; }
.btn.primary { background: var(--gold); color: #1b1606; border-color: transparent; }
.btn.danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn:active { filter: brightness(1.15); }
.pill { min-height: 34px; padding: 0 10px; border-radius: 17px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }

/* --- bibliotheek --- */
#view-library { overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px calc(14px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(14px + var(--safe-left)); }
.lib-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lib-actions #btn-import { grid-column: 1 / -1; }
.lib-actions .btn { white-space: nowrap; }
@media (min-width: 640px) { .lib-actions { grid-template-columns: 2fr 1fr 1fr; } .lib-actions #btn-import { grid-column: auto; } }
#compare-bar { margin-top: 10px; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius); background: #c9a2271f; border: 1px solid #c9a22766; }
#compare-count { flex: 1; font-size: 14px; }
#lib-grid { margin-top: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-align: left; padding: 0; display: flex; flex-direction: column; }
.card .thumb { aspect-ratio: 4/3; background: #000 center/cover no-repeat; position: relative; }
.card .dur { position: absolute; right: 6px; bottom: 6px; background: #000b; padding: 1px 6px; border-radius: 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.card .badge { position: absolute; left: 6px; top: 6px; background: var(--gold); color: #1b1606; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.card .meta { padding: 8px 40px 9px 10px; min-width: 0; }
.card .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .date { font-size: 12px; color: var(--muted); }
.card .more { position: absolute; right: 2px; bottom: 2px; width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); }
.card.selected { outline: 3px solid var(--gold); outline-offset: -3px; }
.card .sel-num { position: absolute; right: 6px; top: 6px; width: 26px; height: 26px; border-radius: 50%; background: var(--gold); color: #1b1606; font-weight: 800; display: grid; place-items: center; }
#lib-empty { text-align: center; padding: 36px 20px 10px; color: var(--text); }
#lib-empty .empty-illu { color: var(--gold); display: flex; justify-content: center; }
#lib-empty .empty-illu svg { width: 64px; height: 64px; }
#lib-empty p { color: var(--muted); max-width: 420px; margin: 8px auto; }
.privacy-note { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; margin-top: 22px; }
.privacy-note .ico svg { width: 16px; height: 16px; }

/* --- analyse --- */
#view-analyze { display: flex; flex-direction: column; }
#stage-wrap { position: relative; flex: 1; min-height: 120px; background: #050806; overflow: hidden; }
#stage { position: absolute; inset: 0; }
.stage-canvas { position: absolute; left: 0; top: 0; z-index: 1; display: block; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.video-holder { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.video-holder video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#hint { z-index: 2; position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: #000c; padding: 6px 12px; border-radius: 16px; font-size: 13px; max-width: 90%; text-align: center; pointer-events: none; }
#zoom-badge { z-index: 2; position: absolute; right: 10px; top: 10px; background: #000b; padding: 4px 10px; border-radius: 14px; font-size: 13px; font-weight: 600; }
#rec-bar { z-index: 3; position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: #000d; padding: 6px 8px 6px 14px; border-radius: 22px; border: 1px solid #e5484d88; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
#rec-time { font-variant-numeric: tabular-nums; font-weight: 700; }
@keyframes pulse { 50% { opacity: .3; } }
#compare-controls { z-index: 2; position: absolute; left: 8px; right: 8px; top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; pointer-events: none; }
#compare-controls > * { pointer-events: auto; }
#overlay-alpha { width: 120px; accent-color: var(--gold); }
.seg { display: inline-flex; background: #000b; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { min-height: 34px; padding: 0 11px; font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--gold); color: #1b1606; }
#loading { z-index: 4; position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 10px; background: #000a; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff3; border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#controls { flex: none; background: var(--panel); border-top: 1px solid var(--line);
  padding: 6px calc(8px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(8px + var(--safe-left)); }
#timeline { padding: 10px 6px 6px; touch-action: none; cursor: pointer; }
#tl-track { position: relative; height: 6px; border-radius: 3px; background: #ffffff24; }
#tl-progress { position: absolute; left: 0; top: 0; bottom: 0; background: var(--gold); border-radius: 3px; width: 0; }
#tl-thumb { position: absolute; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px #0008; left: 0; }
#tl-markers { position: absolute; inset: -5px 0; pointer-events: none; }
#tl-markers i { position: absolute; top: 0; width: 3px; height: 16px; margin-left: -1.5px; background: #00e6b4; border-radius: 2px; }
/* fragment */
#trim-panel { padding: 4px 2px 2px; }
.trim-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; }
.trim-head b { color: var(--gold-soft); }
#trim-info { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.trim-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.trim-btns .btn { padding: 0 6px; font-size: 13px; white-space: nowrap; }
#timeline.trimming { padding: 16px 14px 10px; }
#timeline.trimming #tl-progress { display: none; }
#timeline.trimming #tl-thumb { width: 4px; height: 24px; margin: -12px 0 0 -2px; border-radius: 2px; }
#tl-range { position: absolute; top: -3px; bottom: -3px; background: #c9a22755; border-top: 2px solid var(--gold); border-bottom: 2px solid var(--gold); }
.tl-handle { position: absolute; top: 50%; width: 36px; height: 40px; margin: -20px 0 0 -18px; z-index: 2; touch-action: none; cursor: ew-resize; }
.tl-handle::after { content: ''; position: absolute; left: 12px; top: 6px; width: 12px; height: 28px; background: var(--gold); border-radius: 4px; box-shadow: 0 1px 4px #0009; }
#tl-in::after { border-radius: 6px 2px 2px 6px; }
#tl-out::after { border-radius: 2px 6px 6px 2px; }
.tl-handle.active::after { background: #fff; }
#timeline.ranged #tl-track { background: #c9a22733; box-shadow: inset 3px 0 0 var(--gold), inset -3px 0 0 var(--gold); }
#jog { height: 30px; margin: 2px 4px 4px; border-radius: 8px; background: #0b100d; border: 1px solid var(--line); overflow: hidden; position: relative; touch-action: none; cursor: ew-resize; }
#jog-ticks { position: absolute; inset: 0; background-image: repeating-linear-gradient(90deg, #ffffff38 0 1px, transparent 1px 8px); }
#jog::after { content: ''; position: absolute; left: 50%; top: 3px; bottom: 3px; width: 2px; margin-left: -1px; background: var(--gold); border-radius: 1px; }
#transport { display: flex; align-items: center; gap: 4px; }
#transport .icon-btn.big svg { width: 26px; height: 26px; }
#btn-play { width: 52px; height: 52px; border-radius: 50%; background: var(--gold); color: #1b1606; }
#btn-play svg { width: 28px; height: 28px; }
#time-info { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; line-height: 1.2; }
#t-time { display: block; font-weight: 700; font-size: 15px; }
#t-frame { display: block; font-size: 12px; color: var(--muted); }
.scroll-row { display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 4px 0 2px; }
.scroll-row::-webkit-scrollbar { display: none; }
.tool, .act { flex: none; width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid transparent; }
.tool.on { background: var(--gold); color: #1b1606; }
.act.on { border-color: #00e6b4; color: #00e6b4; }
.act.text { width: auto; padding: 0 10px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.act.rec { color: #ff6b6f; }
.act.rec.on { background: var(--danger); color: #fff; border-color: transparent; }
#btn-save { gap: 6px; display: inline-flex; align-items: center; }
#btn-save svg { width: 18px; height: 18px; }
#btn-save.dirty { border-color: var(--gold); color: var(--gold-soft); }
#export-overlay { position: fixed; inset: 0; z-index: 18; background: #0007; display: grid; place-items: end center; padding-bottom: calc(var(--controls-h, 200px) + 16px); }
#export-overlay .box { display: flex; flex-direction: column; align-items: center; gap: 10px; background: #111a15ee; border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; min-width: 240px; }
#export-text { font-size: 14px; text-align: center; }
#export-bar { width: 100%; height: 6px; border-radius: 3px; background: #ffffff22; overflow: hidden; }
#export-bar i { display: block; height: 100%; width: 0; background: var(--gold); }
#color-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; }

/* De zichtbare hoekentabel wordt in het canvas getekend (strook naast/onder het beeld); dit is de tekstversie voor schermlezers. */
#angle-panel { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#angle-panel .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; color: var(--gold-soft); min-height: 26px; }
#angle-panel .head button { font-size: 12px; color: var(--muted); padding: 4px 0 4px 8px; }
#angle-panel.collapsed .body { display: none; }
#angle-panel .row { line-height: 1.5; display: flex; justify-content: space-between; gap: 12px; }
#angle-panel .row b { color: #00e6b4; }
#angle-panel .note { color: var(--muted); font-size: 11px; margin-top: 6px; max-width: 200px; }

/* Liggend op telefoon: bediening rechts naast het beeld */
@media (orientation: landscape) and (max-height: 520px) {
  #view-analyze { flex-direction: row; }
  #controls { width: 300px; border-top: 0; border-left: 1px solid var(--line); overflow-y: auto; padding-top: 4px; }
  #toolbar, #actionbar { flex-wrap: wrap; overflow: visible; }
  #topbar { padding-top: calc(2px + var(--safe-top)); padding-bottom: 2px; }
  .icon-btn { height: 38px; }
}

/* --- sheet (onderpaneel) --- */
#sheet-backdrop { position: fixed; inset: 0; background: #0009; z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 85dvh; overflow-y: auto; background: var(--panel); border-radius: 16px 16px 0 0; border-top: 1px solid var(--line);
  padding: 8px calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left)); animation: up .18s ease-out; }
@media (min-width: 700px) { #sheet { left: 50%; right: auto; width: 520px; transform: translateX(-50%); bottom: 20px; border-radius: 16px; border: 1px solid var(--line); animation: none; } }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
#sheet h3 { margin: 10px 0 6px; font-size: 17px; }
#sheet p { margin: 6px 0; color: var(--muted); }
#sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: #ffffff33; margin: 2px auto 8px; }
.menu-list { display: flex; flex-direction: column; margin: 6px 0; }
.menu-list button { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 6px; border-bottom: 1px solid var(--line); text-align: left; font-size: 16px; }
.menu-list button:last-child { border-bottom: 0; }
.menu-list button.on { color: var(--gold-soft); font-weight: 700; }
.menu-list button.danger { color: #ff6b6f; }
.menu-list button .right { margin-left: auto; color: var(--muted); font-size: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 14px; }
.swatches button { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: #fff; }
.widths { display: flex; gap: 8px; }
.widths button { flex: 1; min-height: 44px; border-radius: 10px; background: var(--panel-2); display: grid; place-items: center; border: 2px solid transparent; }
.widths button.on { border-color: var(--gold); }
.widths i { display: block; width: 32px; border-radius: 4px; background: #fff; }
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 16px; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.check-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.check-list label { display: flex; gap: 8px; align-items: center; min-height: 40px; padding: 0 8px; background: var(--panel-2); border-radius: 8px; }
.check-list input { width: 20px; height: 20px; accent-color: var(--gold); }
.info-list { font-size: 14px; color: var(--muted); padding-left: 18px; }
.info-list li { margin: 4px 0; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 8px 0; }

/* --- toast --- */
#toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 30; background: #222c26; border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 12px; box-shadow: 0 6px 24px #0008; display: flex; gap: 12px; align-items: center; max-width: calc(100% - 24px); font-size: 14px; }
#toast.error { border-color: #e5484d; }
body.analyzing #toast { bottom: calc(var(--controls-h, 200px) + 10px); }
@media (orientation: landscape) and (max-height: 520px) { body.analyzing #toast { bottom: 12px; left: calc(50% - 150px); } }
#toast button { color: var(--gold-soft); font-weight: 700; white-space: nowrap; }
