/*
================================================================================
|                                                                              |
|                              SAVE BOID STYLES                                |
|                        Refactored & Optimized for v2.0                         |
|                                                                              |
================================================================================
*/

/*
================================================================================
| 0. FONT DEFINITIONS                                                          |
| NOTE: The 'OTS parsing error' indicates your font files may be corrupt.      |
| Please re-download them from the original source (e.g., Google Fonts).       |
================================================================================
*/

/* --- Amatic SC --- */
@font-face {
  font-family: 'Amatic SC';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/amatic-sc-v27-latin_latin-ext-regular.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Amatic SC';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/amatic-sc-v27-latin_latin-ext-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* --- Cinzel (Variable) --- */
@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 400 900;
  /* Defines the variable weight range */
  font-display: swap;
  src: url('../fonts/Cinzel-VariableFont_wght.ttf') format('truetype-variations');
}

/* --- Cinzel Decorative --- */
@font-face {
  font-family: 'Cinzel Decorative';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/cinzel-decorative-v18-latin_latin-ext-regular.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Cinzel Decorative';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/cinzel-decorative-v18-latin_latin-ext-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


/*
================================================================================
| 1. ROOT & BASE STYLES                                                        |
================================================================================
*/

:root {
  /* Color Palette */
  --primary-dark: #0c1821;
  --primary-blue: #1e2a3a;
  --accent-blue: #2c3e50;
  --accent-cyan: #008080;
  --accent-bright: #20b2aa;
  --accent-light: #40e0d0;
  --accent-vibrant: #00ffff;
  --success-green: #00d4aa;
  --warning-orange: #ff6b47;
  --warning-red: #ff4444;
  --gold: #ffd700;
  --text-primary: #ffffff;
  --text-secondary: #a0c4c7;
  --text-tertiary: #6b8e8e;

  /* Typography */
  --font-primary: 'Cinzel', serif;
  --font-accent: 'Amatic SC', cursive;
  --font-title: 'Cinzel Decorative', serif;

  /* UI Variables */
  --border-radius: 8px;
  --border-radius-large: 16px;
  --transition-speed: 0.3s;
  --shadow-small: 0 2px 10px rgba(0, 0, 0, 0.3);
  --shadow-large: 0 10px 30px rgba(0, 0, 0, 0.5);
  --touch-target: 44px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--primary-dark);
  font-family: var(--font-primary);
  color: var(--text-primary);
  position: fixed;
  /* Prevents scroll bounce on mobile */
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  /* Prevents panning and zooming */
}

/* Accessibility Focus Styles */
:is(button, input, select, .level-item):focus-visible {
  outline: 3px solid var(--accent-light);
  outline-offset: 3px;
  border-radius: var(--border-radius);
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/*
================================================================================
| 2. LAYOUT & CORE CONTAINERS                                                  |
================================================================================
*/

#app-container,
#game-ui-container,
.game-container,
#phaser-game,
canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#game-ui-container {
  position: relative;
}

.ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ui-overlay>* {
  pointer-events: auto;
}

#orientation-warning {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 15, 35, 0.98);
  color: var(--text-primary);
  display: none;
  /* Hidden by default */
  justify-content: center;
  align-items: center;
  z-index: 99999;
  text-align: center;
}

@media (orientation: portrait) and (max-height: 500px) {
  #orientation-warning {
    display: flex;
  }
}

.orientation-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px;
}

.orientation-content svg {
  animation: rotate-animation 2s ease-in-out infinite;
}

/*
================================================================================
| 3. GLOBAL UI COMPONENTS                                                      |
================================================================================
*/

.ui-btn {
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-speed);
  backdrop-filter: blur(10px);
}

.ui-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.2);
}

.menu-btn {
  background: linear-gradient(135deg, rgba(32, 178, 170, 0.35), rgba(0, 128, 128, 0.25));
  border: 2px solid rgba(64, 224, 208, 0.4);
  border-radius: var(--border-radius);
  padding: 18px 35px;
  font-family: var(--font-primary);
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.08em;
  min-height: 60px;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(15px);
  box-shadow: 0 4px 20px rgba(32, 178, 170, 0.25);
  text-transform: uppercase;
}

.menu-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(64, 224, 208, 0.5), transparent);
  transition: left 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-btn:hover::before {
  left: 100%;
}

.menu-btn:hover {
  background: linear-gradient(135deg, rgba(32, 178, 170, 0.55), rgba(0, 128, 128, 0.45));
  border-color: rgba(64, 224, 208, 0.7);
  box-shadow: 0 8px 30px rgba(32, 178, 170, 0.45);
  transform: translateY(-3px) scale(1.02);
}

.menu-btn:active {
  transform: translateY(-1px) scale(0.98);
  box-shadow: 0 4px 15px rgba(32, 178, 170, 0.6);
}

.menu-btn.primary {
  background: linear-gradient(135deg, rgba(32, 178, 170, 0.5), rgba(0, 128, 128, 0.4));
  border-color: rgba(64, 224, 208, 0.6);
  box-shadow: 0 6px 25px rgba(32, 178, 170, 0.5);
  font-weight: 700;
}

.menu-btn.primary:hover {
  background: linear-gradient(135deg, rgba(32, 178, 170, 0.7), rgba(0, 128, 128, 0.6));
  border-color: rgba(64, 224, 208, 0.9);
}

/*
================================================================================
| 4. SCREENS & OVERLAYS                                                        |
================================================================================
*/

/* --- Loading Screen --- */
.loading-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-blue) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease-out;
}

.loading-content {
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.loading-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: clamp(3rem, 12vw, 5rem);
  background: linear-gradient(45deg, var(--accent-bright), var(--accent-light));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 40px;
  animation: pulse 2s ease-in-out infinite;
}

.loading-text {
  font-family: var(--font-accent);
  font-weight: 700;
  font-size: clamp(1.5rem, 4vw, 2rem);
  color: var(--accent-bright);
  margin-top: 15px;
  min-height: 25px;
  animation: loadingPulse 2s ease-in-out infinite;
}

/* --- Base Menu Overlay --- */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 35, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 15px;
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.menu-content {
  width: 100%;
  text-align: center;
  animation: slideIn 0.5s ease-out;
  max-height: 95vh;
  overflow-y: auto;
  padding: 20px 10px;
}

/* Custom scrollbar for menus */
.menu-content::-webkit-scrollbar {
  width: 8px;
}

.menu-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.menu-content::-webkit-scrollbar-thumb {
  background: rgba(64, 224, 208, 0.4);
  border-radius: 4px;
}

.menu-content::-webkit-scrollbar-thumb:hover {
  background: rgba(64, 224, 208, 0.6);
}


.game-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: clamp(2.5rem, 10vw, 4rem);
  background: linear-gradient(45deg, var(--accent-bright), var(--accent-light));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 10px;
}

.game-subtitle {
  font-family: var(--font-accent);
  font-weight: 700;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.menu-title {
  font-family: var(--font-title);
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  margin-bottom: 20px;
  color: var(--accent-light);
}

.keyboard-hint {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-bottom: 25px;
  font-style: italic;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-width: 280px;
  margin: 20px auto 0;
}

/* --- Main Menu Specifics --- */
#main-menu .menu-content {
  max-width: 500px;
}

/* --- FIX: Main Menu Title Image is handled by CSS, not inline styles --- */
#title-image {
    width: 60vw;
    max-width: 450px;
    min-width: 280px;
    height: auto;
    object-fit: contain;
    margin-bottom: 20px;
    opacity: 0; /* Base state is invisible */
    transition: opacity 0.5s ease-in-out;
}

#title-image.visible {
    opacity: 1; /* Target state is visible */
}

/* --- Level Complete / Score Summary --- */
.score-summary {
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--border-radius);
  padding: 20px;
  margin: 20px 0;
}

/* --- FIX: Constrain level completion star container width --- */
.essence-crystals-display {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 25px auto;
  /* Use auto margin to center the container block */
  width: fit-content;
  /* Make the container only as wide as its content needs */
  max-width: 100%;
  /* Ensure it doesn't overflow on small screens */
}

.crystal {
  width: clamp(40px, 8vw, 60px);
  height: clamp(40px, 8vw, 60px);
  opacity: 0.3;
  transform: scale(0.9);
  filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.4));
  transition: all 0.4s ease;
}

.crystal.earned {
  opacity: 1;
  transform: scale(1);
  animation: starPop 0.6s ease-out;
  filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.8));
}

@keyframes starPop {
  0% {
    transform: scale(0.6);
  }

  60% {
    transform: scale(1.2);
  }

  100% {
    transform: scale(1);
  }
}

/* --- Level Select Menu --- */
#level-select-menu .menu-content {
  background: rgba(12, 24, 33, 0.7);
  border-radius: var(--border-radius-large);
  padding: clamp(15px, 3vw, 30px);
  max-width: 950px;
  width: 95%;
  max-height: 90vh;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(15px);
}

.level-select-content {
  display: flex;
  gap: clamp(15px, 3vw, 30px);
  margin-top: 20px;
  text-align: left;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 15px;
  flex: 3;
  /* Takes up more space */
  align-content: start;
}

.level-item {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--border-radius);
  padding: 20px 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  aspect-ratio: 1 / 1;
}

.level-item:hover:not(.locked) {
  transform: translateY(-5px);
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent-light);
  box-shadow: 0 10px 30px rgba(64, 224, 208, 0.2);
}

.level-item.selected {
  background: linear-gradient(135deg, rgba(64, 224, 208, 0.2), rgba(64, 224, 208, 0.1));
  border-color: var(--accent-vibrant);
  box-shadow: 0 0 20px rgba(64, 224, 208, 0.4);
  transform: translateY(-2px) scale(1.02);
}

.level-item.locked {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(80%);
}

.level-item.locked::after {
  content: '🔒';
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.2rem;
  text-shadow: 0 0 5px black;
}

.level-number {
  font-family: var(--font-title);
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 700;
  color: var(--accent-light);
  text-shadow: 0 2px 10px rgba(64, 224, 208, 0.5);
}

.level-name {
  font-family: var(--font-primary);
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  min-height: 2.6em;
  /* Ensures consistent alignment */
  margin: 5px 0;
}

.level-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.crystal-icon {
  display: inline-block;
  width: clamp(20px, 3vw, 24px);
  height: clamp(20px, 3vw, 24px);
  opacity: 0.3;
  transition: all 0.3s ease;
}

.crystal-icon svg {
  width: 100%;
  height: 100%;
  fill: #333;
  stroke: #555;
  stroke-width: 1;
}

.crystal-icon.earned {
  opacity: 1;
  filter: drop-shadow(0 0 5px var(--gold));
}

.crystal-icon.earned svg {
  fill: var(--gold);
  stroke: #ffed4e;
  animation: sparkle 2s ease-in-out infinite;
}

.level-info-panel {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--border-radius);
  padding: clamp(15px, 3vw, 25px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  flex: 2;
  /* Takes up less space than the grid */
  display: flex;
  flex-direction: column;
}

.level-info-placeholder {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: var(--text-secondary);
  font-style: italic;
  font-size: 1.1rem;
  text-align: center;
}

#preview-level-name {
  font-family: var(--font-title);
  color: var(--accent-light);
  margin-bottom: 10px;
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  line-height: 1.2;
}

#preview-level-description {
  color: var(--text-secondary);
  margin-bottom: 25px;
  line-height: 1.6;
  font-size: clamp(0.85rem, 2vw, 1rem);
  flex-grow: 1;
  /* Pushes stats to the bottom */
}

.stats-display {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 15px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 15px;
}

.stats-display .stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: clamp(0.9rem, 2.2vw, 1rem);
}

.stats-display .stat-label {
  color: var(--text-secondary);
}

.stats-display .stat-value {
  color: var(--text-primary);
  font-weight: 700;
}

#preview-stars .stars-display {
  justify-content: flex-end;
  /* Align stars with stat values */
}

#preview-stars .crystal-icon {
  width: 28px;
  height: 28px;
}

#level-select-menu .menu-buttons {
  flex-direction: row;
  justify-content: flex-end;
  max-width: none;
  /* Override default */
  width: 100%;
  gap: 20px;
  margin-top: 25px;
}

#play-selected-level-btn {
  flex-grow: 1;
  /* Take available space */
  max-width: 300px;
}

#play-selected-level-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #444;
  border-color: #555;
  box-shadow: none;
  transform: none;
}

#play-selected-level-btn:disabled::before {
  display: none;
}

/*
================================================================================
| 5. IN-GAME HUD                                                               |
================================================================================
*/

.mobile-controls {
  position: absolute;
  inset: 0 0 auto 0;
  padding: env(safe-area-inset-top, 8px) 8px 8px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), transparent);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  /* Critical: Allows clicks to pass through to the game canvas */
}

.pause-btn,
.game-stats {
  pointer-events: auto;
  /* Re-enable pointer events for actual UI elements */
}

.game-stats {
  display: flex;
  gap: 12px;
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 12px;
  border-radius: var(--border-radius);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.stat-value {
  font-family: var(--font-primary);
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent-light);
  line-height: 1.2;
}

.stat-value.warning {
  color: var(--warning-red) !important;
  text-shadow: 0 0 6px rgba(255, 68, 68, 0.6);
  animation: pulse-warning 1.5s infinite;
}

/*
================================================================================
| 6. ANIMATIONS & KEYFRAMES                                                    |
================================================================================
*/

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    text-shadow: 0 0 15px var(--accent-light);
  }

  50% {
    opacity: 0.8;
    text-shadow: 0 0 8px var(--accent-light);
  }
}

@keyframes loadingPulse {

  0%,
  100% {
    opacity: 0.7;
  }

  50% {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sparkle {

  0%,
  100% {
    transform: scale(1) rotate(0deg);
  }

  50% {
    transform: scale(1.1) rotate(5deg);
  }
}

@keyframes pulse-warning {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }
}

@keyframes rotate-animation {
  0% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(90deg);
  }

  100% {
    transform: rotate(90deg);
  }
}

/*
================================================================================
| 7. RESPONSIVE DESIGN (MEDIA QUERIES)                                         |
================================================================================
*/

/* --- Small Phones in Landscape (Most constrained view) --- */
@media (orientation: landscape) and (max-height: 500px) {
  .game-title {
    font-size: 2rem;
    margin-bottom: 5px;
  }

  .game-subtitle {
    font-size: 1.2rem;
    margin-bottom: 15px;
  }

  .menu-title {
    font-size: 1.5rem;
    margin-bottom: 15px;
  }

  .menu-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 100%;
  }

  .menu-btn {
    padding: 8px 16px;
    font-size: 0.8rem;
    min-height: 40px;
  }

  .keyboard-hint {
    display: none;
  }
}

/* --- Tablets and Vertical Layouts (900px and below) --- */
@media (max-width: 900px) {
  #level-select-menu .menu-content {
    padding: 20px;
    max-width: 95%;
  }

  .level-select-content {
    flex-direction: column;
    /* THE KEY CHANGE for mobile */
  }

  .level-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .level-info-panel {
    min-height: auto;
    /* Allow panel to shrink */
  }

  #preview-level-description {
    min-height: 80px;
    /* Give some space on stacked view */
  }

  #level-select-menu .menu-buttons {
    flex-direction: column-reverse;
    /* Puts "Back" below "Play" */
    align-items: center;
  }

  #play-selected-level-btn,
  #level-select-back-btn {
    width: 100%;
    max-width: 350px;
  }
}

/* --- Mobile Phones (480px and below) --- */
@media (max-width: 480px) {
  .level-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 10px;
  }

  .level-item {
    padding: 10px;
    border-width: 1px;
  }

  .level-number {
    font-size: 1.8rem;
  }

  .level-name {
    font-size: 0.75rem;
    min-height: 2.4em;
  }
}