/**
 * Crumble — Swap-to-Spell Styling
 * Bakery-arcade aesthetic with tactile letter tiles,
 * glowing Scrabble bonus badges, and fluid cascade animations.
 */

:root {
  --crumble-gold: #ffbe0b;
  --crumble-amber: #ff7b00;
  --crumble-cyan: #00e5ff;
  --crumble-mint: #00ff66;
  --tile-bg: rgba(255, 255, 255, 0.08);
  --tile-border: rgba(255, 255, 255, 0.16);
  --tile-hover: rgba(255, 255, 255, 0.14);
  --tile-selected-border: #ffbe0b;
  --tile-selected-glow: rgba(255, 190, 11, 0.4);
}

/* Crumble Main Stage Layout */
.crumble-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
}

/* Crumble Status Bar */
.crumble-status-bar {
  width: 100%;
  max-width: 520px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  padding: 10px 16px;
  border-radius: 16px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.crumble-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.crumble-mode-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.crumble-mode-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
}

.crumble-mode-tag {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag-original {
  background: rgba(255, 190, 11, 0.15);
  color: var(--toast-gold);
  border: 1px solid rgba(255, 190, 11, 0.35);
}

.tag-panko {
  background: rgba(0, 229, 255, 0.15);
  color: var(--crumble-cyan);
  border: 1px solid rgba(0, 229, 255, 0.35);
}

.crumble-subtext {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  white-space: nowrap;
}

.crumble-stats-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 4px 10px;
  min-width: 60px;
}

.stat-pill-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1;
  margin-bottom: 2px;
}

.stat-pill-val {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--toast-gold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stat-pill-val.val-swaps {
  color: var(--pickle-neon);
}

.stat-pill-val.val-timer {
  color: var(--crumble-cyan);
  transition: color 0.15s ease, text-shadow 0.15s ease;
}

.stat-pill-val.val-timer.timer-paused {
  color: #ffbe0b !important;
  text-shadow: 0 0 10px rgba(255, 190, 11, 0.65);
}

/* 7x7 Board Container */
.crumble-board-wrapper {
  position: relative;
  width: 100%;
  max-width: min(100%, calc(100dvh - 230px), 510px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* Allows fluid drag/swipe */
}

.crumble-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: 5px;
  padding: 7px;
  background: rgba(4, 18, 9, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(0, 0, 0, 0.4);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Individual Tile */
.crumble-tile {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--tile-bg);
  border: 1.5px solid var(--tile-border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1), 
              background 0.15s ease, 
              border-color 0.15s ease, 
              box-shadow 0.15s ease;
  will-change: transform;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.crumble-tile:hover {
  background: var(--tile-hover);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

/* Tile Selection */
.crumble-tile.selected {
  background: rgba(255, 190, 11, 0.2);
  border-color: var(--tile-selected-border);
  box-shadow: 0 0 16px var(--tile-selected-glow), inset 0 0 8px var(--tile-selected-glow);
  transform: scale(1.05);
  z-index: 10;
}

/* Bonus Tile Visual Markers */
.crumble-tile[data-bonus="TW"] {
  border-color: rgba(255, 123, 0, 0.45);
  background: radial-gradient(circle at 50% 50%, rgba(255, 123, 0, 0.22) 0%, rgba(255, 123, 0, 0.06) 100%), var(--tile-bg);
}

.crumble-tile[data-bonus="DW"] {
  border-color: rgba(255, 190, 11, 0.45);
  background: radial-gradient(circle at 50% 50%, rgba(255, 190, 11, 0.2) 0%, rgba(255, 190, 11, 0.05) 100%), var(--tile-bg);
}

.crumble-tile[data-bonus="TL"] {
  border-color: rgba(0, 229, 255, 0.55);
  background: radial-gradient(circle at 50% 50%, rgba(0, 229, 255, 0.26) 0%, rgba(0, 229, 255, 0.08) 100%), var(--tile-bg);
}

.crumble-tile[data-bonus="DL"] {
  border-color: rgba(0, 255, 102, 0.45);
  background: radial-gradient(circle at 50% 50%, rgba(0, 255, 102, 0.18) 0%, rgba(0, 255, 102, 0.05) 100%), var(--tile-bg);
}

/* Small Bonus Badge in corner of tile */
.tile-bonus-badge {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: clamp(0.44rem, 1.6vw, 0.52rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  opacity: 0.9;
  pointer-events: none;
}

.tile-bonus-badge.badge-TW { color: var(--crumble-amber); }
.tile-bonus-badge.badge-DW { color: var(--crumble-gold); }
.tile-bonus-badge.badge-TL { color: var(--crumble-cyan); }
.tile-bonus-badge.badge-DL { color: var(--crumble-mint); }

/* Tile Letter */
.tile-letter {
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 4.4vw, 1.55rem);
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  line-height: 1;
  pointer-events: none;
}

/* Tile Point Value Subscript */
.tile-points {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: clamp(0.44rem, 1.6vw, 0.52rem);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.65);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  pointer-events: none;
}

/* Match Clear Animation */
.crumble-tile.clearing {
  animation: tileClearFlash 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  z-index: 15;
}

@keyframes tileClearFlash {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  40% {
    transform: scale(1.15);
    filter: brightness(2.2);
    box-shadow: 0 0 24px rgba(255, 255, 255, 0.8);
  }
  100% {
    transform: scale(0.2) rotate(10deg);
    opacity: 0;
  }
}

/* Cascade Tile Falling Animation */
.crumble-tile.falling {
  animation: tileFallIn 0.3s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes tileFallIn {
  from {
    transform: translateY(-40px);
    opacity: 0.3;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Word Popups Floating Layer */
.word-popups-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

.word-popup {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(5, 16, 9, 0.92);
  border: 1.5px solid var(--toast-gold);
  border-radius: 12px;
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), 0 0 15px rgba(255, 190, 11, 0.3);
  animation: popupFloat 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.popup-word-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  white-space: nowrap;
}

.popup-dir-tag {
  font-size: 0.68rem;
  color: var(--text-dim);
  font-weight: 600;
}

.popup-score {
  color: var(--toast-gold);
  font-weight: 900;
}

.popup-flavor {
  font-size: 0.72rem;
  color: var(--pickle-neon);
  font-weight: 700;
  font-style: italic;
  white-space: nowrap;
}

@keyframes popupFloat {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.8);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
  70% {
    opacity: 1;
    transform: translate(-50%, -65%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -85%) scale(0.9);
  }
}

/* Recent Words List Tray */
.crumble-tray {
  width: 100%;
  max-width: 520px;
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.crumble-tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.crumble-words-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 72px;
  overflow-y: auto;
}

.word-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 5px;
}

.word-chip-text {
  font-weight: 700;
  color: #fff;
}

.word-chip-pts {
  color: var(--toast-gold);
  font-weight: 800;
  font-size: 0.7rem;
}

/* Mobile responsive scaling */
@media (max-width: 480px) {
  .crumble-stage {
    gap: 10px;
  }
  .crumble-status-bar {
    padding: 7px 10px;
    border-radius: 13px;
  }
  .crumble-mode-name {
    font-size: 1.02rem;
  }
  .crumble-mode-tag {
    font-size: 0.62rem;
    padding: 1px 5px;
  }
  .crumble-subtext {
    font-size: 0.7rem;
  }
  .stat-pill {
    padding: 3px 6px;
    min-width: 48px;
    border-radius: 8px;
  }
  .stat-pill-label {
    font-size: 0.55rem;
  }
  .stat-pill-val {
    font-size: 0.95rem;
  }
  .crumble-board {
    gap: 3.5px;
    padding: 5px;
    border-radius: 14px;
  }
  .crumble-tile {
    border-radius: 6.5px;
    border-width: 1px;
  }
  .crumble-tray {
    padding: 8px 10px;
    border-radius: 12px;
  }
  .crumble-tray-header {
    font-size: 0.66rem;
    flex-wrap: wrap;
    gap: 3px;
  }
  .crumble-words-chips {
    max-height: 64px;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .word-chip {
    padding: 2.5px 6px;
    font-size: 0.72rem;
    border-radius: 6px;
  }
  .modal-overlay {
    padding: 10px;
  }
  .modal-overlay .modal-content {
    padding: 20px 16px;
    border-radius: 18px;
    max-height: 92dvh;
    -webkit-overflow-scrolling: touch;
  }
  .completed-banner-card {
    padding: 10px 14px;
    border-radius: 13px;
  }
  .btn-banner-panko, .btn-banner-share {
    min-height: 42px;
    font-size: 0.8rem;
    padding: 8px 12px;
  }
}

@media (max-width: 360px) {
  .crumble-mode-tag {
    display: none;
  }
  .stat-pill {
    min-width: 42px;
    padding: 2px 4px;
  }
  .stat-pill-val {
    font-size: 0.88rem;
  }
  .completed-banner-actions {
    flex-direction: column;
    gap: 6px;
  }
}

/* Shake feedback for invalid moves */
@keyframes tileShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.crumble-tile.shake {
  animation: tileShake 0.25s ease;
}

/* Modal Overlay Fail-Safe Protection & Glassmorphism Polish */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 15, 9, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.modal-overlay .modal-content {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-glow);
  border-radius: 24px;
  max-width: 520px;
  width: 100%;
  padding: 28px 24px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(12px);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-content {
  transform: scale(1) translateY(0);
}

/* Daily Completed Banner */
.daily-completed-banner {
  width: 100%;
  max-width: 510px;
  margin: 0 auto;
}

.completed-banner-card {
  background: linear-gradient(135deg, rgba(4, 25, 12, 0.95) 0%, rgba(2, 14, 7, 0.98) 100%);
  border: 1.5px solid var(--pickle-neon);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 16px rgba(0, 255, 102, 0.2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.completed-banner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.completed-badge {
  font-family: var(--font-display);
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--pickle-neon);
  letter-spacing: 0.05em;
  background: rgba(0, 255, 102, 0.12);
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0, 255, 102, 0.3);
}

.completed-score-callout {
  font-size: 0.88rem;
  color: #fff;
}

.completed-score-callout strong {
  color: var(--toast-gold);
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.completed-countdown-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.countdown-digits {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1.05rem;
  color: var(--toast-gold);
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.countdown-tz {
  font-size: 0.72rem;
  opacity: 0.7;
}

.completed-banner-actions {
  display: flex;
  gap: 10px;
}

.btn-banner-panko, .btn-banner-share {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.18s ease;
  border: none;
  white-space: nowrap;
}

.btn-banner-panko {
  background: linear-gradient(135deg, #00e5ff 0%, #00b0ff 100%);
  color: #03141a;
  box-shadow: 0 4px 14px rgba(0, 229, 255, 0.35);
}

.btn-banner-panko:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 229, 255, 0.55);
}

.btn-banner-share {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-banner-share:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-2px);
}

/* Locked Board when daily original is completed */
.crumble-board.locked {
  pointer-events: none;
  opacity: 0.88;
}

.stat-pill-val.val-swaps.done {
  color: var(--pickle-neon);
  font-size: 0.85rem;
  font-weight: 900;
}

/* Score rollup pulse animation */
.stat-pill-val.score-pulse {
  animation: scoreTickPulse 0.3s ease-out;
  color: #fff !important;
  text-shadow: 0 0 14px var(--toast-gold);
}

@keyframes scoreTickPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* 5s Skip Cascade Button */
.btn-cascade-skip {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px) scale(0.9);
  background: rgba(4, 18, 9, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid var(--toast-gold);
  color: var(--toast-gold);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7), 0 0 16px rgba(255, 190, 11, 0.4);
  padding: 7px 18px;
  border-radius: 20px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  z-index: 250;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
}

.btn-cascade-skip:hover {
  transform: translateX(-50%) translateY(0) scale(1.05);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.8), 0 0 24px rgba(255, 190, 11, 0.6);
  color: #fff;
}

.btn-cascade-skip.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* Leaderboard player row highlight */
tr.lb-current-user {
  background: rgba(255, 190, 11, 0.16) !important;
  border-left: 3px solid var(--toast-gold);
}

tr.lb-current-user td:nth-child(2) span:first-child {
  color: var(--toast-gold) !important;
  font-weight: 800;
}

tr.lb-current-user td:nth-child(3) {
  text-shadow: 0 0 10px rgba(255, 190, 11, 0.4);
}


