/* Global Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Inter", sans-serif;
  touch-action: none;
  background: url('../img/bg.png') center center / cover no-repeat fixed;
  color: #f9fafb;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Game Header */
.game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: none; /* Hidden by default */
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  z-index: 100;
  background: transparent; /* No background */
}

.game-header-left {
  width: 80px; /* Match right side for perfect centering */
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
}

.game-header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: auto;
}

.level-display {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.25rem;
  font-weight: 900;
  color: #FFC107; /* Vibrant gold */
  letter-spacing: 1px;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
}

.game-header-right {
  width: 80px; /* Match left side for perfect centering */
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

/* Show game header only when game is active */
body.game-active .game-header {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* Hide game header when level selection is active */
body.level-selection-active .game-header {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Icon Button Base Style - Dark Blue-Gray with Gold Border */
.icon-button {
  background: linear-gradient(to bottom, #2A2F4D 0%, #1A1F3A 100%);
  color: #FFC107;
  font-weight: 700;
  padding: 8px; /* Added padding */
  border: 2px solid rgba(255, 193, 7, 0.4);
  border-radius: 10px; /* Reduced from 14px */
  box-shadow: 0 4px 12px rgba(255, 193, 7, 0.3), 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: all 0.3s ease;
  cursor: pointer;
  font-size: 1.0625rem; /* Reduced by 15% from 1.25rem */
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 193, 7, 0.5), 0 4px 12px rgba(0, 0, 0, 0.6);
  background: linear-gradient(to bottom, #3A3F5D 0%, #2A2F4A 100%);
  border-color: rgba(255, 193, 7, 0.7);
  color: #FFD54F;
}

.icon-button:active {
  transform: translateY(0);
}

/* Individual Button States */
.sound-button.muted {
  opacity: 0.6;
}

/* Main Game Container */
.game-container {
  width: 100%;
  max-width: 32rem;
  margin: 0 auto;
  padding: 0rem 1rem 2rem;
  display: none; /* Hidden by default */
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* Action Buttons Bar */
.action-buttons-bar {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 500px;
  padding: 0.75rem;
  background: linear-gradient(to bottom, #5B3C2D 0%, #3F2719 100%);
  border: 1.5px solid #5B3C2D;
  border-radius: 12px; /* Reduced from 16px */
  margin-top: 1rem;
}

.action-button {
  flex: 1;
  background: linear-gradient(to bottom, #F8E7C5 0%, #E2C89F 100%);
  color: #5A3A28;
  border: none;
  border-radius: 8px; /* Reduced from 12px */
  padding: 12px 10px; /* Increased padding */
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.3px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  min-width: 0;
}

.action-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  background: linear-gradient(to bottom, #F8E7C5 0%, #E2C89F 100%);
  filter: brightness(1.1);
}

.action-button:active {
  transform: translateY(0);
}

.action-button.active {
  background: linear-gradient(to bottom, #FFC107 0%, #FF8F00 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(255, 193, 7, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.action-button.active:hover {
  background: linear-gradient(to bottom, #FFC107 0%, #FF8F00 100%);
  box-shadow: 0 6px 16px rgba(255, 193, 7, 0.5), 0 4px 12px rgba(0, 0, 0, 0.35);
}

.action-button i {
  font-size: 15.3px; /* Reduced by 15% from 18px */
  margin-bottom: 2px;
}

.action-button-label {
  font-weight: 700;
  font-size: 11px;
  line-height: 1.2;
}

.action-button-subtext {
  font-weight: 600;
  font-size: 9px;
  color: rgba(90, 58, 40, 0.7);
  line-height: 1;
}

.action-button.active .action-button-subtext {
  color: rgba(255, 255, 255, 0.8);
}

/* Show game container only when game is active */
body.game-active .game-container {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

.game-title {
  font-size: 3.5rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 2rem;
  background: linear-gradient(135deg, #e9af51 0%, #fbbf24 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 30px rgba(233, 175, 81, 0.5);
  animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
  from {
    filter: drop-shadow(0 0 20px rgba(233, 175, 81, 0.3));
  }
  to {
    filter: drop-shadow(0 0 30px rgba(233, 175, 81, 0.6));
  }
}

.game-board-container {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  /* Outer Frame */
  background: #F8E7C5;
  border: 3px solid #5B3C2D;
  border-radius: 18px;
  padding: 3px;
  box-shadow: none;
}

/* Game Board - Inner Frame (Tray Effect) */
#game-board,
.game-board {
  display: grid;
  gap: 4px;
  padding: 6px;
  background: rgba(78, 46, 29, 0.96);
  border: 1.5px solid #A1765D;
  border-radius: 14px;
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
  box-shadow: none;
  height: auto;
}

/* Dynamic grid columns */
.game-board.columns-3 { grid-template-columns: repeat(3, 1fr); max-width: 350px; }
.game-board.columns-4 { grid-template-columns: repeat(4, 1fr); max-width: 400px; }
.game-board.columns-5 { grid-template-columns: repeat(5, 1fr); max-width: 450px; }
.game-board.columns-6 { grid-template-columns: repeat(6, 1fr); max-width: 500px; }
.game-board.columns-7 { grid-template-columns: repeat(7, 1fr); max-width: 550px; gap: 6px; padding: 10px; }
.game-board.columns-8 { grid-template-columns: repeat(8, 1fr); max-width: 600px; gap: 6px; padding: 10px; }
.game-board.columns-9 { grid-template-columns: repeat(9, 1fr); max-width: 650px; gap: 6px; padding: 10px; }
.game-board.columns-10 { grid-template-columns: repeat(10, 1fr); max-width: 700px; gap: 6px; padding: 10px; }
.game-board.columns-11 { grid-template-columns: repeat(11, 1fr); max-width: 750px; gap: 6px; padding: 10px; }
.game-board.columns-12 { grid-template-columns: repeat(12, 1fr); max-width: 800px; gap: 6px; padding: 10px; }

/* Tile Styles */
.tile {
  transition: opacity 200ms ease, all 0.2s ease;
  will-change: transform, opacity;
  background: linear-gradient(to bottom, #F8E7C5 0%, #E2C89F 100%);
  color: #5A3A28;
  border: 2px solid #5B3C2D;
  border-radius: 8px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 5px 9px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  aspect-ratio: 1 / 1;
  font-size: 32px; /* Default */
}

/* Dynamic font sizes for tiles */
.tile.font-size-large { font-size: 32px; }
.tile.font-size-medium { font-size: 24px; }
.tile.font-size-small { font-size: 18px; }
.tile.font-size-xsmall { font-size: 16px; }
.tile.font-size-xxsmall { font-size: 14px; }

.tile:hover {
  transform: translateY(-1px);
}

.tile:active {
  transform: translateY(0);
}

/* Highlighted tiles (during swap mode) */
.tile.highlighted {
  background: linear-gradient(to bottom, #FFC107 0%, #FF8F00 100%);
  border: 3px solid #5B3C2D;
  box-shadow: 0 5px 14px rgba(255, 193, 7, 0.55), 0 0 2px rgba(255, 193, 7, 0.55);
}

.empty-tile {
  background: transparent !important;
  border: 2px solid rgba(161, 118, 93, 0.5) !important; /* #A1765D at 50% opacity */
  box-shadow: none !important;
  cursor: default;
  opacity: 0;
}

.empty-tile:hover {
  transform: none;
  box-shadow: none;
}

/* Modal Styles */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 1000;
  overflow-y: auto;
}

.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: linear-gradient(to bottom, #5B3C2D 0%, #3F2719 100%);
  border: 1.5px solid #A1765D;
  border-radius: 24px;
  box-shadow: none;
  padding: 0;
  max-width: 42rem;
  width: 100%;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  overflow: hidden;
  position: relative;
}

.goal-modal {
  max-width: 400px !important;
  width: 90% !important;
}

.win-modal {
  max-width: 500px !important;
  width: auto !important;
}

.modal-backdrop.show .modal {
  transform: scale(1);
}

.modal-header {
  padding: 18px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(161, 118, 93, 0.6); /* #A1765D at 60% opacity */
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.goal-modal .modal-header {
  padding: 12px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.goal-modal .modal-title {
  margin: 0;
  flex: 1;
  text-align: center;
}

.modal-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 22px;
  font-weight: 900;
  color: #EBC147; /* vibrant mustard yellow */
  margin: 0;
  letter-spacing: 1.5px;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
}

/* Level Selection Screen (Full Screen) */
.level-selection-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url('../img/background.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  overflow-y: auto;
  padding: 32px 12px 8px;
  pointer-events: none;
}

.level-selection-screen.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.level-selection-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Hide game elements when level selection is shown */
body.level-selection-active .game-header,
body.level-selection-active .game-container,
body.level-selection-active .game-board-container,
body.level-selection-active #game-board,
body.level-selection-active .action-buttons-bar {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Hide level selection when game is active */
body.game-active .level-selection-screen {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.level-selection-active .level-selection-screen {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

body.level-selection-active .level-selection-screen.hidden {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

/* Initial state: show level selection, hide game */
body:not(.game-active) .game-header,
body:not(.game-active) .game-container {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}


.level-selection-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding-top: 24px;
  min-height: 100vh;
  justify-content: flex-start;
}

.game-logo {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.logo-image {
  width: min(320px, 74vw);
  height: auto;
  display: block;
  filter: drop-shadow(2px 2px 6px rgba(0, 0, 0, 0.75));
}

.logo-image::selection {
  background: transparent;
}

.logo-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 3.5px;
  margin: 0;
  /* 3-color horizontal gradient: light gold -> vibrant gold -> dark orange-gold */
  background: linear-gradient(90deg, #FFD54F 0%, #FFC107 50%, #FF8F00 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: inline-block;
  /* Primary shadow: black 80% opacity, offset (2,2), blur 6px */
  /* Glow shadow: gold 50% opacity, offset (0,0), blur 15px */
  filter: drop-shadow(2px 2px 6px rgba(0, 0, 0, 0.8)) drop-shadow(0 0 15px rgba(255, 193, 7, 0.5));
  white-space: nowrap;
  overflow: visible;
  position: relative;
}

.logo-decorative-line {
  width: 110px;
  height: 4px;
  background: linear-gradient(90deg, #FFD54F 0%, #FF8F00 100%);
  border-radius: 2px;
  margin-top: 16px;
}

.level-grid-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* Default: 3 columns for small screens */
  gap: 8px;
  width: 100%;
  max-width: 100%;
  padding: 0 12px;
}


/* Level Card - Wooden Frame Style */
.level-card {
  aspect-ratio: 0.9;
  border-radius: 10px; /* Reduced corner radius */
  border: 1.5px solid #5B3C2D;
  background: #F8E7C5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: 'Orbitron', sans-serif;
  min-height: 60px;
  padding: 8px 4px; /* Increased padding */
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  overflow: visible; /* Allow icons to go outside */
  width: 100%;
}

/* Inner Container (Inset Effect) */
.level-card::before {
  content: "";
  position: absolute;
  top: 1.5px;
  left: 1.5px;
  right: 1.5px;
  bottom: 1.5px;
  border-radius: 10.5px;
  border: 0.5px solid #A1765D;
  pointer-events: none;
}

.level-card.level-completed {
  /* Completed levels keep the same wooden style */
  opacity: 1;
}

.level-check-icon {
  position: relative; /* Changed from absolute to relative */
  font-size: 20px; /* Increased size */
  color: #FFC107; /* Changed to gold to match theme */
  z-index: 1;
  margin-top: 2px;
  text-shadow: 0 0 4px rgba(255, 193, 7, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  /* No background, no border-radius, no box-shadow */
}

.level-card.level-locked {
  opacity: 0.6;
  cursor: not-allowed;
}

.level-card.level-unlocked:hover,
.level-card.level-completed:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.level-card.level-locked:hover {
  transform: none;
}

.level-icon {
  position: relative; /* Changed from absolute to relative */
  font-size: 18px; /* Increased size */
  line-height: 1;
  color: rgba(90, 58, 40, 0.7);
  z-index: 1;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* No background, no border-radius, no box-shadow */
}

.level-number {
  font-size: 28px; /* Increased from 21px */
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #5A3A28;
  z-index: 1;
  margin-bottom: 4px;
}

/* Increase by 50% on desktop/web screens */
@media (min-width: 1025px) {
  .level-number {
    font-size: 42px; /* 50% larger (28px * 1.5) */
  }
  
  .level-grid-size {
    font-size: 30px; /* 50% larger (20px * 1.5) */
  }
}

.level-grid-size {
  font-size: 20px; /* Increased from 16px */
  font-weight: 700;
  letter-spacing: 0.5px;
  color: rgba(90, 58, 40, 0.8);
  z-index: 1;
  margin-top: 4px;
  margin-bottom: 4px;
}

/* Dot indicator removed - no longer needed */



.start-modal-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.instructions-section {
  flex: 1;
  order: 2;
}

.instructions h3 {
  color: #FFC107; /* vibrant gold */
  font-size: 1.25rem;
  margin-bottom: 1rem;
  font-weight: 700;
}

.instructions h3:first-child {
  margin-top: 0;
}

.instructions ul {
  list-style: none;
  padding: 0;
}

.instructions li {
  margin-bottom: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(161, 118, 93, 0.2);
  font-size: 1rem;
  line-height: 1.5;
  color: #ffffff;
}

.instructions li:last-child {
  border-bottom: none;
}

.board-preview-section {
  flex: 0 0 auto;
  text-align: center;
  order: 1;
}

.board-preview-section h3 {
  color: #FFC107; /* vibrant gold */
  font-size: 1.25rem;
  margin-bottom: 1rem;
  font-weight: 700;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
}

.board-preview-section {
  position: relative;
}

.preview-board {
  display: grid;
  gap: 4px;
  width: 180px;
  height: 180px;
  padding: 6px;
  background: rgba(78, 46, 29, 0.96); /* #4E2E1D with 96% opacity */
  border: 1.5px solid #A1765D;
  border-radius: 14px;
  margin: 0 auto;
  box-shadow: none;
  position: relative;
}

.preview-board::before {
  content: "";
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  bottom: -3px;
  background: #F8E7C5;
  border: 3px solid #5B3C2D;
  border-radius: 18px;
  z-index: -1;
}

.preview-tile {
  background: linear-gradient(to bottom, #F8E7C5 0%, #E2C89F 100%);
  color: #5A3A28;
  border: 2px solid #5B3C2D;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 5px 9px rgba(0, 0, 0, 0.25);
  aspect-ratio: 1 / 1;
}

.preview-empty {
  background: transparent;
  border: 2px solid rgba(161, 118, 93, 0.5); /* #A1765D at 50% opacity */
  box-shadow: none;
  opacity: 0;
}

.modal-footer {
  padding: 0px 24px 24px;
  text-align: center;
}

.start-button,
.play-again-button,
.next-level-button {
  background: linear-gradient(to bottom, #FFC107 0%, #FF8F00 100%);
  color: #ffffff;
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  padding: 14px 22px; /* Increased padding */
  border: 2px solid rgba(255, 193, 7, 0.6);
  border-radius: 8px; /* Reduced from 12px */
  box-shadow: 0 4px 12px rgba(255, 193, 7, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 200px;
  justify-content: center;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7);
}

.start-button:hover,
.play-again-button:hover,
.next-level-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 193, 7, 0.5), 0 4px 10px rgba(0, 0, 0, 0.35);
}

.start-button:active,
.play-again-button:active,
.next-level-button:active {
  transform: translateY(0);
}

.next-level-button {
  margin-right: 1rem;
}

.button-icon {
  font-size: 1.02rem; /* Reduced by 15% from 1.2rem */
  line-height: 1;
}

/* Win Modal Specific Styles */
.win-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.5rem;
  font-weight: 900;
  color: #EBC147; /* vibrant mustard yellow */
  margin: 0;
  letter-spacing: 1.5px;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
}

.win-message {
  font-size: 1.125rem;
  margin: 1.5rem;
  color: #ffffff;
  text-align: center;
}

.final-stats {
  display: flex;
  justify-content: center;
  margin: 1.5rem;
  gap: 0;
  align-items: center;
}

.final-stats .stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.5rem;
  position: relative;
}

.final-stats .stat-item:not(:last-child)::after {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 40px;
  background: rgba(255, 193, 7, 0.3); /* #FFC107 at 30% opacity */
}

.final-stats .stat-item .stat-icon {
  font-size: 32px;
  line-height: 1;
}

.final-stats .stat-item .stat-label {
  font-size: 12px;
  color: #FFC107; /* vibrant gold */
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.final-stats .stat-item .stat-value {
  font-size: 20px;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 1px;
  margin: 0;
}

/* Goal Modal Styles */
.goal-modal {
  max-width: 400px;
  width: 90%;
  position: relative;
}

.goal-modal .modal-title {
  color: #EBC147; /* vibrant mustard yellow */
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
  font-size: 1.5rem;
}

.goal-modal .modal-title #goal-level {
  font-size: 2rem;
  font-weight: 900;
}

.goal-message {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: #ffffff;
  text-align: center;
}

.goal-board-container {
  display: flex;
  justify-content: center;
  margin: 0.5rem 0;
  position: relative;
  width: 100%;
  overflow: hidden;
}

.goal-board {
  display: grid;
  gap: 4px;
  padding: 6px;
  background: rgba(78, 46, 29, 0.96); /* #4E2E1D with 96% opacity */
  border: 1.5px solid #A1765D;
  border-radius: 14px;
  box-shadow: none;
  width: 100%;
  max-width: 100%;
  position: relative;
  /* Height determined by content */
  height: auto;
  /* Prevent overflow */
  overflow: hidden;
  box-sizing: border-box;
  /* Ensure tiles fit within container */
  min-width: 0;
  min-height: 0;
}

/* Dynamic grid columns for goal board */
.goal-board.columns-3 { grid-template-columns: repeat(3, 1fr); max-width: 350px; }
.goal-board.columns-4 { grid-template-columns: repeat(4, 1fr); max-width: 400px; }
.goal-board.columns-5 { grid-template-columns: repeat(5, 1fr); max-width: 450px; }
.goal-board.columns-6 { grid-template-columns: repeat(6, 1fr); max-width: 500px; }
.goal-board.columns-7 { grid-template-columns: repeat(7, 1fr); max-width: 550px; gap: 6px; padding: 10px; }
.goal-board.columns-8 { grid-template-columns: repeat(8, 1fr); max-width: 600px; gap: 6px; padding: 10px; }
.goal-board.columns-9 { grid-template-columns: repeat(9, 1fr); max-width: 650px; gap: 6px; padding: 10px; }
.goal-board.columns-10 { grid-template-columns: repeat(10, 1fr); max-width: 700px; gap: 6px; padding: 10px; }
.goal-board.columns-11 { grid-template-columns: repeat(11, 1fr); max-width: 750px; gap: 6px; padding: 10px; }
.goal-board.columns-12 { grid-template-columns: repeat(12, 1fr); max-width: 800px; gap: 6px; padding: 10px; }

.goal-board::before {
  content: "";
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  bottom: -3px;
  background: #F8E7C5;
  border: 3px solid #5B3C2D;
  border-radius: 18px;
  z-index: -1;
}

.goal-tile {
  background: linear-gradient(to bottom, #F8E7C5 0%, #E2C89F 100%);
  color: #5A3A28;
  border: 2px solid #5B3C2D;
  border-radius: 8px;
  font-size: 1.5rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 5px 9px rgba(0, 0, 0, 0.25);
  aspect-ratio: 1 / 1;
  /* Prevent tiles from overflowing */
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  /* Ensure tiles fit within grid */
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.goal-empty {
  background: transparent;
  border: 2px solid rgba(161, 118, 93, 0.5); /* #A1765D at 50% opacity */
  box-shadow: none;
  opacity: 0;
}

/* Close button in top-right corner - Wood Theme */
.close-goal-button-icon {
  position: relative;
  width: 30px;
  height: 30px;
  background: #F8E7C5; /* Light beige/cream */
  color: #5A3A28; /* Dark brown */
  border: 1.5px solid #5B3C2D; /* Dark brown border */
  border-radius: 50%; /* Properly circular */
  box-shadow: none;
  transition: all 0.3s ease;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 6px; /* Added padding */
  font-size: 15.3px; /* Reduced by 15% from 18px */
  flex-shrink: 0;
  margin-left: auto;
}

.close-goal-button-icon:hover {
  transform: scale(1.05);
  background: #E2C89F; /* Slightly darker beige on hover */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.close-goal-button-icon:active {
  transform: scale(0.98);
  background: #D4A046; /* Even darker on active */
}

/* Responsive Design */
@media (max-width: 1024px) {
  .modal {
    max-width: 90vw;
  }
  
  .win-modal {
    max-width: 500px !important;
    width: auto !important;
  }
}

/* Responsive Logo Sizing */
@media (min-width: 1024px) {
  .logo-title {
    font-size: 40px;
    letter-spacing: 3.5px;
  }
  .logo-decorative-line {
    width: 110px;
    height: 4px;
    margin-top: 16px;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .logo-title {
    font-size: 36px;
    letter-spacing: 3px;
  }
  .logo-decorative-line {
    width: 100px;
    height: 3.5px;
    margin-top: 14px;
  }
}

@media (min-width: 480px) and (max-width: 767px) {
  .logo-title {
    font-size: 32px;
    letter-spacing: 2.5px;
  }
  .logo-decorative-line {
    width: 90px;
    height: 3px;
    margin-top: 12px;
  }
}

@media (min-width: 360px) and (max-width: 479px) {
  .logo-title {
    font-size: 28px;
    letter-spacing: 2px;
  }
  .logo-decorative-line {
    width: 80px;
    height: 2.5px;
    margin-top: 10px;
  }
}

@media (max-width: 359px) {
  .logo-title {
    font-size: 24px;
    letter-spacing: 1.5px;
  }
  .logo-decorative-line {
    width: 70px;
    height: 2px;
    margin-top: 8px;
  }
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* Mobile Landscape (orientation: landscape) */
@media (orientation: landscape) and (max-height: 600px) {
  .game-container {
    padding: 5rem 1rem 1rem;
  }

  .action-buttons-bar {
    padding: 0.5rem;
    gap: 0.4rem;
  }

  .action-button {
    padding: 8px 6px;
    font-size: 9px;
  }

  .action-button i {
    font-size: 13px; /* Reduced by 15% */
  }

  .level-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    padding: 0 8px;
  }

  .level-card {
    min-height: 50px;
    padding: 6px 3px;
  }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
  .game-header {
    padding: 0.5rem;
  }

  .game-header-left {
    width: 60px; /* Match right for centering */
  }

  .game-header-right {
    width: 60px;
  }

  .icon-button {
    width: 32px;
    height: 32px;
    font-size: 0.8075rem; /* Reduced by 15% from 0.95rem */
    padding: 6px; /* Added padding */
    border-radius: 50%; /* Perfectly round */
  }

  .level-display {
    font-size: 0.95rem;
  }

  .game-container {
    padding: 6rem 0.5rem 1rem;
  }

  .action-buttons-bar {
    gap: 0.5rem; /* Increased gap for round buttons */
    padding: 0.75rem; /* Increased padding */
    flex-wrap: wrap;
    border-radius: 10px; /* Reduced */
    justify-content: center;
  }

  .action-button {
    flex: 0 0 auto; /* Don't flex, use fixed size */
    width: 70px; /* Fixed width for perfect circle */
    height: 70px; /* Fixed height for perfect circle */
    padding: 12px; /* Increased padding */
    font-size: 9px;
    border-radius: 50%; /* Perfectly round on mobile */
    aspect-ratio: 1 / 1; /* Ensure perfect circle */
    min-width: 70px;
    min-height: 70px;
    max-width: 70px;
    max-height: 70px;
  }

  .action-button i {
    font-size: 11.9px; /* Reduced by 15% from 14px */
  }

  .action-button-label {
    font-size: 9px;
  }

  .action-button-subtext {
    font-size: 7px;
  }

  .level-display {
    font-size: 1rem;
  }

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

  .tile {
    font-size: 1.25rem;
  }

  .modal-backdrop {
    padding: 0.25rem;
  }

  .modal {
    margin: 0.5rem;
    max-width: calc(100vw - 1rem);
  }

  .win-modal {
    max-width: 90% !important;
    width: auto !important;
  }

  .modal-header {
    padding: 18px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .modal-title {
    font-size: 18px;
  }

 

  .modal-footer {
    padding: 0px 16px 20px;
  }

  .instructions h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
  }

  .level-selection-screen {
    padding: 16px 8px 4px;
  }

  .level-selection-content {
    gap: 16px;
    padding-top: 16px;
  }

  .level-grid {
    grid-template-columns: repeat(3, 1fr) !important; /* 3 columns for small mobile - force override */
    gap: 10px !important;
    padding: 0 12px !important;
  }

  .level-card {
    min-height: 110px !important; /* Increased card size for small mobile */
    padding: 10px 6px !important; /* Increased padding */
    border-radius: 8px;
  }

  .level-number {
    font-size: 22px; /* Increased from 15px */
    margin-bottom: 2px;
  }

  .level-grid-size {
    font-size: 16px; /* Increased from 12px */
    margin-top: 2px;
  }

  .level-icon {
    font-size: 16px; /* Slightly smaller for mobile */
    margin-top: 2px;
  }

  .level-check-icon {
    font-size: 18px; /* Slightly smaller for mobile */
    margin-top: 2px;
  }

  .start-button,
  .play-again-button,
  .next-level-button {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    border-radius: 8px; /* Reduced */
  }

  .goal-modal {
    max-width: 300px !important;
    width: 80% !important;
  }

  .goal-modal .modal-title {
    font-size: 1.125rem;
  }

  .goal-modal .modal-title #goal-level {
    font-size: 1.5rem;
  }

  .goal-tile {
    font-size: 1rem;
  }

  .goal-board {
    max-width: 100%;
  }

  .close-goal-button-icon {
    width: 28px;
    height: 28px;
    font-size: 13.6px; /* Reduced by 15% from 16px */
    padding: 6px; /* Added padding */
    right: 8px;
  }

  /* Additional responsive adjustments for small mobile */
  .game-board-container {
    max-width: 100%;
    padding: 2px;
  }

  .game-board {
    padding: 4px;
    gap: 3px;
  }

  .tile {
    font-size: 1.25rem;
    border-radius: 6px; /* Reduced */
  }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
  .game-header {
    padding: 0.5rem 0.75rem;
  }

  .game-header-left {
    width: 36px;
  }

  .game-header-right {
    width: 70px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 0.935rem; /* Reduced by 15% from 1.1rem */
    padding: 7px; /* Added padding */
    border-radius: 8px; /* Reduced */
  }

  .level-display {
    font-size: 1.125rem;
  }

  .game-container {
    padding: 7rem 1rem 1rem;
  }

  .action-buttons-bar {
    gap: 0.4rem;
    padding: 0.6rem;
    border-radius: 11px; /* Reduced */
  }

  .action-button {
    padding: 11px 9px; /* Increased padding */
    font-size: 10px;
    border-radius: 7px; /* Reduced */
  }

  .action-button i {
    font-size: 13.6px; /* Reduced by 15% from 16px */
  }

  .action-button-label {
    font-size: 10px;
  }

  .action-button-subtext {
    font-size: 8px;
  }

  .level-grid {
    grid-template-columns: repeat(3, 1fr) !important; /* 3 columns for mobile - force override */
    gap: 12px !important;
    padding: 0 16px !important;
  }

  .level-card {
    min-height: 120px !important; /* Increased card size for mobile */
    padding: 12px 8px !important; /* Increased padding */
    border-radius: 9px;
  }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
  .game-header {
    padding: 0.6rem 0.875rem;
  }

  .icon-button {
    width: 38px;
    height: 38px;
    font-size: 1.0625rem; /* Reduced by 15% */
    padding: 7px;
    border-radius: 9px;
  }

  .game-container {
    padding: 6.5rem 1.25rem 1.5rem;
  }

  .action-buttons-bar {
    padding: 0.7rem;
    border-radius: 11px;
  }

  .action-button {
    padding: 11px 9px;
    border-radius: 7px;
  }

  .action-button i {
    font-size: 14.45px; /* Reduced by 15% */
  }

  .level-grid {
    grid-template-columns: repeat(5, 1fr); /* 5 columns for tablet portrait */
    gap: 8px;
    padding: 0 12px;
    max-width: 700px;
  }

  .level-card {
    min-height: 80px;
    padding: 8px 5px;
    border-radius: 10px;
  }
}

/* Tablet Landscape (769px-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .game-header {
    padding: 0.7rem 1rem;
  }

  .icon-button {
    width: 38px;
    height: 38px;
    font-size: 1.0625rem;
    padding: 7px;
    border-radius: 9px;
  }

  .game-container {
    padding: 6rem 1.5rem 2rem;
  }

  .action-buttons-bar {
    padding: 0.8rem;
    border-radius: 11px;
  }

  .action-button {
    padding: 12px 10px;
    border-radius: 7px;
  }

  .action-button i {
    font-size: 15.3px; /* Reduced by 15% */
  }

  .level-grid {
    grid-template-columns: repeat(6, 1fr); /* 6 columns for tablet landscape */
    gap: 10px;
    padding: 0 16px;
    max-width: 900px;
  }

  .level-card {
    min-height: 90px;
    padding: 10px 6px;
    border-radius: 10px;
  }
}

/* Desktop (≥1025px) - Base styles already defined above */
@media (min-width: 1025px) {
  .game-header {
    padding: 0.75rem 1rem;
  }

  .icon-button {
    width: 40px;
    height: 40px;
    font-size: 1.0625rem; /* Reduced by 15% */
    padding: 8px;
    border-radius: 10px;
  }

  .game-container {
    padding: 5rem 1.5rem 2rem;
  }

  .action-buttons-bar {
    padding: 0.75rem;
    border-radius: 12px;
  }

  .action-button {
    padding: 12px 10px;
    border-radius: 8px;
  }

  .action-button i {
    font-size: 15.3px; /* Reduced by 15% */
  }

  .level-grid {
    grid-template-columns: repeat(6, 1fr); /* 6 columns for desktop */
    gap: 12px;
    padding: 0 20px;
    max-width: 1000px;
  }

  .level-card {
    min-height: 100px;
    padding: 12px 8px;
    border-radius: 10px;
  }
}

/* Legacy max-width: 768px - keeping for compatibility */
@media (max-width: 768px) {
  .game-header {
    padding: 0.5rem 0.75rem;
  }

  .game-header-left {
    width: 36px;
  }

  .game-header-right {
    width: 70px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 0.935rem; /* Reduced by 15% */
    padding: 7px;
    border-radius: 8px;
  }

  .level-display {
    font-size: 1.125rem;
  }

  .game-container {
    padding: 7rem 1rem 1rem;
  }

  .action-buttons-bar {
    gap: 0.4rem;
    padding: 0.6rem;
    border-radius: 11px;
  }

  .action-button {
    padding: 11px 9px; /* Increased padding */
    font-size: 10px;
    border-radius: 7px; /* Reduced */
  }

  .action-button i {
    font-size: 13.6px; /* Reduced by 15% */
  }

  .action-button-label {
    font-size: 10px;
  }

  .action-button-subtext {
    font-size: 8px;
  }

  .level-display {
    font-size: 1.125rem;
  }

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

  .tile {
    font-size: 1.5rem;
  }

  .modal {
    margin: 1rem;
    max-width: calc(100vw - 2rem);
  }

  .win-modal {
    max-width: 500px !important;
    width: auto !important;
  }

  .modal-header {
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .modal-title {
    font-size: 20px;
  }

 

  .modal-footer {
    padding: 0px 24px 24px;
  }

  .instructions h3 {
    font-size: 1.125rem;
  }

  .instructions li {
    font-size: 0.95rem;
    padding: 0.4rem 0;
  }

  .start-button,
  .play-again-button,
  .next-level-button {
    width: 100%;
    min-width: auto;
    margin-right: 0;
    margin-bottom: 0.5rem;
  }

  .next-level-button {
    margin-right: 0;
  }

  .modal-backdrop {
    padding: 0.5rem;
  }

  .level-selection-screen {
    padding: 24px 10px 6px;
  }


  .level-selection-content {
    gap: 24px;
    padding-top: 24px;
  }

  /* Level grid and card styles for mobile (≤640px) are handled in @media (max-width: 640px) */
  /* This breakpoint (≤768px) only applies to screens between 641px-768px (tablet portrait) */
  .level-grid {
    grid-template-columns: repeat(5, 1fr); /* 5 columns for tablet portrait (641px-768px) */
    gap: 8px;
    padding: 0 12px;
    max-width: 100%;
  }

  .level-card {
    min-height: 80px;
    padding: 8px 5px;
    border-radius: 9px;
  }

  .level-number {
    font-size: 26px; /* Increased from 18px */
    margin-bottom: 3px;
  }

  .level-grid-size {
    font-size: 19px; /* Increased from 14px */
    margin-top: 3px;
  }

  .level-icon {
    font-size: 17px; /* Slightly smaller for tablet */
    margin-top: 2px;
  }

  .level-check-icon {
    font-size: 19px; /* Slightly smaller for tablet */
    margin-top: 2px;
  }

  .goal-modal {
    max-width: 350px !important;
    width: 85% !important;
  }

  .goal-modal .modal-title {
    font-size: 1.25rem;
  }

  .goal-modal .modal-title #goal-level {
    font-size: 1.75rem;
  }

  .goal-tile {
    font-size: 1.25rem;
  }

  .goal-board {
    max-width: 100%;
  }
}

/* Duplicate removed - now handled in Small Mobile section above */

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

  .tile {
    font-size: 1.25rem;
  }

  .modal-backdrop {
    padding: 0.25rem;
  }

  /* Additional responsive adjustments for small mobile */
  .game-board-container {
    max-width: 100%;
    padding: 2px;
  }

  .game-board {
    padding: 4px;
    gap: 3px;
  }

  .tile {
    font-size: 1.25rem;
    border-radius: 6px; /* Reduced */
  }

  .modal {
    margin: 0.5rem;
    max-width: calc(100vw - 1rem);
  }

  .modal-header {
    padding: 18px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .modal-title {
    font-size: 18px;
  }

 

  .modal-footer {
    padding: 0px 16px 20px;
  }

  .instructions h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
  }

  .level-selection-screen {
    padding: 16px 8px 4px;
  }


  .level-selection-content {
    gap: 16px;
    padding-top: 16px;
  }


  .level-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
  }

  .level-card {
    min-height: 35px;
    padding: 1px;
  }

  .level-number {
    font-size: 22px; /* Increased from 15px */
    margin-bottom: 2px;
  }

  .level-grid-size {
    font-size: 16px; /* Increased from 12px */
    margin-top: 2px;
  }

  .level-icon {
    font-size: 16px; /* Slightly smaller for mobile */
    margin-top: 2px;
  }

  .level-check-icon {
    font-size: 18px; /* Slightly smaller for mobile */
    margin-top: 2px;
  }


  .start-button,
  .play-again-button,
  .next-level-button {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
  }

  .goal-modal {
    max-width: 300px !important;
    width: 80% !important;
  }

  .goal-modal .modal-title {
    font-size: 1.125rem;
  }

  .goal-modal .modal-title #goal-level {
    font-size: 1.5rem;
  }

  .goal-tile {
    font-size: 1rem;
  }

  .goal-board {
    max-width: 100%;
  }

  .close-goal-button-icon {
    width: 28px;
    height: 28px;
    font-size: 13.6px; /* Reduced by 15% from 16px */
    padding: 6px; /* Added padding */
    right: 8px;
  }
}


/* Landscape Mobile (orientation: landscape) - Enhanced */
@media (orientation: landscape) and (max-height: 600px) {
  .game-header {
    padding: 0.4rem 0.75rem;
  }

  .icon-button {
    width: 32px;
    height: 32px;
    font-size: 0.8075rem; /* Reduced by 15% */
    padding: 6px;
    border-radius: 8px;
  }

  .game-container {
    padding: 4rem 1rem 0.5rem;
  }

  .action-buttons-bar {
    padding: 0.5rem;
    gap: 0.3rem;
    border-radius: 10px;
  }

  .action-button {
    padding: 8px 6px;
    font-size: 9px;
    border-radius: 6px; /* Reduced */
  }

  .action-button i {
    font-size: 11.9px; /* Reduced by 15% */
  }

  .modal {
    max-width: 28rem;
    max-height: 85vh;
    overflow-y: auto;
  }

  .modal-header {
    padding: 0.75rem 1.5rem 0.5rem;
  }

  .modal-title {
    font-size: 1.5rem;
  }

  .modal-content {
    max-height: calc(85vh - 120px);
    overflow-y: auto;
  }

  .modal-footer {
    padding: 0px 1.5rem 0.75rem;
    flex-shrink: 0; 
  }

  .start-modal-layout {
    flex-direction: column;
    gap: 0.75rem;
  }

  .board-preview-section {
    display: none;
  }

  .instructions h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
  }

  .instructions li {
    font-size: 0.85rem;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    line-height: 1.3;
  }

  .start-button,
  .play-again-button,
  .next-level-button {
    padding: 0.6rem 1.25rem;
    font-size: 0.95rem;
    min-width: 140px;
  }

  /* Custom Scrollbar for Landscape Modal */
  .modal-content::-webkit-scrollbar {
    width: 6px;
  }

  .modal-content::-webkit-scrollbar-track {
    background: rgba(233, 175, 81, 0.1);
    border-radius: 3px;
  }

  .modal-content::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #e9af51 0%, #d4a046 100%);
    border-radius: 3px;
  }

  .modal-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #fbbf24 0%, #e9af51 100%);
  }

  /* Firefox scrollbar */
  .modal-content {
    scrollbar-width: thin;
    scrollbar-color: #e9af51 rgba(233, 175, 81, 0.1);
  }

  .goal-board {
    max-width: 180px;
  }
}

/* Utility Classes */
.hidden {
  display: none !important;
}

.flex {
  display: flex;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.min-h-screen {
  min-height: 100vh;
}
