/* Blox Burst - opmaak. Mobiel eerst; iPhone/iPad-veilig (safe areas, geen zoom of scroll). */
:root {
  --bg1: #7c4dff;
  --bg2: #305ceb;
  --bg3: #0e1034;
  --panel: rgba(255, 255, 255, 0.08);
  --gold: #ffcd3c;
  --sub: #b4bdff;
  --font: "Fredoka", ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, sans-serif;
  --board: min(92vw, 520px);
  --pitch: 40px;
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg3); color: #fff; font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}
body { position: fixed; inset: 0; touch-action: none; }
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }

/* ---------- Achtergrond ---------- */
#bg {
  position: fixed; inset: -20%;
  background: linear-gradient(135deg, var(--bg1), var(--bg2) 45%, var(--bg3));
  animation: bgspin 30s ease-in-out infinite alternate;
  z-index: 0;
}
@keyframes bgspin { to { transform: rotate(12deg) scale(1.1); } }
body.fever #bg { background: linear-gradient(135deg, #ff6a2a, #b8306b 45%, #1d0b2a); }
#floaters { position: absolute; inset: 0; }
.floater {
  position: absolute; border-radius: 22%; opacity: 0.16;
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  from { transform: translateY(110vh) rotate(0deg); }
  to { transform: translateY(-20vh) rotate(360deg); }
}

/* ---------- Layout ---------- */
#app {
  position: fixed; inset: 0; z-index: 1;
  display: grid;
  grid-template-areas: "top" "powers" "board" "tray" "menu";
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: clamp(6px, 1.6vh, 14px);
  padding:
    max(env(safe-area-inset-top), 10px)
    max(env(safe-area-inset-right), 12px)
    max(env(safe-area-inset-bottom), 10px)
    max(env(safe-area-inset-left), 12px);
  max-width: 620px; margin: 0 auto;
}
#top { grid-area: top; }
#powers { grid-area: powers; }
#boardWrap { grid-area: board; }
#tray { grid-area: tray; }
#menu { grid-area: menu; }

/* liggend (iPad liggend, telefoon dwars, desktop) */
@media (min-aspect-ratio: 5/4) {
  #app {
    max-width: none;
    grid-template-areas: "board top" "board powers" "board tray" "board menu";
    grid-template-columns: minmax(0, 1fr) minmax(250px, 36%);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    column-gap: clamp(12px, 3vw, 40px);
    max-width: 1400px;
  }
  #tray { align-content: center; }
}

/* ---------- Header ---------- */
#title {
  text-align: center; font-weight: 700; letter-spacing: 0.04em;
  font-size: clamp(20px, 4.2vh, 34px); line-height: 1.1;
  background: linear-gradient(90deg, #ff5c8c, #ffc83c, #3ce6a0, #50aaff, #b46cff, #ff5c8c);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: rainbow 6s linear infinite;
  filter: drop-shadow(0 2px 0 rgba(20, 10, 50, 0.6));
}
@keyframes rainbow { to { background-position: 200% 0; } }
#scoreRow { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-top: 2px; }
.stat { display: flex; flex-direction: column; font-weight: 600; font-size: clamp(14px, 2.4vh, 20px); }
.stat.right { align-items: flex-end; }
.statLabel { color: var(--gold); font-size: 0.75em; }
#score {
  font-weight: 700; font-size: clamp(34px, 7vh, 64px); line-height: 1;
  text-shadow: 0 3px 0 rgba(20, 10, 50, 0.5);
  transition: transform 0.12s;
}
#score.pop { transform: scale(1.25); }
#combo { color: var(--gold); font-weight: 700; text-align: right; }
#combo.fever { color: #ff9a3c; animation: pulse 0.5s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

/* ---------- Power-ups ---------- */
#powers { display: flex; justify-content: center; gap: 10px; }
.power {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px; font-size: clamp(16px, 2.6vh, 22px); font-weight: 700;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s, opacity 0.2s, filter 0.2s;
}
.power:active { transform: scale(0.9); }
#pwRotate { background: linear-gradient(#5ae6ff, #1482c8); }
#pwBomb { background: linear-gradient(#ff825a, #c8283c); }
#pwShuffle { background: linear-gradient(#78f08c, #1ea05a); }
.power.empty { opacity: 0.45; filter: saturate(0.4); }
.power.has { animation: wiggle 2.4s ease-in-out infinite; }
.power.active { animation: shakeit 0.2s linear infinite; box-shadow: 0 0 0 3px #fff, 0 0 24px #ff825a; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-6deg); } 90% { transform: rotate(6deg); } 95% { transform: rotate(-3deg); } }
@keyframes shakeit { 50% { transform: rotate(-8deg) scale(1.06); } }

/* ---------- Bord ---------- */
#boardWrap { display: grid; place-items: center; min-height: 0; position: relative; }
@property --spin { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@keyframes spin { to { --spin: 360deg; } }
#board {
  position: relative; width: var(--board); height: var(--board);
  padding: 2%; border-radius: 4%;
  /* draaiende regenboogrand */
  border: 4px solid transparent;
  background:
    linear-gradient(#15163f, #15163f) padding-box,
    conic-gradient(from var(--spin), #ff5c8c, #ffc83c, #3ce6a0, #50aaff, #b46cff, #ff5c8c) border-box;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  animation: spin 4s linear infinite;
}
body.fever #board {
  border-width: 6px;
  background:
    linear-gradient(#1f1230, #1f1230) padding-box,
    conic-gradient(from var(--spin), #ff3c14, #ffbe28, #ff5a00, #ffd25a, #ff3c14) border-box;
  box-shadow: 0 0 30px #ff6a00, 0 0 70px rgba(255, 90, 0, 0.45);
  animation-duration: 1.2s;
}
#board.shake1 { animation: shake 0.25s, spin 4s linear infinite; }
#board.shake2 { animation: shake 0.4s, spin 4s linear infinite; }
#board.shake3 { animation: shakeBig 0.6s, spin 4s linear infinite; }
#board.punch { animation: punch 0.5s cubic-bezier(.2, 1.6, .4, 1), spin 4s linear infinite; }
@keyframes shake { 20% { translate: -4px 2px; } 40% { translate: 4px -2px; } 60% { translate: -3px -1px; } 80% { translate: 2px 2px; } }
@keyframes shakeBig { 10% { translate: -10px 4px; rotate: -1deg; } 25% { translate: 9px -6px; rotate: 1deg; } 40% { translate: -7px 5px; } 55% { translate: 6px -3px; } 70% { translate: -4px 2px; } 85% { translate: 2px -1px; } }
@keyframes punch { 0% { scale: 1; } 30% { scale: 1.06; } 100% { scale: 1; } }

#cells {
  position: relative; width: 100%; height: 100%;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); gap: 1.2%;
}
.cell { position: relative; border-radius: 20%; background: rgba(255, 255, 255, 0.07); }
.cell.pvline { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6) inset; }

/* ---------- Blokjes ---------- */
.blk {
  position: absolute; inset: 0; border-radius: 20%;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 72%, #fff) 0%, var(--c) 45%, color-mix(in srgb, var(--c) 78%, #000) 100%);
  box-shadow: inset 0 -0.12em 0 color-mix(in srgb, var(--c) 60%, #000), 0 2px 4px rgba(0, 0, 0, 0.25);
  font-size: calc(var(--pitch) * 0.5);
}
.blk::before {
  content: ""; position: absolute; left: 14%; right: 14%; top: 9%; height: 16%;
  border-radius: 99px; background: rgba(255, 255, 255, 0.55);
}
.blk.star::after {
  content: "⭐"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 0.95em; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}
.cell > .blk { display: none; }
.cell.on > .blk { display: block; }
.cell.ghost > .blk { display: block; opacity: 0.45; }
.cell.pop > .blk { animation: placePop 0.28s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes placePop { from { transform: scale(0.6); } to { transform: scale(1); } }
.cell.junk > .blk { --c: #7a7f96; }

/* ---------- Lade ---------- */
#tray { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.slot {
  position: relative; aspect-ratio: 1; max-height: 22vh; width: 100%; justify-self: center;
  border-radius: 20%; background: var(--panel); border: 2px solid rgba(255, 255, 255, 0.12);
  touch-action: none; transition: transform 0.2s;
}
@media (min-aspect-ratio: 5/4) { .slot { max-height: 26vh; } }
/* iPad liggend en andere brede schermen met veel hoogte: lade verticaal */
@media (min-aspect-ratio: 5/4) and (max-aspect-ratio: 17/10) and (min-height: 560px) {
  #tray { grid-template-columns: 1fr; grid-template-rows: repeat(3, minmax(0, 1fr)); min-height: 0; }
  .slot { height: 100%; width: auto; max-height: none; aspect-ratio: 1; }
}
.slot:hover { transform: scale(1.05); }
.piece { position: absolute; pointer-events: none; }
.slot .piece { left: 50%; top: 50%; translate: -50% -50%; animation: bob 2.4s ease-in-out infinite; }
.slot[data-i="1"] .piece { animation-delay: -0.8s; }
.slot[data-i="2"] .piece { animation-delay: -1.6s; }
.slot .piece.enter { animation: enter 0.35s cubic-bezier(.3, 1.6, .5, 1), bob 2.4s ease-in-out 0.35s infinite; }
@keyframes bob { 50% { transform: translateY(-6%) rotate(2deg); } }
@keyframes enter { from { transform: scale(0.2) rotate(-30deg); opacity: 0; } }
.slot .piece.nofit { opacity: 0.35; filter: grayscale(0.5); }
.piece .blk { position: absolute; }
.rotBadge { position: absolute; top: 4%; right: 6%; font-size: clamp(12px, 2vh, 18px); display: none; }
.slot.canRotate .rotBadge { display: block; animation: pulse 0.8s ease-in-out infinite alternate; }

#ghost { position: fixed; left: 0; top: 0; z-index: 30; pointer-events: none; will-change: transform; }
#ghost .piece { position: relative; transition: scale 0.15s; filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.35)); }

#bombPreview {
  position: absolute; display: none; z-index: 5; pointer-events: none; border-radius: 10%;
  background: rgba(255, 70, 50, 0.4); border: 3px solid #ffdc78;
  animation: pulse 0.3s ease-in-out infinite alternate;
}

/* ---------- Menu ---------- */
#menu { display: flex; justify-content: center; gap: 12px; }
.mbtn {
  width: clamp(44px, 7vh, 60px); height: clamp(44px, 7vh, 60px); border-radius: 30%;
  font-size: clamp(20px, 3.4vh, 28px);
  background: linear-gradient(#966eff, #503cc8);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}
.mbtn:active { transform: scale(0.88); }

/* ---------- Popups & effecten ---------- */
#popups { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.popup {
  position: absolute; left: 50%; transform: translate(-50%, -50%);
  font-weight: 700; white-space: nowrap; pointer-events: none;
  text-shadow: 0 3px 0 rgba(20, 10, 50, 0.7), 0 0 18px rgba(0, 0, 0, 0.3);
  animation: popup 1.2s cubic-bezier(.2, 1.4, .4, 1) forwards;
}
@keyframes popup {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  25% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}
#fx { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
#flash { position: fixed; inset: 0; z-index: 41; pointer-events: none; background: #fff; opacity: 0; }
#flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { 0% { opacity: 0.75; } 100% { opacity: 0; } }
#bigText {
  position: fixed; left: 50%; top: 42%; z-index: 42; pointer-events: none;
  font-weight: 700; font-size: clamp(44px, 12vw, 120px); white-space: nowrap; opacity: 0;
  background: linear-gradient(90deg, #ff5c8c, #ffc83c, #3ce6a0, #50aaff, #b46cff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 rgba(20, 10, 50, 0.8)) drop-shadow(0 0 30px rgba(255, 255, 255, 0.4));
  transform: translate(-50%, -50%);
}
#bigText.go { animation: bigText 1.5s cubic-bezier(.2, 1.5, .4, 1) forwards; }
@keyframes bigText {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(3) rotate(-10deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(0.9) rotate(3deg); }
  30% { transform: translate(-50%, -50%) scale(1.05) rotate(-2deg); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); }
}

/* ---------- Venster ---------- */
#modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(5, 5, 25, 0.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: max(env(safe-area-inset-top), 16px) 16px max(env(safe-area-inset-bottom), 16px);
  touch-action: pan-y;
}
#modal.hidden { display: none; }
#modalCard {
  width: min(92vw, 440px); max-height: 100%; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 22px; border-radius: 26px; text-align: center;
  background: linear-gradient(#4632aa, #1a1846); border: 3px solid rgba(140, 150, 255, 0.6);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: cardIn 0.35s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes cardIn { from { transform: scale(0.6) translateY(30px); opacity: 0; } }
#modalCard { position: relative; }
.xBtn {
  position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border-radius: 50%;
  font-size: 20px; font-weight: 700; line-height: 1; background: rgba(255, 255, 255, 0.14);
}
.xBtn:active { transform: scale(0.9); }
#modalCard h2 { margin: 0 0 6px; padding: 0 36px; font-size: 30px; }
#modalCard .big { font-size: 54px; font-weight: 700; margin: 4px 0; }
#modalCard .sub { color: var(--sub); margin: 4px 0 12px; }
#modalCard .gold { color: var(--gold); }
.btn {
  display: block; width: 100%; margin-top: 10px; padding: 14px; border-radius: 18px;
  font-size: 20px; font-weight: 700;
  background: linear-gradient(#5ee68c, #1fa55a);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25);
}
.btn.alt { background: linear-gradient(#7a6ee0, #4a3cb0); }
.btn.red { background: linear-gradient(#ff7a7a, #d23c4c); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; }
input.name {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.3); color: #fff; font: inherit; font-size: 18px; text-align: center;
  -webkit-user-select: text; user-select: text;
}
.tabs { display: flex; gap: 6px; margin: 10px 0; }
.tab { flex: 1; padding: 8px; border-radius: 12px; background: rgba(255, 255, 255, 0.1); font-weight: 600; }
.tab.on { background: var(--gold); color: #2a1a00; }
.lb { list-style: none; padding: 0; margin: 0; text-align: left; }
.lb li { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; padding: 9px 12px; border-radius: 12px; margin-bottom: 5px; background: rgba(0, 0, 0, 0.22); }
.lb li.me { background: rgba(255, 205, 60, 0.25); }
.lb .rk { font-weight: 700; }
.lb .sc { font-weight: 700; color: var(--gold); }
.help { text-align: left; line-height: 1.45; }
.help p { margin: 8px 0; }
.msg { color: #ff9a9a; min-height: 1.2em; margin-top: 8px; }
