:root {
  --bg: #14161c;
  --panel: #1f232c;
  --text: #e9ecf2;
  --muted: #8a92a3;
  --accent: #4f8cff;
  --seam: rgba(0, 0, 0, 0.55);
  --anim: 220ms;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}

.stats { display: flex; gap: 14px; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
#timer { color: var(--muted); }

.controls { display: flex; gap: 8px; }

button, select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid #2d3340;
  border-radius: 10px;
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
}
button:active { background: #2a2f3a; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 12px 16px;
}

#board {
  position: relative;
  width: min(100%, calc(100dvh - 140px));
  aspect-ratio: 1;
  background: var(--panel);
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;
}

.piece {
  position: absolute;
  background-repeat: no-repeat;
  transition: left var(--anim) ease, top var(--anim) ease, transform var(--anim) ease;
  will-change: left, top, transform;
}
/* Naad tussen stukken die (nog) niet aan elkaar hangen */
.piece::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--seam);
  pointer-events: none;
  transition: border-width 150ms;
}
.piece.jt::after { border-top-width: 0; }
.piece.jr::after { border-right-width: 0; }
.piece.jb::after { border-bottom-width: 0; }
.piece.jl::after { border-left-width: 0; }

.piece.lifted { z-index: 10; }
.piece.dragging {
  z-index: 20;
  transition: none;
  filter: brightness(1.08) drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
}
.piece.snap { animation: snap 260ms ease; }
@keyframes snap {
  50% { filter: brightness(1.35); }
}

#board.solved .piece::after { border-width: 0; }
#board.solved .piece { transition: none; }

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms;
}
#board.peeking #preview { opacity: 1; }

#loading {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--panel);
}
#board.loading #loading { display: flex; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #2d3340;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#credit {
  margin: 10px 0 0;
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--muted);
}
#credit a { color: inherit; }

#win {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  justify-content: center;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  animation: rise 300ms ease;
}
#win[hidden] { display: none; }
#win .card {
  width: min(100%, 420px);
  background: var(--panel);
  border: 1px solid #2d3340;
  border-radius: 16px;
  padding: 16px 20px 20px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
#win h2 { margin: 0 0 4px; }
#win p { margin: 0 0 14px; color: var(--muted); }
#next {
  width: 100%;
  height: 48px;
  background: var(--accent);
  border: none;
  font-weight: 600;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
