:root {
  --bg: #eef1f8;
  --card: #fff;
  --ink: #1d2433;
  --muted: #667085;
  --line: #dfe3ee;
  --accent: #3b5bdb;
  --accent-ink: #fff;
  --accent-soft: #e7ecff;
  --top: #f59f00;
  --top-soft: #fff4db;
  --good: #2f9e44;
  --ok: #e8890c;
  --bad: #e03131;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font: 18px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- opbouw ---------- */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 44px; height: 44px; border-radius: 10px; }
.brand > div { min-width: 0; }
.brand h1 { margin: 0; font-size: 24px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--muted); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
  font-weight: 600;
}
.btn:active { transform: scale(0.97); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.4; }
.pill {
  background: #fff0f0; color: var(--bad); border: 1px solid #ffc9c9;
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600;
}

.tabs { display: flex; gap: 6px; padding: 0 18px 10px; }
.tabs button {
  flex: 1; min-height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600;
}
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.count { opacity: 0.75; font-weight: 500; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); padding: 0 18px; gap: 18px; }
main[data-tab="rank"] #panelAll, main[data-tab="all"] #panelRank { display: none; }

@media (min-width: 900px) {
  .tabs { display: none; }
  main { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  main[data-tab] #panelAll, main[data-tab] #panelRank { display: block; }
}

.panel {
  min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 6px 2px 10px;
}
.panel-head h2 { margin: 0; font-size: 20px; }
.hint { margin: 0; color: var(--muted); font-size: 15px; flex-basis: 100%; }
.hint.warn { color: var(--ok); font-weight: 600; }
.panel-foot { margin-top: 14px; display: grid; gap: 12px; }

.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { min-height: 40px; padding: 0 14px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

/* ---------- lijsten en kaartjes ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; min-height: 90px; border-radius: var(--radius); }
.list.drop-target { outline: 3px dashed var(--accent); outline-offset: 4px; }
.empty {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 18px;
  text-align: center; color: var(--muted);
}

.card {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 8px 8px 4px; min-height: 76px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.card.top6 { border-color: #ffd8a8; background: linear-gradient(90deg, var(--top-soft), #fff 40%); }
.handle {
  width: 40px; align-self: stretch; display: flex; align-items: center; justify-content: center;
  color: #98a2b3; font-size: 24px; touch-action: none; cursor: grab; border: 0; background: none; padding: 0;
}
.rank {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.card.top6 .rank { background: var(--top); color: #fff; }
.card-main { flex: 1; min-width: 0; cursor: pointer; padding: 4px 0; }
.card-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 4px; font-size: 13.5px; color: var(--muted); }
.tag { background: #f2f4f7; border-radius: 6px; padding: 1px 7px; }
.tag.hl { background: var(--accent-soft); color: var(--accent); }
.avg {
  min-width: 52px; text-align: center; font-weight: 800; font-size: 19px;
  border-radius: 10px; padding: 6px 6px; background: #f2f4f7; color: var(--muted);
}
.avg small { display: block; font-size: 11px; font-weight: 600; opacity: 0.8; }
.avg.good { background: #ebfbee; color: var(--good); }
.avg.ok { background: #fff4e6; color: var(--ok); }
.avg.bad { background: #fff5f5; color: var(--bad); }
.icon-btn {
  width: 48px; height: 48px; flex-shrink: 0; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; font-size: 20px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.icon-btn:disabled { opacity: 0.3; }
.icon-btn.add { background: var(--accent); color: #fff; border-color: var(--accent); font-size: 26px; }
.btns { display: flex; gap: 6px; }
.reserve {
  list-style: none; text-align: center; color: var(--muted); font-size: 14px; padding: 2px 0;
  display: flex; align-items: center; gap: 10px;
}
.reserve::before, .reserve::after { content: ""; flex: 1; border-top: 1px dashed #c3cad9; }

/* slepen */
.card.placeholder { opacity: 0.35; }
.ghost {
  position: fixed; z-index: 50; pointer-events: none; margin: 0;
  box-shadow: 0 14px 34px rgba(16, 24, 40, 0.25); transform: rotate(-1deg) scale(1.02);
}
.drop-line { height: 6px; border-radius: 3px; background: var(--accent); list-style: none; }
body.dragging, body.dragging * { cursor: grabbing !important; }
body.dragging .panel { overflow: hidden; }

.hidden-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.hidden-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--card); border-radius: 12px; padding: 6px 6px 6px 14px; }
details summary { cursor: pointer; color: var(--muted); padding: 10px 2px; font-weight: 600; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 30; background: rgba(16, 24, 40, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet {
  background: var(--bg); width: 100%; max-width: 760px; max-height: 100%;
  border-radius: 20px; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.35);
}
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 22px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-head input.title { flex: 1; font-size: 20px; font-weight: 700; }
.sheet-tabs { padding: 12px 16px 0; }
.sheet-tabs .seg { width: 100%; }
.sheet-tabs .seg button { flex: 1; min-height: 44px; }
.sheet-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; gap: 18px; }
.sheet-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.sheet-foot .spacer { flex: 1; }

.field { display: grid; gap: 8px; }
.field > label, .field > .label { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.field .help { color: var(--muted); font-size: 14px; font-weight: 400; }
.check { background: #fff4e6; color: var(--ok); font-size: 12px; font-weight: 700; border-radius: 6px; padding: 2px 7px; text-transform: uppercase; letter-spacing: 0.03em; }
input[type=text], input[type=url], textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); font-size: 17px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; font-size: 16px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.crit { background: var(--card); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; }
.crit-name { font-weight: 700; display: flex; justify-content: space-between; }
.crit-name span { color: var(--muted); font-weight: 600; }
.grades { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.grade {
  min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: #f8f9fc;
  font-weight: 700; font-size: 18px; padding: 0;
}
.grade.on { color: #fff; border-color: transparent; }
.summary { background: var(--card); border-radius: var(--radius); padding: 14px; display: flex; align-items: center; gap: 14px; }
.summary .avg { font-size: 26px; min-width: 76px; padding: 10px; }

.crit-row { display: flex; gap: 8px; align-items: center; }
.crit-row input { flex: 1; }
.share-url { font-size: 14px; word-break: break-all; color: var(--muted); background: var(--card); border-radius: 10px; padding: 10px 12px; }
.small { color: var(--muted); font-size: 14px; }

/* ---------- welkom en melding ---------- */
.welcome { height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.welcome .box { background: var(--card); border-radius: 20px; padding: 28px; max-width: 520px; display: grid; gap: 14px; text-align: center; }
.welcome img { width: 96px; height: 96px; border-radius: 22px; margin: 0 auto; }
.welcome h1 { margin: 0; }
.welcome p { margin: 0; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; background: #1d2433; color: #fff; padding: 12px 18px; border-radius: 12px;
  max-width: min(560px, calc(100% - 32px)); font-size: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

@media (max-width: 600px) {
  body { font-size: 16px; }
  .top { padding: 10px 12px; }
  .brand h1 { font-size: 20px; }
  .brand img { width: 36px; height: 36px; }
  .btn { padding: 0 12px; }
  main, .tabs { padding-left: 12px; padding-right: 12px; }
  .grades { grid-template-columns: repeat(5, 1fr); }
  .sub { display: none; }
  .top-actions .btn { padding: 0 10px; font-size: 15px; }
  .card { flex-wrap: wrap; row-gap: 4px; }
  .card .btns { flex-basis: 100%; justify-content: flex-end; }
  .handle { width: 30px; }
  .sheet-foot .btn { font-size: 15px; padding: 0 12px; }
}
