@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap');

:root {
  --primary-color: #ff7f41; /* Rich Apricot Orange */
  --primary-hover: #ff6015;
  --secondary-color: #ffb7b2; /* Pig Pink */
  --bg-gradient: linear-gradient(135deg, #ff9e7d 0%, #ffd3b6 100%);
  --accent-color: #4caf50; /* Fresh Leaf Green */
  --hazard-color: #8d4b38; /* Rotten Apricot Brown */
  --text-dark: #3a221d;
  --text-light: #ffffff;
  --shadow: 0 8px 32px rgba(139, 69, 19, 0.2);
  --glass-bg: rgba(255, 245, 235, 0.7);
  --glass-border: 2px solid rgba(255, 255, 255, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Fredoka', sans-serif;
  background: var(--bg-gradient);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Container keeping aspect ratio (16:9) */
#game-wrapper {
  position: relative;
  width: 100%;
  max-width: 1280px;
  aspect-ratio: 16 / 9;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  border: 4px solid #ffffff;
  background-color: #333;
}

/* The Canvas itself */
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background-color: #87CEEB; /* Sky fallback */
}

/* UI Overlays */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(58, 34, 29, 0.4);
  backdrop-filter: blur(8px);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

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

/* Content panels */
.panel {
  background: var(--glass-bg);
  border: var(--glass-border);
  box-shadow: var(--shadow);
  border-radius: 24px;
  padding: 30px 40px;
  width: 90%;
  max-width: 500px;
  text-align: center;
  transform: scale(0.85);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.overlay.active .panel {
  transform: scale(1);
}

/* Custom panels (wide for level selector) */
.panel-wide {
  max-width: 800px;
  max-height: 90%;
  overflow-y: auto;
}

/* Scrollbar styling */
.panel-wide::-webkit-scrollbar {
  width: 8px;
}
.panel-wide::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.05);
  border-radius: 4px;
}
.panel-wide::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 4px;
}

/* Typography styling */
h1 {
  font-size: 3rem;
  margin-bottom: 15px;
  color: var(--primary-color);
  text-shadow: 2px 2px 0px #ffffff, 4px 4px 0px rgba(0,0,0,0.1);
  letter-spacing: 1px;
}

h2 {
  font-size: 2.2rem;
  margin-bottom: 20px;
  color: var(--primary-color);
  text-shadow: 1px 1px 0px #ffffff;
}

p {
  font-size: 1.1rem;
  line-height: 1.5;
  margin-bottom: 25px;
  color: var(--text-dark);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 12px 32px;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  text-transform: uppercase;
  color: var(--text-light);
  background: var(--primary-color);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 0px #c2531a, 0 12px 20px rgba(194, 83, 26, 0.4);
  transform: translateY(0);
  transition: all 0.15s ease;
  margin: 10px;
  outline: none;
}

.btn:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 0px #c2531a, 0 14px 22px rgba(194, 83, 26, 0.4);
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0px #c2531a, 0 4px 10px rgba(194, 83, 26, 0.6);
}

.btn-secondary {
  background: #a1887f;
  box-shadow: 0 6px 0px #705b53, 0 12px 20px rgba(112, 91, 83, 0.4);
}
.btn-secondary:hover {
  background: #8d6e63;
  box-shadow: 0 8px 0px #705b53, 0 14px 22px rgba(112, 91, 83, 0.4);
}
.btn-secondary:active {
  box-shadow: 0 2px 0px #705b53, 0 4px 10px rgba(112, 91, 83, 0.6);
}

/* Level Grid */
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  margin: 25px 0;
}

@media (max-width: 600px) {
  .level-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.level-card {
  aspect-ratio: 1;
  background-size: cover;
  background-position: center;
  border: 3px solid #ffd3b6;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

.level-card:hover:not(.locked) {
  transform: translateY(-5px) scale(1.05);
  border-color: var(--primary-color);
  box-shadow: 0 8px 16px rgba(255, 127, 65, 0.2);
}

.level-card:active:not(.locked) {
  transform: translateY(1px);
}

/* Semitransparent white wash overlay to ensure text readability */
.level-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.48);
  z-index: 1;
  transition: background 0.2s;
}

.level-card:hover:not(.locked)::before {
  background: rgba(255, 255, 255, 0.3);
}

.level-card.locked::before {
  background: rgba(224, 224, 224, 0.85);
  content: "🔒";
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.8rem;
  z-index: 3;
}

.level-card .num,
.level-card .title,
.level-card .stars {
  position: relative;
  z-index: 2;
  text-shadow: 0 1px 3px rgba(255, 255, 255, 0.9), 0 0 8px rgba(255, 255, 255, 1);
}

.level-card .num {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 2px;
}

.level-card .title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dark);
  text-align: center;
  margin: 2px 10px 6px 10px;
  line-height: 1.15;
  max-width: 90%;
  word-wrap: break-word;
}

.level-card .stars {
  margin-top: 2px;
  display: flex;
  gap: 2px;
}

.level-card .stars span {
  font-size: 0.8rem;
  color: #ccc;
}

.level-card .stars span.active {
  color: #ffb703;
}

.level-card.locked {
  cursor: not-allowed;
  border-color: #bdbdbd;
}

.level-card.locked .num,
.level-card.locked .title,
.level-card.locked .stars {
  display: none;
}

/* HUD / Game UI (Always visible during gameplay) */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 15px 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 5;
}

#hud-left, #hud-right, #hud-center {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.85);
  border: 1.5px solid rgba(255,255,255,0.7);
  border-radius: 12px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  backdrop-filter: blur(4px);
}

.hud-item {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-dark);
}

.hud-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}

.hud-btn:hover {
  transform: scale(1.15);
}

.hud-btn:active {
  transform: scale(0.9);
}

/* Stars styling on Win Panel */
.win-stars {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin: 20px 0;
}

.win-stars span {
  font-size: 3rem;
  color: #ccc;
  transform: scale(0.8);
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.5), color 0.3s;
}

.win-stars span.active {
  color: #ffb703;
  transform: scale(1.2);
  text-shadow: 0 0 10px rgba(255, 183, 3, 0.5);
}

/* Mute state toggle styling */
.muted-icon::after {
  content: "🔊";
}
.muted .muted-icon::after {
  content: "🔇";
}

/* Tutorial banner */
#tutorial-banner {
  position: absolute;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  pointer-events: none;
  z-index: 4;
  animation: float 2s ease-in-out infinite;
}

@keyframes float {
  0% { transform: translate(-50%, 0px); }
  50% { transform: translate(-50%, -6px); }
  100% { transform: translate(-50%, 0px); }
}

/* Highscore Table Styles */
.highscore-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 5px;
  font-size: 1.05rem;
}

.highscore-table th, .highscore-table td {
  padding: 6px 12px;
  text-align: left;
}

.highscore-table th {
  border-bottom: 2px solid #ffd3b6;
  color: var(--primary-color);
  font-weight: 700;
}

.highscore-table tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.35);
}

.highscore-table tr.highlight {
  background-color: rgba(255, 183, 178, 0.45);
  font-weight: 700;
}
