/* Fuse Blocks — mobile-first, fits phone viewport */

.fuse-page {
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.fuse-app {
  width: min(430px, 100%);
  margin: 0 auto;
  padding: 8px 10px max(12px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  /* Fit typical phone: topbar + chrome + board without page scroll */
  min-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fuse-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.fuse-title {
  margin: 0;
  font-size: clamp(1.2rem, 5vw, 1.45rem);
  letter-spacing: 0.01em;
}

.fuse-hint {
  margin: 2px 0 0;
  color: #94a3b8;
  font-size: 0.78rem;
  line-height: 1.35;
}

.fuse-sync {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: #94a3b8;
  line-height: 1.35;
}

.fuse-sync a {
  color: #93c5fd;
  font-weight: 700;
}

.fuse-sync-status {
  font-weight: 700;
}

.fuse-sync-status[data-kind="ok"] { color: #34d399; }
.fuse-sync-status[data-kind="pending"] { color: #fbbf24; }
.fuse-sync-status[data-kind="err"] { color: #f87171; }

.fuse-scores {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.fuse-stat {
  min-width: 58px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.22);
  text-align: center;
}

.fuse-stat-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
}

.fuse-stat-value {
  display: block;
  font-weight: 800;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.fuse-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.fuse-next {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fuse-next-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fuse-next-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fuse-hold-tile.is-empty {
  opacity: 0.45;
  border: 1px dashed rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.5);
  color: #64748b;
  box-shadow: none;
}

.fuse-powers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.fuse-powers[hidden] {
  display: none !important;
}

.fuse-power {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 44px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.9);
  color: #e2e8f0;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.fuse-power span {
  color: #fbbf24;
  font-size: 0.68rem;
}

.fuse-power.active {
  border-color: #fbbf24;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.3);
}

.fuse-power:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.fuse-tool-hint {
  margin: 0;
  min-height: 1.1em;
  color: #93c5fd;
  font-size: 0.75rem;
  font-weight: 600;
}

.fuse-tool-hint[hidden] {
  display: none !important;
}

.fuse-start-picks {
  margin: 0 0 12px;
}

.fuse-start-label {
  margin: 0 0 8px;
  color: #94a3b8;
  font-size: 0.8rem;
  font-weight: 700;
}

.fuse-start-choices {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.fuse-start-choice {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: #1e293b;
  color: #f8fafc;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
}

.fuse-start-choice.is-selected {
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.35);
}

.fuse-cell.tool-target {
  outline: 2px solid #60a5fa;
  outline-offset: -2px;
}

.fuse-cell.swap-selected {
  outline: 2px solid #e879f9;
  outline-offset: -2px;
}

.fuse-tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.fuse-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: #1e293b;
  color: #e2e8f0;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}

.fuse-tool-btn.secondary {
  background: transparent;
}

.fuse-tool-btn.active {
  border-color: #fbbf24;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.35);
}

.fuse-tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#fuse-sparks-pill:disabled {
  opacity: 1;
  cursor: default;
  border-color: rgba(250, 204, 21, 0.45);
  color: #fef08a;
}

#fuse-sparks-pill .fuse-tool-icon {
  color: #fde047;
  font-size: 1rem;
  line-height: 1;
}

#fuse-sparks-pill .fuse-tool-cost {
  background: rgba(250, 204, 21, 0.35);
  color: #fef9c3;
  font-size: 0.85rem;
  font-weight: 800;
}

.fuse-tool-btn.is-muted {
  opacity: 0.7;
  border-style: dashed;
}

.fuse-tool-cost {
  min-width: 1.2em;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
  font-size: 0.75rem;
}

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

.fuse-board {
  --cols: 5;
  --rows: 7;
  --gap: 5px;
  /* Cap board to remaining viewport so whole game fits on phones */
  width: min(100%, calc((100dvh - 220px) * 5 / 7), 400px);
  aspect-ratio: 5 / 7;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: var(--gap);
  padding: var(--gap);
  box-sizing: border-box;
  background: rgba(2, 6, 23, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 14px;
  user-select: none;
}

.fuse-cell {
  position: relative;
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.55);
  min-width: 0;
  min-height: 0;
  touch-action: manipulation;
  cursor: pointer;
}

.fuse-cell.col-hot {
  background: rgba(37, 99, 235, 0.28);
}

.fuse-cell.col-merge,
.fuse-cell.merge-ready {
  outline: 2px solid #34d399;
  outline-offset: -2px;
  background: rgba(52, 211, 153, 0.2);
}

.fuse-cell.clear-target {
  outline: 2px solid #fbbf24;
  outline-offset: -2px;
}

.fuse-cell.clear-too-costly {
  outline: 2px solid rgba(248, 113, 113, 0.7);
  outline-offset: -2px;
  opacity: 0.72;
}

.fuse-tile {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: clamp(0.85rem, 4.2vw, 1.25rem);
  color: #0b1220;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.12s ease, filter 0.12s ease;
  pointer-events: none;
  position: relative;
}

/* Must follow .fuse-tile so fixed positioning wins for the drop ghost */
.fuse-tile.fuse-ghost {
  position: fixed;
  z-index: 40;
  margin: 0;
  transition: none;
  will-change: transform;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.fuse-clear-cost {
  position: absolute;
  top: 2px;
  right: 3px;
  min-width: 1.1em;
  padding: 0 3px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.82);
  color: #fbbf24;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}

.fuse-cell.clear-too-costly .fuse-clear-cost {
  color: #fca5a5;
}

.fuse-next-tile {
  width: 44px;
  height: 44px;
  pointer-events: none;
  flex-shrink: 0;
}

.fuse-tile.pop {
  animation: fuse-pop 0.22s ease;
}

.fuse-tile.fuse-flash {
  animation: fuse-flash 0.28s ease;
}

@keyframes fuse-pop {
  0% { transform: scale(0.55); }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes fuse-flash {
  0% { filter: brightness(1.6); transform: scale(1.12); }
  100% { filter: brightness(1); transform: scale(1); }
}

/* Value colors */
.v2 { background: #7dd3fc; }
.v4 { background: #38bdf8; }
.v8 { background: #22d3ee; color: #082f49; }
.v16 { background: #34d399; }
.v32 { background: #a3e635; }
.v64 { background: #fbbf24; }
.v128 { background: #fb923c; }
.v256 { background: #f87171; }
.v512 { background: #e879f9; }
.v1024 { background: #c084fc; }
.v2048 { background: #f472b6; }
.v4096,
.v8192,
.v16384 {
  background: linear-gradient(145deg, #fde68a, #f59e0b);
}

.v-dynamic {
  color: #fff;
}

.fuse-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 6, 23, 0.72);
  border-radius: 14px;
  padding: 16px;
  z-index: 5;
}

.fuse-overlay[hidden] {
  display: none !important;
}

.fuse-unlock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 6, 23, 0.55);
  border-radius: 14px;
  padding: 16px;
  z-index: 6;
  pointer-events: auto;
  animation: fuse-unlock-backdrop 0.25s ease;
}

.fuse-unlock[hidden] {
  display: none !important;
}

.fuse-unlock-card {
  width: min(100%, 260px);
  text-align: center;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 16px;
  padding: 20px 16px 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  animation: fuse-unlock-pop 0.38s cubic-bezier(0.22, 1.2, 0.36, 1);
}

.fuse-unlock-eyebrow {
  margin: 0 0 12px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #93c5fd;
}

.fuse-unlock-tile {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  font-size: 1.45rem;
  border-radius: 14px;
  animation: fuse-unlock-tile-pulse 0.9s ease infinite alternate;
}

.fuse-unlock-text {
  margin: 0;
  color: #cbd5e1;
  font-size: 0.9rem;
  line-height: 1.45;
}

.fuse-unlock-hint {
  margin: 14px 0 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748b;
}

@keyframes fuse-unlock-backdrop {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fuse-unlock-pop {
  from {
    opacity: 0;
    transform: scale(0.82) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes fuse-unlock-tile-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.fuse-overlay-card {
  width: min(100%, 280px);
  text-align: center;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 14px;
  padding: 18px 16px;
}

.fuse-overlay-card h2 {
  margin: 0 0 6px;
  font-size: 1.25rem;
}

.fuse-overlay-card p {
  margin: 0 0 14px;
  color: #94a3b8;
  font-size: 0.9rem;
}

.fuse-overlay-actions {
  display: grid;
  gap: 8px;
}

.fuse-primary-btn {
  min-height: 44px;
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: #2563eb;
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
}

.fuse-secondary-btn {
  min-height: 44px;
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  background: transparent;
  color: #cbd5e1;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}

.fuse-help {
  margin: 0;
  color: #64748b;
  font-size: 0.75rem;
  line-height: 1.4;
  text-align: center;
  padding: 0 4px;
}

.fuse-leaderboard {
  margin-top: 8px;
  padding: 14px 12px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.72);
}

.fuse-leaderboard-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.fuse-leaderboard-lead {
  margin: 0 0 12px;
  color: #94a3b8;
  font-size: 0.78rem;
  line-height: 1.4;
}

.fuse-leaderboard-lead a {
  color: #93c5fd;
  font-weight: 700;
}

.fuse-leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.fuse-leaderboard-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.45);
}

.fuse-leaderboard-row.is-you {
  border: 1px solid rgba(96, 165, 250, 0.55);
  background: rgba(37, 99, 235, 0.18);
}

.fuse-leaderboard-rank {
  font-weight: 800;
  color: #93c5fd;
  font-variant-numeric: tabular-nums;
}

.fuse-leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.9rem;
}

.fuse-leaderboard-score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #f8fafc;
}

.fuse-leaderboard-empty {
  margin: 0;
  color: #64748b;
  font-size: 0.85rem;
}

/* Very short phones: tighten chrome so board stays playable */
@media (max-height: 640px) {
  .fuse-hint,
  .fuse-help {
    display: none;
  }

  .fuse-app {
    gap: 6px;
    padding-top: 4px;
  }

  .fuse-board {
    width: min(100%, calc((100dvh - 170px) * 5 / 7));
  }
}

@media (min-width: 520px) {
  .fuse-app {
    padding-top: 14px;
  }

  .fuse-card:hover {
    border-color: rgba(96, 165, 250, 0.5);
  }
}
