/* ==========================================================================
   Arrow Puzzle Escape Game - style.css
   Modern, responsive, tactile styles and animations
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800;900&family=Plus+Jakarta+Sans:wght@500;600;700;800&display=swap');

:root {
  --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Theme Accents */
  --color-up: #38bdf8;
  --color-up-bg: rgba(56, 189, 248, 0.15);
  --color-up-border: rgba(56, 189, 248, 0.4);
  --color-up-glow: rgba(56, 189, 248, 0.35);

  --color-right: #34d399;
  --color-right-bg: rgba(52, 211, 153, 0.15);
  --color-right-border: rgba(52, 211, 153, 0.4);
  --color-right-glow: rgba(52, 211, 153, 0.35);

  --color-down: #fbbf24;
  --color-down-bg: rgba(251, 191, 36, 0.15);
  --color-down-border: rgba(251, 191, 36, 0.4);
  --color-down-glow: rgba(251, 191, 36, 0.35);

  --color-left: #a78bfa;
  --color-left-bg: rgba(167, 139, 250, 0.15);
  --color-left-border: rgba(167, 139, 250, 0.4);
  --color-left-glow: rgba(167, 139, 250, 0.35);

  --cell-size: 64px;
}

/* Global Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  font-family: var(--font-sans);
  background-color: #030712;
  color: #f3f4f6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, .font-display {
  font-family: var(--font-display);
}

/* Custom Scrollbar for level select and modals */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.6);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.5);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.7);
}

/* Glassmorphism Card Style */
.glass-panel {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.glass-modal {
  background: rgba(11, 17, 33, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Game Board & Grid */
#game-board-container {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-grid {
  display: grid;
  width: 100%;
  height: 100%;
  gap: 8px;
  position: relative;
  padding: 12px;
  border-radius: 1.5rem;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6), inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Grid slot placeholder (empty recessed cell) */
.grid-slot {
  width: 100%;
  height: 100%;
  border-radius: 0.85rem;
  background: rgba(2, 6, 23, 0.45);
  border: 1px dashed rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

/* Arrow Tile (Interactive) */
.arrow-tile {
  width: 100%;
  height: 100%;
  border-radius: 0.85rem;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease, border-color 0.15s ease, filter 0.15s ease;
  will-change: transform, opacity;
  box-shadow: 0 6px 12px -2px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2), inset 0 -2px 0 rgba(0, 0, 0, 0.4);
}

.arrow-tile:hover {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.15);
}

.arrow-tile:active {
  transform: translateY(1px) scale(0.97);
  box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.4), inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Direction Themes */
.arrow-tile[data-dir="up"] {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25) 0%, rgba(14, 116, 144, 0.35) 100%);
  border: 1.5px solid var(--color-up-border);
  color: var(--color-up);
  box-shadow: 0 6px 14px -3px var(--color-up-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.arrow-tile[data-dir="right"] {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.25) 0%, rgba(4, 120, 87, 0.35) 100%);
  border: 1.5px solid var(--color-right-border);
  color: var(--color-right);
  box-shadow: 0 6px 14px -3px var(--color-right-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.arrow-tile[data-dir="down"] {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.25) 0%, rgba(180, 83, 9, 0.35) 100%);
  border: 1.5px solid var(--color-down-border);
  color: var(--color-down);
  box-shadow: 0 6px 14px -3px var(--color-down-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.arrow-tile[data-dir="left"] {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.25) 0%, rgba(109, 40, 217, 0.35) 100%);
  border: 1.5px solid var(--color-left-border);
  color: var(--color-left);
  box-shadow: 0 6px 14px -3px var(--color-left-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

/* Arrow Icon inside Tile */
.arrow-icon-svg {
  width: 60%;
  height: 60%;
  transition: transform 0.2s ease;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.arrow-tile[data-dir="up"] .arrow-icon-svg { transform: rotate(0deg); }
.arrow-tile[data-dir="right"] .arrow-icon-svg { transform: rotate(90deg); }
.arrow-tile[data-dir="down"] .arrow-icon-svg { transform: rotate(180deg); }
.arrow-tile[data-dir="left"] .arrow-icon-svg { transform: rotate(270deg); }

/* Escape Animations (Arrow flies off the grid) */
.escape-up {
  animation: flyUp 0.38s cubic-bezier(0.12, 0.8, 0.32, 1) forwards !important;
  z-index: 50;
  pointer-events: none;
}
.escape-down {
  animation: flyDown 0.38s cubic-bezier(0.12, 0.8, 0.32, 1) forwards !important;
  z-index: 50;
  pointer-events: none;
}
.escape-left {
  animation: flyLeft 0.38s cubic-bezier(0.12, 0.8, 0.32, 1) forwards !important;
  z-index: 50;
  pointer-events: none;
}
.escape-right {
  animation: flyRight 0.38s cubic-bezier(0.12, 0.8, 0.32, 1) forwards !important;
  z-index: 50;
  pointer-events: none;
}

@keyframes flyUp {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  60% { opacity: 0.9; }
  100% { transform: translateY(-400px) scale(0.85); opacity: 0; }
}
@keyframes flyDown {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  60% { opacity: 0.9; }
  100% { transform: translateY(400px) scale(0.85); opacity: 0; }
}
@keyframes flyLeft {
  0% { transform: translateX(0) scale(1); opacity: 1; }
  60% { opacity: 0.9; }
  100% { transform: translateX(-400px) scale(0.85); opacity: 0; }
}
@keyframes flyRight {
  0% { transform: translateX(0) scale(1); opacity: 1; }
  60% { opacity: 0.9; }
  100% { transform: translateX(400px) scale(0.85); opacity: 0; }
}

/* Blocked Collision Bump Animations (Recoil bounce) */
.bump-up { animation: animBumpUp 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.bump-down { animation: animBumpDown 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.bump-left { animation: animBumpLeft 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.bump-right { animation: animBumpRight 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }

@keyframes animBumpUp {
  0% { transform: translateY(0); }
  35% { transform: translateY(-16px) scale(0.96); }
  65% { transform: translateY(4px) scale(1.02); }
  100% { transform: translateY(0) scale(1); }
}
@keyframes animBumpDown {
  0% { transform: translateY(0); }
  35% { transform: translateY(16px) scale(0.96); }
  65% { transform: translateY(-4px) scale(1.02); }
  100% { transform: translateY(0) scale(1); }
}
@keyframes animBumpLeft {
  0% { transform: translateX(0); }
  35% { transform: translateX(-16px) scale(0.96); }
  65% { transform: translateX(4px) scale(1.02); }
  100% { transform: translateX(0) scale(1); }
}
@keyframes animBumpRight {
  0% { transform: translateX(0); }
  35% { transform: translateX(16px) scale(0.96); }
  65% { transform: translateX(-4px) scale(1.02); }
  100% { transform: translateX(0) scale(1); }
}

/* Blocker Warning Pulse (The arrow that caused the block) */
.blocker-flash {
  animation: animBlockerFlash 0.45s ease-out;
  z-index: 20;
}
@keyframes animBlockerFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.8), 0 0 20px rgba(239, 68, 68, 0.6);
    border-color: #ef4444;
    filter: brightness(1.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.4), 0 0 30px rgba(239, 68, 68, 0.8);
    border-color: #f87171;
    transform: scale(1.06);
  }
  100% {
    box-shadow: inherit;
    border-color: inherit;
    transform: scale(1);
    filter: inherit;
  }
}

/* Hint Beacon Pulse Animation */
.hint-highlight {
  animation: animHintBeacon 1.2s infinite ease-in-out;
  z-index: 30;
}

@keyframes animHintBeacon {
  0% {
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.8), 0 0 25px rgba(56, 189, 248, 0.6);
    transform: scale(1);
    border-color: #38bdf8;
  }
  50% {
    box-shadow: 0 0 0 10px rgba(56, 189, 248, 0), 0 0 40px rgba(56, 189, 248, 0.9);
    transform: scale(1.08);
    border-color: #7dd3fc;
  }
  100% {
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0), 0 0 25px rgba(56, 189, 248, 0.6);
    transform: scale(1);
    border-color: #38bdf8;
  }
}

/* Star Pop Animation for Victory Modal */
.star-pop {
  animation: animStarPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes animStarPop {
  0% { transform: scale(0) rotate(-45deg); opacity: 0; }
  70% { transform: scale(1.3) rotate(15deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Combo Popup Badge */
.combo-badge {
  animation: animComboPop 0.8s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

@keyframes animComboPop {
  0% { transform: translate(-50%, 0) scale(0.5); opacity: 0; }
  30% { transform: translate(-50%, -15px) scale(1.15); opacity: 1; }
  80% { transform: translate(-50%, -25px) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -40px) scale(0.9); opacity: 0; }
}

/* Spark Particle Canvas */
#fx-canvas, #confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

#confetti-canvas {
  position: fixed;
  z-index: 100;
}

/* Subtle Shakes */
.shake-screen {
  animation: animShake 0.28s ease-in-out;
}
@keyframes animShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, -1px); }
  80% { transform: translate(3px, 1px); }
}

/* Custom Checkbox / Toggle Switches */
.toggle-checkbox:checked {
  right: 0;
  border-color: #38bdf8;
}
.toggle-checkbox:checked + .toggle-label {
  background-color: #38bdf8;
}

/* Responsive Grid Gap Adjustments */
@media (max-width: 480px) {
  #game-grid {
    gap: 6px;
    padding: 8px;
    border-radius: 1.25rem;
  }
  .arrow-tile {
    border-radius: 0.65rem;
  }
}

@media (max-height: 700px) {
  #game-board-container {
    max-width: 340px;
  }
}

