:root {
  --bg: #f3ebdd;
  --bg-deep: #e9dcc6;
  --wood: #d8b98c;
  --wood-dark: #b8935f;
  --ink: #3b3631;
  --hole: #6e5432;

  --red: #d9645a;
  --orange: #e9965a;
  --yellow: #f0c457;
  --green: #7fb36e;
  --blue: #5d90c9;
  --purple: #9b7ec4;
  --pink: #eca2b6;
  --brown: #9a6b4a;

  --sel: #d9645a;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

/* Nothing in the app scrolls: a fixed body stops iOS rubber-banding and pull-to-refresh. */
html, body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  font-family: -apple-system, system-ui, sans-serif;
  color: var(--ink);
}

/* touch-action: none prevents Safari from cancelling drags (pointercancel) and zooming on double-tap. */
body, body * {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px);
}
.view.active { display: flex; animation: fade-in .35s ease; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Home ---------- */

#home { align-items: center; justify-content: center; }

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: min(5vmin, 40px);
  justify-content: center;
  align-items: center;
}

.tile {
  width: min(28vmin, 240px);
  height: min(28vmin, 240px);
  border-radius: 28%;
  background: #fffaf2;
  box-shadow: 0 6px 0 var(--bg-deep), 0 10px 24px rgba(80, 60, 30, .12);
  transition: transform .15s ease;
}
.tile:active { transform: translateY(4px) scale(.97); box-shadow: 0 2px 0 var(--bg-deep); }
.tile svg { width: 78%; height: 78%; display: block; margin: auto; }

@media (orientation: portrait) {
  .tiles { flex-direction: column; }
  .tile { width: min(26vh, 62vw, 240px); height: min(26vh, 62vw, 240px); }
}

/* ---------- Hold-to-activate buttons ---------- */

.hold {
  position: fixed;
  z-index: 50;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 250, 242, .85);
  box-shadow: 0 2px 8px rgba(80, 60, 30, .15);
  display: none;
}
.hold.visible { display: block; }
.hold-back { top: calc(var(--safe-t) + 10px); left: calc(var(--safe-l) + 10px); }
.hold-clear { top: calc(var(--safe-t) + 10px); right: calc(var(--safe-r) + 10px); }

.hold .icon {
  position: absolute;
  inset: 16px;
  width: 28px;
  height: 28px;
  fill: #b9a98f;
  stroke: #b9a98f;
  stroke-width: 1.5;
  stroke-linejoin: round;
}
.hold .ring {
  position: absolute;
  inset: 0;
  width: 60px;
  height: 60px;
  transform: rotate(-90deg);
}
.hold .ring circle {
  fill: none;
  stroke: var(--green);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 164;
  stroke-dashoffset: 164;
}
.hold .icon-undo { display: none; }
.hold.undo { background: var(--green); }
.hold.undo .icon-reset { display: none; }
.hold.undo .icon-undo { display: block; fill: #fff; stroke: #fff; }

.hold.holding .ring circle {
  transition: stroke-dashoffset var(--hold-ms, 900ms) linear;
  stroke-dashoffset: 0;
}

/* ---------- Shared play surface ---------- */

.play {
  position: relative;
  flex: 1;
}
/* Keep pieces clear of the back button in the top-left corner. */
#colors, #shapes, #picker, #coloring, #paint { padding-top: calc(var(--safe-t) + 64px); }

.piece {
  position: absolute;
  z-index: 5;
  will-change: transform;
  filter: drop-shadow(0 4px 3px rgba(60, 40, 20, .25));
}
.piece.dragging {
  z-index: 40;
  filter: drop-shadow(0 12px 10px rgba(60, 40, 20, .3));
}
.piece.returning { transition: transform .45s cubic-bezier(.3, 1.4, .5, 1); }
.piece svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ---------- Kleuren sorteren ---------- */

.bowl {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #fffdf8 0 55%, #efe4d2 75%);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .06), 0 6px 0 var(--bg-deep);
  border: 10px solid var(--c);
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 2px;
  padding: var(--bowl-pad, 20px);
}
.bowl.happy { animation: wiggle .7s ease; }
.bowl .mark {
  position: absolute;
  inset: 20%;
  width: 60%;
  height: 60%;
  opacity: .3;
  pointer-events: none;
}

.bowl .piece {
  position: relative;
  left: auto !important;
  top: auto !important;
  width: var(--in-bowl) !important;
  height: var(--in-bowl) !important;
  filter: drop-shadow(0 2px 1px rgba(60, 40, 20, .2));
}

@keyframes wiggle {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.08); }
  60% { transform: scale(.97); }
}

/* ---------- Vormen inpassen ---------- */

.board {
  position: absolute;
  border-radius: 28px;
  background:
    repeating-linear-gradient(95deg, rgba(255, 255, 255, .06) 0 6px, rgba(0, 0, 0, .03) 6px 14px),
    var(--wood);
  box-shadow: inset 0 -8px 0 var(--wood-dark), 0 8px 18px rgba(80, 60, 30, .18);
}
.hole { position: absolute; }
.hole svg { display: block; width: 100%; height: 100%; overflow: visible; }
.hole.filled { animation: wiggle .6s ease; }

/* ---------- Kleurplaat kiezen ---------- */

#picker { align-items: center; justify-content: center; }

.picker-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), var(--t, 150px));
  gap: var(--gap, 18px);
}
.thumb {
  width: var(--t, 150px);
  height: var(--t, 150px);
  border-radius: 22%;
  background: #fff;
  box-shadow: 0 5px 0 var(--bg-deep), 0 8px 18px rgba(80, 60, 30, .1);
  padding: 8%;
  transition: transform .15s ease;
}
.thumb:active { transform: translateY(3px) scale(.97); }
.thumb svg, .thumb canvas { width: 100%; height: 100%; display: block; }
.thumb.blank svg { padding: 14%; }

/* ---------- Inkleuren + vingerverf ---------- */

#coloring, #paint { gap: 12px; }
@media (orientation: landscape) { #coloring, #paint { flex-direction: row; } }
@media (orientation: portrait)  { #coloring, #paint { flex-direction: column; } }

.canvas-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#coloring .canvas-wrap { container-type: size; }

/* Always square, as large as fits: a stretched box would shift marker strokes away from the finger. */
.drawing {
  position: relative;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 6px 18px rgba(80, 60, 30, .12);
  overflow: hidden;
}
.drawing canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.drawing .lines { pointer-events: none; }

/* Fill / marker switch, top centre between the corner buttons. */
.tools {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  gap: 14px;
}
.tool {
  width: 60px;
  height: 52px;
  border-radius: 18px;
  background: rgba(255, 250, 242, .85);
  box-shadow: 0 2px 8px rgba(80, 60, 30, .15);
  transition: transform .15s ease;
}
.tool svg { width: 38px; height: 38px; display: block; margin: auto; }
.tool.selected { background: #fff; outline: 4px solid var(--ink); outline-offset: 2px; transform: scale(1.06); }


.paper {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 6px 18px rgba(80, 60, 30, .12);
}

.palette {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 10px;
}
/* In landscape the dots fill columns; sizePalettes() sets --cols to what the height needs. */
@media (orientation: landscape) {
  .palette { flex-direction: column; width: calc(var(--cols, 2) * (var(--dot) + 10px) - 10px); }
}
@media (orientation: portrait)  { .palette { flex-direction: row; } }

.palette { --dot: clamp(44px, 8.5vmin, 72px); }

.dot {
  width: var(--dot);
  height: var(--dot);
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .12), 0 3px 6px rgba(80, 60, 30, .15);
  transition: transform .15s ease;
}
.dot.white { box-shadow: inset 0 0 0 2px #e4d9c6, inset 0 -4px 0 rgba(0, 0, 0, .06), 0 3px 6px rgba(80, 60, 30, .15); }
.dot.glitter {
  position: relative;
  overflow: hidden;
  background-size: 48px 48px;
}
/* A slow shine across the glitter dots. */
.dot.glitter::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .75) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: shine 2.4s ease-in-out infinite;
}
@keyframes shine {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}
.dot.selected { transform: scale(1.15); outline: 4px solid var(--ink); outline-offset: 3px; }
