/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --cell-size:   40px;
  --gap:         3px;
  --rack-tile:   22px;

  --bg:          #0A0A1A;
  --surface:     #13132B;
  --surface2:    #1C1C3A;
  --border:      #2A2A50;
  --text:        #E8E8FF;
  --text-dim:    #7777AA;
  --accent:      #5566FF;
  --danger:      #FF4466;
  --success:     #44FF88;
  --gold:        #FFD700;
}

/* ── ZeroLabs splash ─────────────────────────────────────────────────────── */
#splash {
  position: fixed;
  inset: 0;
  background: #0A0A1A;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 9999;
}

#splash-tagline {
  color: #64ffda;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 300;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  text-indent: 0.4em;
  opacity: 0;
}

#splash-logo {
  width: 100px;
  height: 100px;
  color: #64ffda;
  opacity: 0;
  transition: opacity 0.3s;
}

#splash-logo svg {
  width: 100%;
  height: 100%;
  fill: none;
  display: block;
}

#splash-logo #B { opacity: 0; }

/* ── Reset / base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  overflow: hidden;
  padding: 6px 8px;
  gap: 6px;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
#header {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  align-items: stretch;
  gap: 6px;
  flex-shrink: 0;
}

#btn-back, #btn-chat {
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
#btn-back:hover, #btn-chat:hover {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(85, 102, 255, 0.08);
}

.player-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  border-radius: 12px;
  background: var(--surface);
  min-width: 0;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}

.player-info.active {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(85, 102, 255, 0.4);
}

#p2-info { align-items: center; }

.player-name {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.player-score {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
}

#turn-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 2px solid rgba(255, 140, 0, 0.45);
  border-radius: 14px;
  padding: 6px 10px;
  box-shadow: 0 0 14px rgba(255, 140, 0, 0.15);
}

#turn-score-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #FF8C00;
  border-radius: 8px;
  padding: 4px 14px;
  min-width: 72px;
}

#turn-score-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  display: inline-block;
}

@keyframes scorePop {
  0%   { transform: scale(1);    opacity: 1; }
  35%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}

#turn-score-value.score-pop {
  animation: scorePop 0.35s ease-out forwards;
}


#turn-label {
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 160, 40, 0.85);
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── Board ───────────────────────────────────────────────────────────────── */
#board-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  display: grid;
  grid-template-columns: repeat(8, var(--cell-size));
  grid-template-rows:    repeat(8, var(--cell-size));
  gap: var(--gap);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: #222244;
  border: 1px solid #4444AA;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.08s, box-shadow 0.08s;
}

.cell:hover { filter: brightness(1.15); }

/* Multiplier empty cells */
.cell.mult-2 { background: #1A1E3A; border-color: #3A3E6A; }
.cell.mult-3 { background: #1E1A30; border-color: #5A3A6A; }

.mult-label {
  font-size: calc(var(--cell-size) * 0.28);
  font-weight: 700;
  pointer-events: none;
  color: rgba(255,255,255,0.45);
}
.cell.mult-2 .mult-label { color: #8899DD; }
.cell.mult-3 .mult-label { color: var(--gold); }

/* All star tiles use a large ★ centered in the cell */
.cell.tile.star-tile .tile-symbol {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 18%;
  font-size: calc(var(--cell-size) * 1.05);
  line-height: 1;
  z-index: 2;
}

.cell.tile.star-tile .mult-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.24);
  font-weight: 900;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.7);
  z-index: 3;
  line-height: 1;
  pointer-events: none;
}

/* Mult label on non-star colored tiles: centered, same layout as star tiles */
.cell.tile:not(.star-tile) .mult-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.24);
  font-weight: 900;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.7);
  z-index: 2;
  line-height: 1;
  pointer-events: none;
}

/* Floating score text */
@keyframes scoreFloat {
  0%   { transform: translateX(-50%) translateY(0);     opacity: 1; }
  15%  { transform: translateX(-50%) translateY(-8px);  opacity: 1; }
  100% { transform: translateX(-50%) translateY(-60px); opacity: 0; }
}

.score-float {
  position: fixed;
  pointer-events: none;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-weight: 900;
  font-size: 18px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.95), 0 0 16px rgba(0,0,0,0.6);
  animation: scoreFloat 1.0s ease-out forwards;
  z-index: 500;
  white-space: nowrap;
}

/* Match clear animation */
@keyframes matchPop {
  0%   { transform: scale(1.0);  filter: brightness(1.0); opacity: 1; }
  30%  { transform: scale(1.25); filter: brightness(2.8); opacity: 1; }
  100% { transform: scale(0);    filter: brightness(1.0); opacity: 0; }
}

.cell.match-clear {
  animation: matchPop 0.75s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  pointer-events: none;
  z-index: 3;
}

/* Filled tile states */
.cell.tile {
  border-color: transparent;
  border-radius: 7px;
  cursor: pointer;
}

.cell.tile:hover { transform: scale(1.06); z-index: 2; }

.cell.current-turn {
  transform: scale(1.04);
  z-index: 1;
  cursor: grab;
}

.cell.ghost {
  opacity: 0.45;
  transform: scale(1.02);
  cursor: crosshair;
  pointer-events: none;
}

.cell.permanent { cursor: default; }
.cell.permanent:hover { transform: none; }
.cell.tile.permanent:not(.star-tile):hover { filter: saturate(0.76) brightness(0.94); }

/* Player tint: subtle inner shadow so you can tell who placed what */
.cell.owner-0 { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.15); }
.cell.owner-1 { box-shadow: inset 0 0 0 2px rgba(0,0,0,0.25); }

.tile-symbol {
  font-size: calc(var(--cell-size) * 0.48);
  pointer-events: none;
  line-height: 1;
}

/* ── Star / wildcard tiles ───────────────────────────────────────────────── */
@keyframes rotateCW {
  to { transform: rotate(360deg); }
}

.cell.tile.star-tile { overflow: hidden; }

/* Spinning rainbow ring */
.cell.tile.star-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: conic-gradient(#ff0080, #ff6600, #ffdd00, #00dd55, #3399ff, #cc44ff, #ff0080);
  animation: rotateCW 2.5s linear infinite;
  filter: blur(2px);
  pointer-events: none;
  z-index: 0;
}

/* Rectangular center fill — leaves a uniform ring at all 4 edges */
.cell.tile.star-tile::after {
  content: '';
  position: absolute;
  inset: 3px;
  background: #1A1A30;
  border-radius: 5px;
  pointer-events: none;
  z-index: 1;
}

.cell.star-tile {
  background: #1A1A30 !important;
  border: 1px solid rgba(192,192,192,0.7) !important;
  box-shadow: 0 0 6px rgba(192,192,192,0.3) !important;
}

.cell.star-tile .tile-symbol {
  color: #C0C0C0;
  text-shadow: 0 0 6px rgba(192,192,192,0.8);
}

.rack-tile.star-tile {
  background: #1A1A30;
  border: 1px solid rgba(192,192,192,0.6);
  color: #C0C0C0;
  text-shadow: 0 0 5px rgba(192,192,192,0.7);
  font-size: calc(var(--rack-tile) * 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.drag-tile.star-tile {
  background: #1A1A30;
  border: 1px solid rgba(192,192,192,0.6);
  color: #C0C0C0;
  text-shadow: 0 0 5px rgba(192,192,192,0.7);
}

/* ── Rack ────────────────────────────────────────────────────────────────── */
#rack-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

#rack {
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  gap: 8px;
  height: calc(var(--rack-tile) * 3 + 26px);
  overflow: hidden;
}

.rack-slot {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 4px;
  background: var(--surface);
  border-radius: 12px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.rack-slot:hover  { border-color: var(--border); }
.rack-slot.selected {
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(85,102,255,0.45);
}
.rack-slot.placed { border-color: var(--border); }

.recall-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.recall-btn:hover {
  color: var(--accent);
  background: rgba(85, 102, 255, 0.12);
}

/* The 3-tile display area — fixed square so H and V both fit */
.piece-tiles {
  display: flex;
  gap: 3px;
  align-items: center;
  justify-content: center;
  width: calc(var(--rack-tile) * 3 + 6px);
  height: calc(var(--rack-tile) * 3 + 6px);
  touch-action: none;
}

.piece-tiles.orient-horizontal { flex-direction: row;    align-items: center; }
.piece-tiles.orient-vertical   { flex-direction: column; justify-content: center; }

.rack-tile {
  width: var(--rack-tile);
  height: var(--rack-tile);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--rack-tile) * 0.55);
  flex-shrink: 0;
}

/* Piece action buttons */
.piece-actions {
  display: flex;
  gap: 4px;
  width: 100%;
}

.piece-actions button {
  flex: 1;
  padding: 4px 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
}

.piece-actions button:hover      { background: #2A2A50; }
.piece-actions button:active     { transform: scale(0.96); }
.piece-actions button.disabled   { opacity: 0.35; cursor: not-allowed; }
.piece-actions button.flash-error { background: var(--danger); }

.btn-rotate { font-size: 14px !important; }

/* ── Drag Ghost ──────────────────────────────────────────────────────────── */
.drag-ghost {
  position: fixed;
  display: flex;
  gap: 3px;
  pointer-events: none;
  z-index: 200;
  transform: translate(-50%, -50%);
  opacity: 0.88;
}

.drag-ghost.hidden { display: none; }
.drag-ghost.orient-horizontal { flex-direction: row; }
.drag-ghost.orient-vertical   { flex-direction: column; }

.drag-tile {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,0.55);
}

/* ── Rack controls row ───────────────────────────────────────────────────── */
#rack-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

#rack-controls > * { flex: 1; min-width: 0; }

#coins-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 14px;
  font-weight: 700;
  color: var(--gold);
  background: rgba(255,215,0,0.08);
  border: 1px solid rgba(255,215,0,0.35);
  border-radius: 20px;
  padding: 6px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-resign {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-resign:hover { background: rgba(255,68,102,0.15); }

#btn-items {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-items:hover:not(:disabled) { background: #2A2A50; }
#btn-items.active { background: rgba(85,170,255,0.18); border-color: #55AAFF; color: #88CCFF; }
#btn-items:disabled { opacity: 0.4; cursor: not-allowed; }

#btn-swap-mode {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-swap-mode:hover       { background: #2A2A50; }
#btn-swap-mode.active      { background: var(--success); color: #001A0A; border-color: var(--success); }
#btn-swap-mode.cant-afford { opacity: 0.4; cursor: not-allowed; }

#btn-play {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 6px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-play:hover    { background: #6677FF; }
#btn-play:active   { transform: scale(0.97); }
#btn-play:disabled { background: #3A3A5A; color: #6666AA; cursor: not-allowed; transform: none; }

/* Swap cost label (appears under each slot in swap mode) */
.swap-cost-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  margin-top: 2px;
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  transition: background 0.1s;
}

.swap-cost-label:hover { background: rgba(255,215,0,0.15); }

.swap-cost-label.cant-afford {
  color: var(--danger);
  opacity: 0.7;
}

/* Swap-mode highlight on rack slots */
.rack-slot.swap-mode {
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(255,215,0,0.3);
  cursor: pointer;
}

.rack-slot.flash-error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 10px rgba(255,68,102,0.5) !important;
}

/* ── Overlay ─────────────────────────────────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 20, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

#overlay.hidden { display: none; }

.pass-card, .gameover-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  text-align: center;
}

.pass-turn-score {
  font-size: 52px;
  font-weight: 800;
  color: #FF8C00;
  line-height: 1;
}

.pass-label { font-size: 14px; color: var(--text-dim); }
.pass-detail { font-size: 13px; color: var(--text-dim); }

.pass-item-used {
  color: var(--danger) !important;
  font-weight: 700 !important;
}

.pass-divider {
  width: 60%;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.pass-next {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.gameover-headline {
  font-size: 30px;
  font-weight: 800;
  color: var(--gold);
}

.gameover-scores {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}

.gs-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface);
  font-size: 15px;
}

.gs-row.winner {
  background: rgba(85,102,255,0.25);
  border: 1px solid var(--accent);
  font-weight: 700;
}

.btn-continue {
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 28px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-continue:hover { background: #6677FF; }

/* ── Items modal ─────────────────────────────────────────────────────────── */
.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  width: 100%;
}

.item-info { flex: 1; text-align: left; }
.item-name { font-size: 15px; font-weight: 700; color: var(--text); }
.item-desc { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.item-stock { font-size: 12px; color: var(--gold); margin-top: 4px; }

.item-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.btn-item-action {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  min-width: 80px;
}
.btn-item-action:hover:not(:disabled) { filter: brightness(1.15); }
.btn-item-action.use { background: #FF8833; }
.btn-item-action:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Bomb targeting ──────────────────────────────────────────────────────── */
.cell.bomb-target {
  outline: 2px solid rgba(255, 100, 0, 0.75);
  outline-offset: -2px;
}
.cell.bomb-center {
  outline: 2px solid #FF5500;
  outline-offset: -2px;
  background-color: rgba(255, 85, 0, 0.18) !important;
}

/* ── Bomb detonation animation ───────────────────────────────────────────── */
@keyframes bombPop {
  0%   { transform: scale(1);   background-color: #FF8833 !important; }
  30%  { transform: scale(1.4); background-color: #FF3300 !important; }
  100% { transform: scale(0);   opacity: 0; }
}
.cell.bomb-clear {
  animation: bombPop 0.55s ease-out forwards;
}

/* ── Cross bomb targeting ────────────────────────────────────────────────── */
.cell.cross-target {
  outline: 2px solid rgba(255, 50, 180, 0.7);
  outline-offset: -2px;
  background-color: rgba(255, 50, 180, 0.08) !important;
}
.cell.cross-center {
  outline: 2px solid #FF33CC;
  outline-offset: -2px;
  background-color: rgba(255, 50, 180, 0.22) !important;
}

/* ── Cross bomb detonation animation ─────────────────────────────────────── */
@keyframes crossPop {
  0%   { transform: scale(1);    background-color: #FF33CC !important; opacity: 1; }
  35%  { transform: scale(1.45); background-color: #CC00FF !important; opacity: 1; }
  100% { transform: scale(0);    opacity: 0; }
}
.cell.cross-clear {
  animation: crossPop 0.6s ease-out forwards;
  pointer-events: none;
  z-index: 3;
}

/* ── Chain targeting ─────────────────────────────────────────────────────── */
.cell.chain-target {
  outline: 2px solid rgba(0, 210, 255, 0.7);
  outline-offset: -2px;
  background-color: rgba(0, 210, 255, 0.10) !important;
}
.cell.chain-center {
  outline: 2px solid #00DDFF;
  outline-offset: -2px;
  background-color: rgba(0, 210, 255, 0.22) !important;
}

/* ── Chain detonation animation ──────────────────────────────────────────── */
@keyframes chainPop {
  0%   { transform: scale(1);    filter: brightness(1)   hue-rotate(0deg);   opacity: 1; }
  35%  { transform: scale(1.35); filter: brightness(3.5) hue-rotate(160deg); opacity: 1; }
  100% { transform: scale(0);    filter: brightness(1);                       opacity: 0; }
}
.cell.chain-clear {
  animation: chainPop 0.65s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  pointer-events: none;
  z-index: 3;
}

/* ── Star match flash (flashes bright but stays on board) ────────────────── */
@keyframes starMatchFlash {
  0%   { transform: scale(1);    filter: brightness(1)   drop-shadow(0 0 4px #fff);  opacity: 1; }
  25%  { transform: scale(1.35); filter: brightness(4.0) drop-shadow(0 0 12px #fff); opacity: 1; }
  60%  { transform: scale(1.1);  filter: brightness(2.0) drop-shadow(0 0 6px #fff);  opacity: 1; }
  100% { transform: scale(1);    filter: brightness(1);                               opacity: 1; }
}

.cell.star-match-flash {
  animation: starMatchFlash 0.65s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  pointer-events: none;
  z-index: 3;
}

/* ── Permanent (old) tiles look less vibrant than fresh current-turn tiles ── */
.cell.tile.permanent:not(.star-tile) {
  filter: saturate(0.76) brightness(0.82);
}

/* ── Bot bomb preview ────────────────────────────────────────────────────── */
@keyframes bomb-warn {
  0%   { box-shadow: inset 0 0 0 3px rgba(255, 45, 45, 0.95), 0 0 10px 2px rgba(255, 45, 45, 0.5); }
  50%  { box-shadow: none; }
  100% { box-shadow: inset 0 0 0 3px rgba(255, 45, 45, 0.95), 0 0 10px 2px rgba(255, 45, 45, 0.5); }
}
.bomb-warn {
  animation: bomb-warn 0.38s ease-in-out 3;
}

@keyframes bot-bomb-bounce {
  from { transform: translate(-50%, -110%) scale(1.0);  }
  to   { transform: translate(-50%, -120%) scale(1.12); }
}
.bot-bomb-preview {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  font-size: 30px;
  line-height: 1;
  filter: drop-shadow(0 3px 10px rgba(0,0,0,0.85));
  animation: bot-bomb-bounce 0.38s ease-in-out infinite alternate;
}

/* ── Bot piece drop-in ───────────────────────────────────────────────────── */
@keyframes tileDrop {
  0%   { transform: scale(0.0);  opacity: 0; }
  60%  { transform: scale(1.18); opacity: 1; }
  80%  { transform: scale(0.96); opacity: 1; }
  100% { transform: scale(1.04); opacity: 1; }
}

.cell.tile.tile-drop {
  animation: tileDrop 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  z-index: 2;
}

/* ── Rack piece wiggle + glow ────────────────────────────────────────────── */
@keyframes tileJump {
  0%, 100% { transform: scale(1.04) translateY(0); }
  18%       { transform: scale(1.06, 1.00) translateY(-4px); }
  36%       { transform: scale(1.02, 1.07) translateY(0); }
  52%       { transform: scale(1.05, 1.02) translateY(-2px); }
  68%       { transform: scale(1.04) translateY(0); }
}

.cell.tile.current-turn {
  animation: tileJump 1.6s cubic-bezier(0.36, 0.07, 0.19, 0.97) infinite;
  animation-delay: var(--jump-delay, 0ms);
}

.cell.tile.current-turn:not(.star-tile):not(.invalid) {
  box-shadow: 0 0 0 3px rgba(20, 35, 175, 0.95), 0 0 12px 5px rgba(40, 70, 210, 0.45);
}

/* ── Item panel ──────────────────────────────────────────────────────────── */
/* Item panel renders directly inside #rack — no separate container needed */
#item-panel { display: none; }

.rack-items-panel {
  display: flex;
  width: 100%;
  gap: 8px;
}

/* Item cards match .rack-slot appearance exactly */
.ipr {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: 6px 4px;
  background: var(--surface);
  border-radius: 12px;
  border: 2px solid var(--border);
  text-align: center;
  min-width: 0;
  transition: border-color 0.15s;
}

.ipr-owned {
  cursor: grab;
}

.ipr-owned:hover { border-color: var(--accent); box-shadow: 0 0 10px rgba(85,102,255,0.3); }
.ipr-owned:active { cursor: grabbing; }

.ipr-empty .ipr-icon,
.ipr-empty .ipr-name,
.ipr-empty .ipr-stock {
  opacity: 0.55;
}

.ipr-icon {
  font-size: 22px;
  line-height: 1;
}

.ipr-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.ipr-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.ipr-stock {
  font-size: 10px;
  color: var(--gold);
}

.ipr-desc { display: none; }

.ipr-drag-hint {
  font-size: 10px;
  color: var(--accent);
  opacity: 0.8;
}

.ipr-buy {
  background: var(--surface2);
  color: var(--gold);
  border: 1px solid rgba(255,215,0,0.4);
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s;
  width: 100%;
}

.ipr-buy:hover:not(:disabled) { background: rgba(255,215,0,0.12); }


.ipr-buy.ipr-broke,
.ipr-buy:disabled {
  color: var(--text-dim);
  border-color: var(--border);
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Item ghost (follows pointer during drag from panel) ─────────────────── */
.item-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 300;
  transform: translate(-50%, -60%);
  font-size: 32px;
  line-height: 1;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.7));
  transition: none;
}

.item-ghost.hidden { display: none; }

/* ── CANCEL / BOOM confirmation row ──────────────────────────────────────── */
.item-boom-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  width: 100%;
}

.btn-item-cancel {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
  transition: background 0.12s;
}

.btn-item-cancel:hover { background: rgba(255,255,255,0.06); }

.btn-item-boom {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
  letter-spacing: 0.04em;
  transition: filter 0.12s;
}

.btn-item-boom:hover { filter: brightness(1.15); }
.btn-item-boom:active { transform: scale(0.97); }
