/* WordBloom — crossword word-connect game */
:root {
  --accent: #3f6fd1;
  --tile-empty: rgba(255, 255, 255, 0.34);
  --ink: #2a2f45;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #fff; overflow: hidden; user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---------- Splash / loading ---------- */
.splash {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #7b73ff 0%, #3f6fd1 100%);
  color: #fff; transition: opacity .5s ease;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; animation: rise .5s ease; }
.splash-logo { width: 104px; height: 104px; filter: drop-shadow(0 10px 22px rgba(0,0,0,.28)); animation: bob 2.4s ease-in-out infinite; }
.splash-title { font-size: 34px; font-weight: 800; margin: 16px 0 4px; letter-spacing: .5px; }
.splash-tagline { opacity: .85; margin: 0 0 24px; font-weight: 700; letter-spacing: 3px; font-size: 12px; text-transform: uppercase; }
.splash-dots { display: flex; gap: 9px; justify-content: center; }
.splash-dots span { width: 10px; height: 10px; border-radius: 50%; background: #fff; opacity: .4; animation: blink 1.2s infinite; }
.splash-dots span:nth-child(2) { animation-delay: .2s; }
.splash-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes blink { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

/* ---------- Win confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 19; overflow: hidden; }
.confetti i { position: absolute; top: -24px; width: 9px; height: 14px; border-radius: 2px; opacity: .95; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(112vh) rotate(720deg); } }

.bg {
  position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(180deg, #8fc0ff 0%, #cfe6ff 55%, #a7d9a0 100%);
  transition: background 0.6s ease;
}

.app {
  position: relative; height: 100dvh; max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
}

/* ---------- HUD ---------- */
.hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 6px 6px; flex: 0 0 auto;
}
.level-label { font-size: 20px; font-weight: 700; text-shadow: 0 1px 4px rgba(0,0,0,.25); }
.icon-btn {
  border: none; background: rgba(255,255,255,.95); color: var(--accent);
  width: 44px; height: 44px; border-radius: 50%; font-size: 20px; font-weight: 800;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.22); line-height: 1;
}
.icon-btn:active { transform: translateY(1px); }
.hud-right { display: flex; align-items: center; gap: 8px; }
@media (max-width: 360px) {
  .icon-btn { width: 40px; height: 40px; font-size: 18px; }
  .hud-right { gap: 6px; }
  .level-label { font-size: 18px; }
}
.coins {
  display: flex; align-items: center; gap: 5px; font-weight: 700;
  background: rgba(0,0,0,.18); padding: 6px 12px; border-radius: 20px; backdrop-filter: blur(4px);
}
.coin-dot { color: #ffd34d; }

/* ---------- Board (crossword grid) ---------- */
.board {
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: grid; place-content: center; align-content: center;
  gap: var(--gap, 4px);
  grid-template-columns: repeat(var(--cols, 1), var(--tile, 40px));
  grid-template-rows: repeat(var(--rows, 1), var(--tile, 40px));
  padding: 8px 0;
}
.cell {
  width: var(--tile, 40px); height: var(--tile, 40px);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: calc(var(--tile, 40px) * 0.52);
  background: var(--tile-empty);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.cell.filled { background: var(--accent); box-shadow: 0 2px 6px rgba(0,0,0,.22); }
.cell.hint.filled { background: #2fa86a; }
.cell.pop { animation: pop .28s ease; }
.cell.flash { animation: flash .5s ease; }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes flash { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.6); } }

/* ---------- Preview bubble (absolute — must NOT reflow the wheel mid-swipe) ---------- */
.preview {
  position: absolute; left: 50%; top: 46px; transform: translateX(-50%); z-index: 4;
  min-width: 56px; height: 38px; padding: 0 16px;
  background: var(--accent); color: #fff; font-weight: 800; letter-spacing: 2px;
  font-size: 20px; border-radius: 18px; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .12s ease;
  box-shadow: 0 3px 10px rgba(0,0,0,.25);
}
.preview.show { opacity: 1; }
.preview.shake { animation: shake .35s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-7px)} 40%{transform:translateX(7px)} 60%{transform:translateX(-5px)} 80%{transform:translateX(5px)} }

.toast {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%) translateY(-6px);
  background: rgba(0,0,0,.7); color: #fff; padding: 8px 16px; border-radius: 20px;
  font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 5;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Bottom: controls + wheel ---------- */
.bottom { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; padding-bottom: 8px; }
.controls { display: flex; gap: 14px; margin-bottom: 4px; }
.ctrl-btn {
  position: relative; border: none; cursor: pointer; color: #fff;
  background: rgba(255,255,255,.25); width: 50px; height: 50px; border-radius: 50%;
  font-size: 22px; backdrop-filter: blur(4px);
}
.ctrl-btn .cost {
  position: absolute; bottom: -6px; right: -6px; background: rgba(0,0,0,.55);
  font-size: 11px; padding: 2px 6px; border-radius: 10px; display: flex; gap: 2px; align-items: center;
}

.wheel {
  position: relative; width: min(82vw, 340px, 44dvh); aspect-ratio: 1;
  background: rgba(255,255,255,.5); border-radius: 50%; backdrop-filter: blur(3px);
  touch-action: none; box-shadow: 0 4px 24px rgba(0,0,0,.15);
}
.wheel-lines { position: absolute; inset: 0; pointer-events: none; }
.wheel-lines polyline { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.wheel-lines .joint { fill: var(--accent); }
.node {
  position: absolute; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800;
  font-size: 26px; box-shadow: 0 3px 8px rgba(0,0,0,.25); cursor: pointer;
  transition: transform .08s ease;
}
.node.sel { transform: scale(1.12); filter: brightness(1.12); }
.node.pulse { animation: pop .2s ease; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45); backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.overlay-card {
  background: #fff; color: var(--ink); border-radius: 22px; padding: 28px 26px;
  width: min(86vw, 360px); text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.3);
  animation: rise .35s ease;
}
@keyframes rise { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.overlay-emoji { font-size: 48px; }
.overlay-card h2 { margin: 8px 0 4px; }
.overlay-sub { color: var(--accent); font-weight: 800; font-size: 18px; margin: 0 0 18px; }
.help-list { text-align: left; line-height: 1.7; color: #444; padding-left: 20px; margin: 12px 0 20px; }
.primary-btn {
  border: none; background: var(--accent); color: #fff; font-weight: 800; font-size: 17px;
  padding: 13px 32px; border-radius: 26px; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.primary-btn:active { transform: translateY(1px); }

/* ---------- About / menu panel ---------- */
.about-version { color: #8a90a2; font-size: 13px; font-weight: 700; margin: -2px 0 18px; }
.bmc-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  background: #ffdd00; color: #000; font-weight: 800; font-size: 16px;
  padding: 13px 18px; border-radius: 16px; text-decoration: none; margin-bottom: 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,.15);
}
.bmc-btn:active { transform: translateY(1px); }
.secondary-btn {
  display: block; width: 100%; border: none; background: #eef0f6; color: #333;
  font-weight: 700; font-size: 15px; padding: 12px; border-radius: 16px; cursor: pointer; margin-bottom: 12px;
}
.secondary-btn:active { transform: translateY(1px); }
#aboutOverlay .primary-btn { width: 100%; }
.overlay-actions { display: flex; gap: 10px; }
.overlay-actions .secondary-btn, .overlay-actions .primary-btn { flex: 1; margin: 0; padding: 13px 10px; }
.splash-version { margin: 18px 0 0; font-size: 12px; font-weight: 600; opacity: .7; letter-spacing: .5px; }
