:root {
  --steel: #4682b4;
  --text: #14263a;
  --muted: #4c6178;
  --accent: #1f5a8f;
  --glass: rgba(255, 255, 255, 0.22);
  --glass-border: rgba(255, 255, 255, 0.55);
  --shadow: 0 8px 32px rgba(10, 40, 80, 0.25);
  --tile: 112px; /* vaste tegelgrootte, overal gelijk */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--steel) linear-gradient(135deg, #5a93bf 0%, #4682b4 50%, #386a94 100%) fixed;
}
/* Zachte lichtvlekken zodat de blur van het glas zichtbaar is (niet bij eigen achtergrond) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.22), transparent 40%),
    radial-gradient(circle at 85% 35%, rgba(255, 255, 255, 0.14), transparent 38%),
    radial-gradient(circle at 50% 95%, rgba(255, 255, 255, 0.18), transparent 40%);
}
/* Eigen achtergrond op een vaste laag (werkt ook op iOS, waar background-attachment: fixed ontbreekt) */
body.has-bg::before { background: var(--bg-image) center / cover no-repeat; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}
.card { border-radius: 24px; padding: 24px; }

/* Tegels vanuit het midden van de pagina */
.center {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px 40px;
}
.grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 28px 24px;
  max-width: 900px;
}
.empty { color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }

/* Tegels hebben altijd exact dezelfde grootte en krimpen nooit mee */
.tile-wrap { position: relative; flex: 0 0 var(--tile); width: var(--tile); }
.tile-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}
.tile {
  flex: 0 0 var(--tile);
  width: var(--tile);
  height: var(--tile);
  border-radius: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tile-link:hover .tile,
.tile-link:focus-visible .tile { transform: translateY(-3px) scale(1.03); box-shadow: 0 12px 36px rgba(10, 40, 80, 0.35); }
.tile-link:focus-visible { outline: none; }
.tile-link:focus-visible .tile { outline: 2px solid #fff; outline-offset: 2px; }
.tile img { width: 64%; height: 64%; object-fit: contain; }
.tile .letter { font-size: 2.4rem; font-weight: 600; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.tile-label {
  max-width: 100%;
  font-size: 0.85rem;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Slepen (bewerkmodus) */
.tile-wrap[draggable="true"], .group-wrap[draggable="true"] { cursor: grab; }
.tile img { -webkit-user-drag: none; user-select: none; }
.dragging { opacity: 0.35; }
.drop-before::before, .drop-after::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 4px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
}
.drop-before::before { left: -14px; }
.drop-after::before { right: -14px; }
.drop-into { outline: 2px dashed #fff; outline-offset: 6px; border-radius: 30px; }

/* Bewerkknoppen op tegels */
.tile-actions { position: absolute; top: -8px; right: -8px; display: flex; gap: 4px; }
.round {
  width: 26px; height: 26px; padding: 0;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.round.danger { color: #c0332b; }

/* Werkbalk */
.toolbar {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.toolbar form { margin: 0; }

.btn {
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: rgba(255, 255, 255, 0.8); }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #174a77; }

/* Groep: container die zich aanpast aan de (vaste) tegelgrootte */
.group-wrap { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; }
.group { flex: 1 1 auto; border-radius: 30px; padding: 18px; } /* vult de rijhoogte: groepen op één regel zijn even hoog */
.group .grid { gap: 20px 16px; max-width: calc(4 * var(--tile) + 3 * 16px); }
.group-label { font-size: 0.85rem; font-weight: 700; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); }
.add-slot { font-size: 2rem; color: #fff; border-style: dashed; }
.tile-link.placeholder { cursor: default; }
.empty-slot { border-radius: 26px; border: 1px dashed var(--glass-border); color: #fff; font-size: 0.85rem; }

/* Formulieren */
dialog.card { width: min(420px, calc(100% - 32px)); color: var(--text); background: rgba(255, 255, 255, 0.88); }
dialog::backdrop { background: rgba(20, 50, 90, 0.4); backdrop-filter: blur(4px); }
form h1, form h2 { margin: 0 0 16px; font-size: 1.3rem; }
label { display: block; margin-bottom: 14px; font-size: 0.85rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; }
input[type="text"], input[type="url"], input[type="password"], input[type="file"], select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  font: inherit; color: var(--text);
  border: 1px solid rgba(40, 70, 110, 0.25);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.error { color: #c0332b; font-size: 0.9rem; }
[hidden] { display: none !important; }

/* Loginscherm: opaquer glas voor leesbaarheid op blauw */
.login { width: min(360px, 100%); background: rgba(255, 255, 255, 0.85); color: var(--text); }
.login .btn { width: 100%; margin-top: 4px; }

/* Melding bij ontbrekende database-migratie */
.banner {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20;
  width: min(720px, calc(100% - 32px));
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 246, 214, 0.97);
  color: #4a3b00;
  border: 1px solid #e0c35a;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
.banner pre { margin: 8px 0; padding: 10px 12px; border-radius: 10px; background: #2b2b2b; color: #f5f5f5; white-space: pre-wrap; word-break: break-all; font-size: 0.85rem; }

/* ---- Slepen met aanraking ---- */
.tile-wrap, .group-wrap { -webkit-touch-callout: none; user-select: none; }
.touch-ghost { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; opacity: 0.85; }
.touch-ghost .tile-actions { display: none; }
button, .btn, .tile-link { touch-action: manipulation; }

/* ---- Responsive ---- */
dialog.card { max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; }
.banner { bottom: max(16px, env(safe-area-inset-bottom)); }

/* Aanraakschermen: grotere knoppen */
@media (pointer: coarse) {
  .btn { min-height: 44px; padding: 10px 18px; }
  .round { width: 34px; height: 34px; font-size: 1rem; }
  .tile-actions { top: -12px; right: -12px; }
  input[type="text"], input[type="url"], input[type="password"], select { min-height: 44px; }
}

/* Tablets en telefoons: werkbalk in de paginastroom i.p.v. er bovenop */
@media (max-width: 760px) {
  .toolbar { position: static; justify-content: center; padding: 14px 12px 0; }
  .center { min-height: calc(100vh - 70px); min-height: calc(100dvh - 70px); padding: 24px 16px 40px; }
  .login-page .center { min-height: 100vh; min-height: 100dvh; }
  .grid { gap: 24px 18px; }
  .card { padding: 20px; }
}

/* Telefoons: alle tegels uniform kleiner (de verhouding blijft overal gelijk) */
@media (max-width: 480px) {
  :root { --tile: 88px; }
  .tile { border-radius: 22px; }
  .tile .letter { font-size: 2rem; }
  .group { padding: 14px; border-radius: 26px; }
  .group .grid { gap: 20px 12px; max-width: calc(3 * var(--tile) + 2 * 12px); }
  .tile-label, .group-label { font-size: 0.8rem; }
  .actions .btn { flex: 1 1 auto; }
}
@media (max-width: 360px) {
  .group .grid { max-width: calc(2 * var(--tile) + 12px); }
}

.banner .btn { margin-right: 6px; }

/* Groepskop: label met (in bewerkmodus) de knoppen ernaast i.p.v. erover */
.group-head { display: flex; align-items: center; justify-content: center; gap: 8px; max-width: 100%; }
.tile-actions.inline { position: static; }
