/**
 * Tavern Larder: Goods Sort — CSS
 * Cerulean Blue & Marigold Gold fantasy aesthetic with 3D wooden shelf depth.
 */

:root {
  --cerulean-glow: rgba(2, 136, 209, 0.45);
  --marigold-glow: rgba(255, 159, 28, 0.45);
  --oak-dark: #22150a;
  --oak-shelf: #452a16;
  --oak-rim: #784824;
  --brass-rim: #d97706;
}

body.sort-game-body {
  min-height: 100vh;
  margin: 0;
  color: #f1f5f9;
  background-color: #060e1a;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  font-family: var(--font-body, 'Inter', system-ui, sans-serif);
}

.sort-shell {
  position: relative;
  z-index: 1;
  max-width: 960px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-sizing: border-box;
}

/* ---------------- Topbar & Controls ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(8, 22, 44, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.back-link {
  font-family: var(--font-mono, monospace);
  font-size: 0.8rem;
  font-weight: 700;
  color: #38bdf8;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(2, 136, 209, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.4);
  transition: all 0.18s ease;
}

.back-link:hover {
  background: rgba(2, 136, 209, 0.4);
  border-color: #ffd24d;
  color: #ffffff;
  transform: translateX(-2px);
}

.title-group {
  display: flex;
  flex-direction: column;
}

.game-title {
  margin: 0;
  font-family: var(--font-rpg, 'Cinzel', serif);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  background: linear-gradient(180deg, #ffffff 0%, #ffd24d 45%, #ff9f1c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.8));
}

.game-subtitle {
  font-family: var(--font-mono, monospace);
  font-size: 0.68rem;
  font-weight: 700;
  color: #38bdf8;
  letter-spacing: 0.12em;
}

/* Adventurer XP Chip */
.adventurer-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(12, 28, 54, 0.8);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.adv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono, monospace);
  font-size: 0.72rem;
}

.adv-level {
  color: #ffd24d;
  font-weight: 800;
}

.adv-rank {
  color: #94a3b8;
}

.adv-cleared {
  color: #38bdf8;
  font-weight: 700;
  margin-left: auto;
}

.xp-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.8);
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0288d1, #ff9f1c);
  transition: width 0.3s ease;
}

/* Control Bar */
.game-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(10, 24, 48, 0.65);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.controls-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 8px;
  background: rgba(6, 18, 36, 0.85);
  border: 1.5px solid rgba(56, 189, 248, 0.35);
  font-family: var(--font-mono, monospace);
  font-size: 0.75rem;
}

.level-badge {
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.level-badge:hover {
  border-color: #ffd24d;
  background: rgba(255, 170, 0, 0.15);
  transform: translateY(-1px);
}

.badge-label {
  color: #94a3b8;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
}

.badge-value {
  color: #ffd24d;
  font-weight: 800;
}

/* Mode Switch */
.mode-toggle-wrap {
  display: inline-flex;
  border-radius: 8px;
  background: rgba(6, 18, 36, 0.9);
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  padding: 2px;
  overflow: hidden;
}

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-family: var(--font-display, sans-serif);
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.mode-btn.active {
  background: linear-gradient(135deg, #0288d1, #0369a1);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(2, 136, 209, 0.5);
}

.mode-btn:not(.active):hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(16, 40, 75, 0.85), rgba(10, 24, 48, 0.9));
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #e2e8f0;
  font-family: var(--font-display, sans-serif);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.pill-btn:hover {
  border-color: #ffd24d;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(255, 170, 0, 0.35);
  transform: translateY(-1px);
}

.pill-btn.highlight-btn {
  background: linear-gradient(135deg, rgba(255, 170, 0, 0.22) 0%, rgba(2, 136, 209, 0.35) 100%);
  border: 1.5px solid #ffd24d;
  color: #ffd24d;
  box-shadow: 0 0 14px rgba(255, 170, 0, 0.35);
}

.pill-btn.highlight-btn:hover {
  background: linear-gradient(135deg, rgba(255, 170, 0, 0.4) 0%, rgba(2, 136, 209, 0.5) 100%);
  color: #ffffff;
  box-shadow: 0 0 22px rgba(255, 210, 77, 0.6);
  transform: translateY(-2px);
}

/* First-time alert prompt banner */
.first-time-prompt {
  width: 100%;
  max-width: 820px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 16px;
  box-sizing: border-box;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(14, 40, 75, 0.9) 0%, rgba(8, 22, 44, 0.95) 100%);
  border: 1.5px solid #ffd24d;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45), 0 0 18px rgba(255, 170, 0, 0.25);
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.prompt-icon {
  font-size: 1.3rem;
}

.prompt-text {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 600;
  color: #f1f5f9;
  min-width: 220px;
}

.prompt-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.prompt-btn-primary {
  padding: 6px 14px;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffd24d 0%, #ff9f1c 100%);
  border: 1px solid #ffe58f;
  color: #06111f;
  font-family: var(--font-display, sans-serif);
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 159, 28, 0.4);
  transition: all 0.15s ease;
}

.prompt-btn-primary:hover {
  transform: scale(1.04);
  box-shadow: 0 6px 16px rgba(255, 159, 28, 0.6);
}

.prompt-btn-dismiss {
  padding: 6px 10px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #94a3b8;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.prompt-btn-dismiss:hover {
  color: #ffffff;
  border-color: #ffffff;
}

/* Active Interactive Tutorial Banner */
.tutorial-banner {
  width: 100%;
  max-width: 820px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  box-sizing: border-box;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(2, 136, 209, 0.35) 0%, rgba(10, 28, 54, 0.95) 100%);
  border: 2px solid #38bdf8;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), 0 0 25px rgba(2, 136, 209, 0.4);
  animation: pulseGuide 2.5s ease-in-out infinite alternate;
}

@keyframes pulseGuide {
  0% { box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(2, 136, 209, 0.3); }
  100% { box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), 0 0 35px rgba(56, 189, 248, 0.6); }
}

.tutorial-badge {
  font-family: var(--font-mono, monospace);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #ffd24d;
  background: rgba(0, 0, 0, 0.4);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 210, 77, 0.4);
  white-space: nowrap;
}

.tutorial-msg {
  flex: 1;
  font-size: 0.92rem;
  color: #f8fafc;
  line-height: 1.4;
}

.tutorial-close-btn {
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #cbd5e1;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tutorial-close-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
}

/* Pulsing target card or slot */
.tutorial-pulse-target {
  position: relative;
  z-index: 25 !important;
  animation: tutorialTargetPulse 1.2s ease-in-out infinite !important;
  border-color: #ffd24d !important;
}

@keyframes tutorialTargetPulse {
  0%, 100% {
    box-shadow: 0 0 15px rgba(255, 210, 77, 0.6), 0 0 30px rgba(2, 136, 209, 0.4);
    transform: scale(1.05);
  }
  50% {
    box-shadow: 0 0 28px rgba(255, 210, 77, 0.9), 0 0 45px rgba(2, 136, 209, 0.7);
    transform: scale(1.12);
  }
}

.icon-btn {
  padding: 6px 10px;
}

/* ---------------- Cabinet Arena & Shelves ---------------- */
.cabinet-arena {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex: 1;
  padding: 10px 0;
}

/* Arcane Fireworks Canvas Overlay */
.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 45;
}

/* Combo Banner */
.combo-banner {
  position: absolute;
  top: -10px;
  z-index: 55;
  pointer-events: none;
  font-family: var(--font-display, sans-serif);
  font-size: 1.6rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #ffd24d;
  text-shadow: 0 0 15px rgba(255, 159, 28, 0.9), 0 2px 4px rgba(0, 0, 0, 0.9);
  opacity: 0;
  transform: scale(0.6) translateY(10px);
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.combo-banner.show {
  opacity: 1;
  transform: scale(1.1) translateY(0);
}

.combo-banner.tier-2 {
  color: #38bdf8;
  font-size: 1.6rem;
  text-shadow: 0 0 22px rgba(56, 189, 248, 0.95), 0 2px 4px #000;
}

.combo-banner.tier-3 {
  color: #ffd24d;
  font-size: 1.9rem;
  text-shadow: 0 0 28px rgba(255, 170, 0, 1), 0 0 12px #ff9f1c, 0 2px 4px #000;
  animation: bannerPulse 0.4s ease-in-out infinite alternate;
}

.combo-banner.tier-4 {
  color: #e879f9;
  font-size: 2.25rem;
  text-shadow: 0 0 35px rgba(232, 121, 249, 1), 0 0 15px #ffd24d, 0 2px 6px #000;
  animation: megaBannerPulse 0.3s ease-in-out infinite alternate;
}

@keyframes bannerPulse {
  0% { transform: scale(1.1); }
  100% { transform: scale(1.2); }
}

@keyframes megaBannerPulse {
  0% { transform: scale(1.15) rotate(-1deg); }
  100% { transform: scale(1.28) rotate(1deg); }
}

/* Floating Arcane Score Points */
.floating-score {
  position: absolute;
  pointer-events: none;
  z-index: 60;
  font-family: var(--font-display, sans-serif);
  font-weight: 800;
  font-size: 1.3rem;
  color: #ffd24d;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9), 0 0 14px rgba(255, 210, 77, 0.85);
  transform: translate(-50%, -50%);
  animation: floatScoreUp 1.2s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
  white-space: nowrap;
}

.floating-score.tier-2 {
  color: #38bdf8;
  font-size: 1.45rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9), 0 0 18px rgba(56, 189, 248, 0.95);
}

.floating-score.tier-3 {
  color: #ffd24d;
  font-size: 1.7rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9), 0 0 22px rgba(255, 170, 0, 1), 0 0 10px #ff9f1c;
}

.floating-score.tier-4 {
  color: #e879f9;
  font-size: 1.95rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9), 0 0 28px rgba(232, 121, 249, 1), 0 0 14px #ffd24d;
}

.floating-score .combo-tag {
  font-size: 0.8em;
  color: #ffd24d;
  font-weight: 900;
  margin-left: 4px;
}

@keyframes floatScoreUp {
  0% {
    opacity: 0;
    transform: translate(-50%, 0) scale(0.6);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -20px) scale(1.15);
  }
  40% {
    transform: translate(-50%, -36px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -75px) scale(0.9);
  }
}

/* Cabinet Screen Shake for combos >= 3 */
.cabinet-rumble {
  animation: cabinetShake 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes cabinetShake {
  10%, 90% { transform: translate3d(-3px, 0, 0); }
  20%, 80% { transform: translate3d(4px, -1px, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 2px, 0); }
  40%, 60% { transform: translate3d(4px, -2px, 0); }
}

/* Cabinet Frame */
.cabinet-unit {
  width: 100%;
  max-width: 820px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  padding: 18px;
  box-sizing: border-box;
  border-radius: 18px;
  background: 
    linear-gradient(180deg, rgba(34, 21, 10, 0.94) 0%, rgba(20, 12, 6, 0.96) 100%);
  border: 3px solid #784824;
  box-shadow: 
    0 16px 48px rgba(0, 0, 0, 0.85),
    0 0 30px rgba(2, 136, 209, 0.2),
    inset 0 0 40px rgba(0, 0, 0, 0.7),
    inset 0 2px 0 rgba(255, 255, 255, 0.15);
}

/* Individual Shelf Compartment */
.shelf-compartment {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 140px;
  padding: 8px 10px 14px;
  box-sizing: border-box;
  border-radius: 12px;
  background: 
    radial-gradient(ellipse at 50% 20%, rgba(56, 189, 248, 0.08) 0%, transparent 70%),
    linear-gradient(180deg, #180e07 0%, #29180c 60%, #3a2211 100%);
  border: 2px solid #5a341a;
  box-shadow: 
    inset 0 10px 20px rgba(0, 0, 0, 0.75),
    inset 0 -3px 0 #784824,
    0 4px 10px rgba(0, 0, 0, 0.5);
  transition: all 0.2s ease;
}

/* Shelf Board (Wooden ledge at bottom) */
.shelf-compartment::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 12px;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(180deg, #8a5329 0%, #543118 60%, #301b0b 100%);
  border-top: 1.5px solid #d97706;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.shelf-compartment.target-highlight {
  border-color: #ffd24d;
  box-shadow: 
    0 0 20px rgba(255, 170, 0, 0.5),
    inset 0 0 25px rgba(2, 136, 209, 0.35);
  transform: translateY(-2px);
}

/* Shelf Slot Container (Holds the 3 positions) */
.shelf-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  height: 100%;
  align-items: flex-end;
  position: relative;
  z-index: 2;
}

/* An Individual Slot Column */
.shelf-slot {
  position: relative;
  height: 96px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s ease;
}

.shelf-slot.target-empty {
  background: rgba(56, 189, 248, 0.12);
  border: 1px dashed rgba(56, 189, 248, 0.5);
}

.shelf-slot.target-empty:hover {
  background: rgba(255, 170, 0, 0.2);
  border-color: #ffd24d;
}

/* Stacks within a slot (Front + Depth Peeking) */
.item-stack {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* Individual Good Card */
.good-card {
  position: absolute;
  bottom: 0;
  width: 58px;
  height: 74px;
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.98));
  border: 1.5px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
  box-sizing: border-box;
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s ease, opacity 0.2s ease;
  touch-action: manipulation;
}

.good-svg-wrap {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.good-svg-wrap svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.good-name-lbl {
  font-family: var(--font-mono, monospace);
  font-size: 0.58rem;
  font-weight: 700;
  color: #cbd5e1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  margin-top: 2px;
}

/* Layer Depth Effects (Peeking behind front items) */
.good-card.layer-0 {
  /* Front interactive item */
  z-index: 5;
  transform: translateY(0) scale(1);
  opacity: 1;
  cursor: pointer;
}

.good-card.layer-0:hover {
  transform: translateY(-4px) scale(1.04);
  border-color: #ffd24d;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.6), 0 0 15px rgba(255, 170, 0, 0.4);
}

/* Front card visual depth cue when items are stacked behind */
.good-card.has-queued-items {
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.7),
    0 -3px 0 0 rgba(56, 189, 248, 0.5),
    0 -6px 0 0 rgba(255, 210, 77, 0.4);
}

/* Stack Depth Count Badge (+1, +2, etc.) */
.depth-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #0288d1;
  color: #ffffff;
  border: 2px solid #ffd24d;
  font-family: var(--font-mono, monospace);
  font-size: 0.72rem;
  font-weight: 900;
  padding: 1px 7px;
  border-radius: 999px;
  box-shadow: 
    0 3px 8px rgba(0, 0, 0, 0.9),
    0 0 12px rgba(255, 210, 77, 0.9);
  z-index: 15;
  pointer-events: none;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.good-card.layer-1 {
  /* 2nd layer: peeking top - crisp and bright */
  z-index: 3;
  transform: translateY(-18px) scale(0.9);
  opacity: 0.95;
  filter: brightness(0.95) saturate(1.15);
  border: 2px solid #38bdf8;
  box-shadow: 0 -4px 12px rgba(56, 189, 248, 0.55);
  pointer-events: none;
}

.good-card.layer-2 {
  /* 3rd layer: peeking top back - distinct silhouette */
  z-index: 1;
  transform: translateY(-32px) scale(0.82);
  opacity: 0.9;
  filter: brightness(0.88) saturate(1.1);
  border: 2px solid #ffd24d;
  box-shadow: 0 -4px 12px rgba(255, 210, 77, 0.55);
  pointer-events: none;
}

/* Selected Item State */
.good-card.is-selected {
  z-index: 10 !important;
  transform: translateY(-12px) scale(1.1) !important;
  border-color: #ffd24d !important;
  background: linear-gradient(145deg, rgba(2, 136, 209, 0.4), rgba(255, 170, 0, 0.25)) !important;
  box-shadow: 
    0 12px 28px rgba(0, 0, 0, 0.7),
    0 0 24px rgba(255, 170, 0, 0.8),
    0 0 12px rgba(56, 189, 248, 0.8) !important;
  animation: floatPulse 1.4s ease-in-out infinite;
}

@keyframes floatPulse {
  0%, 100% { transform: translateY(-12px) scale(1.1); }
  50% { transform: translateY(-16px) scale(1.12); }
}

/* Triple Match Pop Animation */
.good-card.pop-match {
  z-index: 20 !important;
  animation: matchPopOut 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards !important;
}

@keyframes matchPopOut {
  0% {
    transform: translateY(0) scale(1);
    box-shadow: 0 0 30px #ffd24d;
  }
  50% {
    transform: translateY(-20px) scale(1.25) rotate(6deg);
    border-color: #ffffff;
    box-shadow: 0 0 50px #ff9f1c, 0 0 30px #38bdf8;
    opacity: 1;
  }
  100% {
    transform: translateY(-40px) scale(0.2) rotate(18deg);
    opacity: 0;
  }
}

/* Slide Forward Animation */
.good-card.slide-forward {
  animation: slideToFront 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes slideToFront {
  0% {
    transform: translateY(-14px) scale(0.85);
    opacity: 0.72;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Chained / Locked Shelf */
.shelf-compartment.is-locked {
  filter: grayscale(0.85) brightness(0.65);
  pointer-events: none;
}

.shelf-compartment.is-locked::before {
  content: "🔒 Locked";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid #ef4444;
  color: #fca5a5;
  font-family: var(--font-mono, monospace);
  font-size: 0.75rem;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.8);
}

/* ---------------- Emergency Stash Crate ---------------- */
.stash-crate-wrap {
  width: 100%;
  max-width: 480px;
  padding: 10px 14px;
  box-sizing: border-box;
  border-radius: 12px;
  background: rgba(30, 20, 10, 0.9);
  border: 2px dashed #b45309;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stash-crate-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stash-icon { font-size: 1.1rem; }
.stash-title {
  font-family: var(--font-rpg, serif);
  font-size: 0.85rem;
  font-weight: 700;
  color: #ffd24d;
}
.stash-sub {
  margin-left: auto;
  font-size: 0.68rem;
  color: #94a3b8;
}

.stash-slots {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.stash-slots .shelf-slot {
  width: 68px;
  height: 84px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  border: 1px solid rgba(255, 170, 0, 0.35);
}

/* ---------------- Helper Spells Bar ---------------- */
.spells-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(6, 14, 26, 0.85) 0%, rgba(4, 10, 20, 0.98) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1.5px solid rgba(56, 189, 248, 0.3);
  box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.6);
}

.spell-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 680px;
  width: 100%;
  justify-content: space-around;
}

.spell-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(16, 40, 75, 0.85), rgba(8, 22, 44, 0.95));
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  color: #f1f5f9;
  cursor: pointer;
  transition: all 0.16s ease;
  touch-action: manipulation;
}

.spell-btn:hover:not(:disabled) {
  border-color: #ffd24d;
  background: linear-gradient(145deg, rgba(2, 136, 209, 0.35), rgba(255, 170, 0, 0.25));
  box-shadow: 0 4px 16px rgba(255, 170, 0, 0.4);
  transform: translateY(-2px);
}

.spell-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.8);
}

.spell-icon {
  font-size: 1.25rem;
}

.spell-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}

.spell-name {
  font-family: var(--font-display, sans-serif);
  font-size: 0.76rem;
  font-weight: 700;
  color: #f8fafc;
}

.spell-count {
  font-family: var(--font-mono, monospace);
  font-size: 0.68rem;
  font-weight: 800;
  color: #ffd24d;
}

/* ---------------- Modals (Pause, Victory, Defeat, Rules) ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 10, 22, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 440px;
  padding: 28px 24px;
  box-sizing: border-box;
  border-radius: 18px;
  background: linear-gradient(165deg, rgba(16, 42, 77, 0.95), rgba(8, 20, 40, 0.98));
  border: 2px solid rgba(255, 170, 0, 0.6);
  box-shadow: 
    0 24px 60px rgba(0, 0, 0, 0.9),
    0 0 35px rgba(2, 136, 209, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: popCard 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popCard {
  from { transform: scale(0.9) translateY(20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-icon { font-size: 2.8rem; margin-bottom: 8px; }

.modal-title {
  margin: 0 0 8px;
  font-family: var(--font-rpg, serif);
  font-size: 1.55rem;
  font-weight: 800;
  background: linear-gradient(180deg, #ffffff 0%, #ffd24d 50%, #ff9f1c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.8));
}

.modal-desc {
  margin: 0 0 20px;
  font-size: 0.9rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.victory-stars {
  font-size: 2.2rem;
  margin-bottom: 6px;
  filter: drop-shadow(0 0 12px rgba(255, 170, 0, 0.7));
}

.victory-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  margin-bottom: 22px;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(8, 20, 38, 0.8);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.stat-pill .stat-lbl {
  font-family: var(--font-mono, monospace);
  font-size: 0.68rem;
  color: #94a3b8;
}

.stat-pill .stat-val {
  font-family: var(--font-display, sans-serif);
  font-size: 1.15rem;
  font-weight: 800;
  color: #f8fafc;
}

.stat-pill .stat-val.highlight {
  color: #ffd24d;
  text-shadow: 0 0 10px rgba(255, 170, 0, 0.6);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.modal-cta-btn {
  width: 100%;
  padding: 13px 20px;
  border-radius: 12px;
  background: linear-gradient(135deg, #ffd24d 0%, #ff9f1c 50%, #f77f00 100%);
  border: 1px solid #ffe58f;
  color: #06111f;
  font-family: var(--font-display, sans-serif);
  font-size: 1rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 159, 28, 0.45);
  transition: all 0.16s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.auto-advance-badge {
  font-family: var(--font-mono, monospace);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(6, 17, 31, 0.45);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  letter-spacing: 0.04em;
  text-transform: none;
}

.auto-advance-sub {
  font-family: var(--font-mono, monospace);
  font-size: 0.72rem;
  color: #a6ceff;
  text-align: center;
  margin-top: 2px;
}

.modal-cta-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
  box-shadow: 0 12px 30px rgba(255, 159, 28, 0.65);
}

.modal-sec-btn {
  width: 100%;
  padding: 11px 20px;
  border-radius: 12px;
  background: rgba(16, 40, 75, 0.6);
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  color: #e2e8f0;
  font-family: var(--font-display, sans-serif);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.modal-sec-btn:hover {
  border-color: #ffd24d;
  color: #ffffff;
}

/* Rules list */
.rules-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  margin-bottom: 22px;
  width: 100%;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #e2e8f0;
}

.objective-hero-quote {
  font-family: var(--font-display, sans-serif);
  font-size: 0.95rem;
  font-weight: 700;
  color: #ffd24d;
  background: rgba(2, 136, 209, 0.22);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
  text-shadow: 0 0 10px rgba(255, 170, 0, 0.4);
}

.rule-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #0288d1;
  color: #ffffff;
  font-weight: 800;
  font-size: 0.78rem;
  flex-shrink: 0;
}

/* ---------------- Responsive Tweaks ---------------- */
@media (max-width: 600px) {
  .sort-shell {
    padding: 12px 10px 80px;
    gap: 12px;
  }

  .game-title {
    font-size: 1.15rem;
  }

  .cabinet-unit {
    grid-template-columns: repeat(2, 1fr);
    padding: 12px 8px;
    gap: 10px;
  }

  .shelf-compartment {
    height: 125px;
    padding: 6px 6px 12px;
  }

  .good-card {
    width: 48px;
    height: 64px;
  }

  .good-svg-wrap {
    width: 36px;
    height: 36px;
  }

  .good-name-lbl {
    font-size: 0.52rem;
  }

  .depth-badge {
    top: -6px;
    right: -6px;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-width: 1.5px;
  }

  .spell-btn {
    padding: 6px 10px;
    gap: 6px;
  }

  .spell-name {
    font-size: 0.7rem;
  }

  .spell-icon {
    font-size: 1.1rem;
  }
}
