/*
 * Block Puzzle — Game Anything
 * Shell: /play/shared/ga-casual-shell.css (class ga-casual-scope on #bp-app).
 * AI / themes: set --bp-b0…--bp-b8, --bp-accent, --bp-accent2 on .bp-app or :root.
 */
.bp-embed #bp-app {
  --bp-bg0: #070b14;
  --bp-bg1: #111b2d;
  --bp-panel: rgba(15, 23, 42, 0.72);
  --bp-panel-border: rgba(56, 189, 248, 0.2);
  --bp-text: #f1f5f9;
  --bp-muted: #94a3b8;
  --bp-accent: #3b82f6;
  --bp-accent2: #38bdf8;
  --bp-danger: #fb7185;
  --bp-radius: 20px;
  --bp-radius-sm: 14px;
  --bp-shadow: 0 24px 56px rgba(2, 6, 23, 0.55);
  --bp-cell-gap: 3px;
  --bp-board-pad: 10px;
  --bp-b0: #3b82f6;
  --bp-b1: #6366f1;
  --bp-b2: #22d3ee;
  --bp-b3: #fbbf24;
  --bp-b4: #f472b6;
  --bp-b5: #a78bfa;
  --bp-b6: #38bdf8;
  --bp-b7: #4ade80;
  --bp-b8: #fb923c;
}

.ga-casual-scope.bp-app {
  --bp-bg0: var(--ga-bg-abyss);
  --bp-bg1: var(--ga-bg-mid);
  --bp-panel: var(--ga-surface);
  --bp-panel-border: var(--ga-border);
  --bp-text: var(--ga-text);
  --bp-muted: var(--ga-muted);
  --bp-accent: var(--ga-blue);
  --bp-accent2: var(--ga-sky);
  --bp-danger: var(--ga-danger);
}

.bp-embed #bp-app,
.bp-embed #bp-app *,
.bp-embed #bp-app *::before,
.bp-embed #bp-app *::after {
  box-sizing: border-box;
}

.bp-embed #bp-app {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background: #000000;
  color: var(--bp-text);
  font-family: "Outfit", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.bp-embed #bp-app code {
  font-size: 0.88em;
  color: var(--bp-accent2);
}

.bp-app {
  width: 100%;
  max-width: none;
  margin: 0;
  /* Embedded in Game Worlds: fit container instead of viewport */
  min-height: 100%;
  position: relative;
  /* Border sits at edges; safe-area only (no extra gutter) */
  padding: max(0px, env(safe-area-inset-top)) max(0px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom))
    max(0px, env(safe-area-inset-left));
}

/* Main menu: full-area overlay + centered card (same idea as .cr-ui-overlay) */
.bp-screen-menu:not([hidden]) {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0px, env(safe-area-inset-top)) max(0px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom))
    max(0px, env(safe-area-inset-left));
  background: rgba(2, 6, 23, 0.4);
  backdrop-filter: blur(10px) saturate(1.05);
  -webkit-backdrop-filter: blur(10px) saturate(1.05);
}

.bp-ui-overlay-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* How / daily — same centered card as menu (must not match [hidden] or display:flex overrides native hidden) */
.bp-screen:not(.bp-screen-menu):not(.bp-screen-play):not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: max(0px, env(safe-area-inset-top)) max(0px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom))
    max(0px, env(safe-area-inset-left));
  box-sizing: border-box;
}

.bp-screen:not(.bp-screen-menu):not(.bp-screen-play):not([hidden]) .bp-panel {
  width: min(var(--ga-puzzle-menu-max), 100%);
  max-width: min(var(--ga-puzzle-menu-max), 100%);
}

.bp-screen[hidden] {
  display: none !important;
}

.bp-screen-menu .bp-panel.bp-panel-hero {
  width: min(var(--ga-puzzle-menu-max), 100%);
  max-width: min(var(--ga-puzzle-menu-max), 100%);
}

.bp-screen:not([hidden]) .bp-panel {
  animation: bp-screen-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.bp-screen[data-bp-screen="menu"]:not([hidden]) .bp-panel {
  animation: none;
}

@keyframes bp-screen-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bp-screen:not([hidden]) .bp-panel {
    animation: none;
  }
}

.bp-panel {
  background: var(--bp-panel);
  border: 1px solid var(--bp-panel-border);
  border-radius: var(--bp-radius);
  padding: clamp(24px, 5.5vw, 34px) clamp(22px, 5vw, 30px);
  box-shadow: var(--bp-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(16px);
  transition:
    border-color 0.3s ease,
    box-shadow 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.bp-kicker {
  margin: 0 0 6px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--bp-muted);
}

.bp-lead {
  margin: 0 0 18px;
  line-height: 1.55;
  color: var(--bp-muted);
  font-size: 1.02rem;
}

.bp-menu-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 11px;
  margin-bottom: 8px;
}

.bp-btn {
  appearance: none;
  border: 1px solid var(--bp-panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--bp-text);
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  min-height: 48px;
  padding: 14px 18px;
  border-radius: var(--bp-radius-sm);
  cursor: pointer;
  transition:
    transform 0.2s cubic-bezier(0.34, 1.18, 0.64, 1),
    background 0.25s ease,
    border-color 0.25s ease,
    box-shadow 0.3s ease;
}

.bp-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(56, 189, 248, 0.28);
}

.bp-btn:active {
  transform: scale(0.98);
}

.bp-btn-primary {
  border-color: rgba(37, 99, 235, 0.55);
  background: linear-gradient(135deg, #2563eb, var(--bp-accent) 48%, var(--bp-accent2));
  color: #fff;
  box-shadow: 0 10px 32px rgba(37, 99, 235, 0.42);
}

.bp-btn-primary:hover {
  box-shadow: 0 14px 36px rgba(37, 99, 235, 0.5);
}

.bp-btn-ghost {
  background: transparent;
}

.bp-list {
  margin: 0 0 18px;
  padding-left: 1.1rem;
  color: var(--bp-muted);
  line-height: 1.55;
}

.bp-muted {
  color: var(--bp-muted);
}

.bp-small {
  font-size: 0.85rem;
}

.bp-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Play layout — needs viewport height when active (menu is not) */
.bp-screen-play:not([hidden]) {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.bp-screen-play {
  padding-bottom: 8px;
}

.bp-play-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#bp-app[data-bp-mode="mission"] .bp-play-shell {
  gap: 0;
}

/* Top HUD — puzzle-maze: scores left, Menu/Restart right */
.bp-play-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.62);
  border: 1px solid var(--bp-panel-border);
  box-shadow: 0 10px 18px rgba(2, 6, 23, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.bp-hud-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.bp-hud-chip {
  font-size: 12px;
  color: #cbd5e1;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(125, 211, 252, 0.28);
}

.bp-hud-chip strong {
  color: #f8fafc;
  font-weight: 800;
}

.bp-hud-chip-combo {
  color: #cbd5e1;
}

.bp-hud-chip-combo strong {
  color: var(--bp-accent2);
}

.bp-hud-streak {
  font-size: 11px;
  color: var(--bp-muted);
  font-weight: 600;
}

.bp-hud-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.bp-btn-hud {
  min-height: 0;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 10px;
}

.bp-daily-line {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--bp-accent2);
  font-weight: 600;
}

.bp-mission {
  margin-top: 10px;
  margin-bottom: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--bp-panel-border);
  font-size: 0.88rem;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px 10px;
}

/* Win over `[hidden]` losing to `.bp-mission { display:flex }` in cascade */
.bp-mission[hidden] {
  display: none !important;
}

.bp-mission-row {
  flex: 1 1 0;
  min-width: 0;
  padding: 4px 4px;
  color: var(--bp-muted);
  text-align: center;
  line-height: 1.25;
}

.bp-mission-row--done {
  color: var(--bp-accent2);
}

/* Pieces column to the left of the board (play only) */
.bp-play-field {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
}

.bp-play-field .bp-tray-wrap {
  flex: 0 0 auto;
  width: min(112px, 26vw);
  min-width: 96px;
  padding: 10px 10px 12px;
}

.bp-play-field .bp-tray {
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, auto);
  gap: 8px;
}

.bp-play-field .bp-slot {
  min-height: 72px;
  padding: 6px;
}

.bp-play-field .bp-board-wrap {
  flex: 1 1 220px;
  min-width: 0;
  max-width: 100%;
}

.bp-play-field .bp-tray-label {
  text-align: center;
}

@media (max-width: 420px) {
  .bp-play-field {
    flex-direction: column;
    align-items: stretch;
  }

  .bp-play-field .bp-tray-wrap {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .bp-play-field .bp-tray {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: none;
  }

  .bp-play-field .bp-board-wrap {
    flex: none;
  }
}

.bp-board-wrap {
  position: relative;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  border-radius: calc(var(--bp-radius) + 4px);
  padding: var(--bp-board-pad);
  border: 1px solid var(--bp-panel-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.bp-board {
  --bp-n: 8;
  display: grid;
  grid-template-columns: repeat(var(--bp-n), 1fr);
  grid-template-rows: repeat(var(--bp-n), 1fr);
  grid-auto-rows: 1fr;
  gap: var(--bp-cell-gap);
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: min(72vh, 440px);
  margin: 0 auto;
  justify-items: stretch;
  align-items: stretch;
  transition: transform 0.08s ease;
}

.bp-board--shake {
  animation: bp-shake 0.32s ease;
}

@keyframes bp-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Native <button> min-height / inline sizing breaks square grid cells — reset + aspect-ratio */
.bp-cell {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  margin: 0;
  border: none;
  padding: 0;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  align-self: stretch;
  justify-self: stretch;
  overflow: hidden;
  line-height: 0;
  font-size: 0;
  color: transparent;
}

.bp-cell:focus-visible {
  outline: 2px solid var(--bp-accent);
  outline-offset: 2px;
}

.bp-cell--c0 {
  background: linear-gradient(145deg, #6a9dff, #355cab);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.bp-cell--c1 {
  background: linear-gradient(145deg, #8b74ff, #4a32b8);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.bp-cell--c2 {
  background: linear-gradient(145deg, #55e6d0, #239f8c);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.bp-cell--c3 {
  background: linear-gradient(145deg, #ffc266, #c97a1e);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.bp-cell--c4 {
  background: linear-gradient(145deg, #ff73aa, #c23d72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.bp-cell--c5 {
  background: linear-gradient(145deg, #aa7dff, #6237c4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.bp-cell--c6 {
  background: linear-gradient(145deg, #6ee6ff, #2a9bb8);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.bp-cell--c7 {
  background: linear-gradient(145deg, #c8f56e, #7fb02e);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.bp-cell--c8 {
  background: linear-gradient(145deg, #ff8a6e, #c44a32);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.25);
}

.bp-cell--clear {
  animation: bp-line-pop 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
  z-index: 2;
}

@keyframes bp-line-pop {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  40% {
    transform: scale(1.08);
    filter: brightness(1.35) saturate(1.2);
  }
  100% {
    transform: scale(0.92);
    filter: brightness(0.85);
    opacity: 0.85;
  }
}

.bp-tray-wrap {
  background: var(--bp-panel);
  border: 1px solid var(--bp-panel-border);
  border-radius: var(--bp-radius);
  padding: 12px 12px 14px;
}

.bp-tray-label {
  margin: 0 0 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--bp-muted);
}

.bp-tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  align-items: stretch;
}

.bp-slot {
  min-height: 92px;
  border-radius: var(--bp-radius-sm);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  touch-action: none;
  cursor: grab;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.bp-slot:active {
  cursor: grabbing;
}

.bp-slot--selected {
  border-color: var(--bp-accent2);
  box-shadow: 0 0 0 2px rgba(61, 217, 195, 0.25);
}

.bp-slot--empty {
  opacity: 0.45;
  cursor: default;
}

.bp-slot-inner {
  display: grid;
  gap: 3px;
  width: 100%;
  max-width: 88px;
  aspect-ratio: 1 / 1;
}

.bp-mini {
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
}

.bp-mini--on {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.bp-mini--c0 {
  background: linear-gradient(145deg, #6a9dff, #355cab);
}
.bp-mini--c1 {
  background: linear-gradient(145deg, #8b74ff, #4a32b8);
}
.bp-mini--c2 {
  background: linear-gradient(145deg, #55e6d0, #239f8c);
}
.bp-mini--c3 {
  background: linear-gradient(145deg, #ffc266, #c97a1e);
}
.bp-mini--c4 {
  background: linear-gradient(145deg, #ff73aa, #c23d72);
}
.bp-mini--c5 {
  background: linear-gradient(145deg, #aa7dff, #6237c4);
}
.bp-mini--c6 {
  background: linear-gradient(145deg, #6ee6ff, #2a9bb8);
}
.bp-mini--c7 {
  background: linear-gradient(145deg, #c8f56e, #7fb02e);
}
.bp-mini--c8 {
  background: linear-gradient(145deg, #ff8a6e, #c44a32);
}

/* Drag ghost: default absolute in .bp-board-wrap; while dragging, JS reparents to document.body
   and sets position:fixed + viewport px so layout/backdrop-filter on ancestors cannot skew placement. */
.bp-ghost {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  grid-gap: 3px;
  pointer-events: none;
  z-index: 20;
  opacity: 0.88;
  transition: opacity 0.1s ease;
}

.bp-ghost--on {
  display: grid;
}

.bp-ghost--bad {
  opacity: 0.45;
  filter: saturate(0.5);
}

.bp-ghost-cell {
  border-radius: 6px;
  background: transparent;
}

.bp-ghost-cell--on {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  outline: 2px solid rgba(255, 255, 255, 0.35);
}

.bp-float-host {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}

.bp-float-score {
  position: fixed;
  transform: translate(-50%, -50%) scale(0.7);
  font-weight: 800;
  font-size: 1.35rem;
  color: #fff;
  text-shadow: 0 2px 10px rgba(124, 92, 255, 0.6);
  opacity: 0;
  transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
}

.bp-float-score--show {
  opacity: 1;
  transform: translate(-50%, -120%) scale(1);
}

.bp-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(20, 24, 44, 0.92);
  border: 1px solid var(--bp-panel-border);
  color: var(--bp-text);
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  z-index: 80;
  box-shadow: var(--bp-shadow);
  max-width: calc(100% - 32px);
  text-align: center;
}

.bp-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
  animation: bp-modal-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ga-casual-scope .bp-modal.ga-game-overlay {
  z-index: 70;
}

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

.bp-modal-panel {
  animation: bp-modal-panel-in 0.42s cubic-bezier(0.34, 1.18, 0.64, 1) both;
}

@keyframes bp-modal-panel-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bp-modal {
    animation: none;
  }
  .bp-modal-panel {
    animation: none;
  }
}

.bp-modal-panel h3 {
  margin: 0 0 10px;
  font-size: 1.45rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* [hidden] must win over .bp-modal { display:flex } when embedded after site CSS */
.bp-modal[hidden] {
  display: none !important;
}

/*
 * Game Worlds: global `.game-worlds-play-shell #gamebox { flex: 0 1 auto }` plus `h-full`
 * on #gamebox/#bp-app collapses height (percent heights need a definite parent). Fill the
 * fixed shell and let the play column distribute space correctly.
 */
.game-worlds-body .game-worlds-play-shell #gamebox.bp-embed {
  flex: 1 1 auto;
  align-self: stretch;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.game-worlds-body .game-worlds-play-shell .bp-embed #bp-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.game-worlds-body .game-worlds-play-shell .bp-embed .bp-screens {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.game-worlds-body .game-worlds-play-shell .bp-embed .bp-screen-play:not([hidden]) {
  flex: 1 1 auto;
  min-height: 0;
}

.game-worlds-body .game-worlds-play-shell .bp-embed .bp-play-shell {
  flex: 1 1 auto;
  min-height: 0;
}

.game-worlds-body .game-worlds-play-shell .bp-embed .bp-play-field {
  flex: 1 1 auto;
  min-height: 0;
}
