/* ============================================================================
   Salad Ninja — styles
   Colorful, fresh and responsive UI layered on top of the Three.js canvas.
   ========================================================================== */

:root {
  --green: #43a047;
  --green-dark: #2e7d32;
  --orange: #fb8c00;
  --red: #e53935;
  --gold: #ffd54f;
  --cream: #fdf6e3;
  --ink: #2b2b2b;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-dark: rgba(30, 30, 46, 0.9);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  --radius: 18px;
  --focus: #ffb300;
}

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

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #1a1a2e;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#game-container {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#game-canvas {
  position: absolute;
  inset: 0;
}

#game-canvas canvas {
  display: block;
}

#ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* Only interactive overlays capture pointer events (menus, buttons). The
   decorative overlays (flashes, toasts, combo popup) stay click-through. */
.screen,
.sound-toggle,
.hud-left {
  pointer-events: auto;
}

/* --- screens -------------------------------------------------------------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 1.5rem;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.screen.active {
  opacity: 1;
  visibility: visible;
}

/* --- logo / titles -------------------------------------------------------- */

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.9;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.15));
}

.logo-salad {
  font-size: clamp(2.8rem, 10vw, 6rem);
  font-weight: 900;
  color: var(--green-dark);
  letter-spacing: 0.02em;
  text-shadow: 2px 2px 0 var(--gold), 4px 4px 0 rgba(0, 0, 0, 0.18);
}

.logo-ninja {
  font-size: clamp(3.2rem, 12vw, 7rem);
  font-weight: 900;
  color: var(--orange);
  letter-spacing: 0.04em;
  text-shadow: 2px 2px 0 #fff, 5px 5px 0 rgba(0, 0, 0, 0.18);
}

.screen-title {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 800;
  color: var(--ink);
}

.tagline {
  font-size: clamp(1rem, 3vw, 1.35rem);
  color: var(--green-dark);
  font-weight: 600;
}

.hint {
  font-size: 0.85rem;
  opacity: 0.7;
}

/* --- buttons -------------------------------------------------------------- */

.btn {
  font: inherit;
  font-weight: 700;
  font-size: clamp(1rem, 3vw, 1.25rem);
  padding: 0.85rem 2.2rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
  min-width: 12rem;
}

.btn:active {
  transform: translateY(2px) scale(0.98);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #66bb6a, var(--green-dark));
}

.btn-secondary {
  background: linear-gradient(180deg, #ffa726, var(--orange));
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 2px solid rgba(0, 0, 0, 0.25);
  box-shadow: none;
}

.btn.hidden {
  display: none;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: center;
}

.pill-btn {
  font: inherit;
  font-weight: 700;
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sound-toggle {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 20;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.5rem 0.9rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* --- focus visibility (accessibility) ------------------------------------- */

.btn:focus-visible,
.pill-btn:focus-visible,
.sound-toggle:focus-visible,
.level-card:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* --- HUD ------------------------------------------------------------------ */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: none;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.75rem 0.9rem;
  pointer-events: none;
}

.hud.active {
  display: flex;
}

.hud-left,
.hud-right,
.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.hud-left {
  align-items: flex-start;
  pointer-events: auto;
}

.hud-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 0.75rem;
}

.hud-score {
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}

.hud-combo {
  font-size: 1rem;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  min-height: 1.2em;
}

.hud-timer {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
}

.hud-lives {
  display: flex;
  gap: 0.15rem;
  font-size: 1.5rem;
  line-height: 1;
}

.heart {
  color: #ff4d4d;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.heart.lost {
  color: rgba(255, 255, 255, 0.35);
  transform: scale(0.85);
}

/* --- level select --------------------------------------------------------- */

.levels-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 260px));
  gap: 1rem;
  width: 100%;
  max-width: 620px;
  justify-content: center;
}

.level-card {
  font: inherit;
  text-align: center;
  padding: 1rem 0.9rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
  color: var(--ink);
  transition: transform 0.1s ease;
}

.level-card:not(:disabled):hover {
  transform: translateY(-3px);
}

.level-card.locked {
  opacity: 0.6;
  filter: grayscale(0.7);
  cursor: not-allowed;
}

.level-card h3 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--green-dark);
}

.level-tag {
  font-size: 0.78rem;
  opacity: 0.75;
  min-height: 1.1em;
}

.level-score {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--orange);
}

.stars {
  display: flex;
  gap: 0.1rem;
}

.star {
  color: #d7ccc8;
  font-size: 1.4rem;
  line-height: 1;
}

.star.filled {
  color: var(--gold);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.levels-actions {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  justify-content: center;
}

.levels-actions .btn {
  min-width: 0;
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
}

/* --- results -------------------------------------------------------------- */

.result-stars {
  display: flex;
  gap: 0.4rem;
  font-size: 3rem;
  line-height: 1;
}

.star.big {
  color: #d7ccc8;
  opacity: 0.3;
  transform: scale(0.5);
}

.star.big.earned {
  color: var(--gold);
  opacity: 1;
  animation: star-pop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) both;
}

@keyframes star-pop {
  0% {
    transform: scale(0);
  }
  70% {
    transform: scale(1.4);
  }
  100% {
    transform: scale(1);
  }
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, 1fr));
  gap: 0.7rem;
  width: 100%;
  max-width: 420px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--panel);
  border-radius: 14px;
  padding: 0.5rem;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14);
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--green-dark);
}

.newbest {
  font-weight: 800;
  color: var(--orange);
  visibility: hidden;
}

.newbest.visible {
  visibility: visible;
  animation: pop 0.5s ease;
}

.results-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  justify-content: center;
}

.results-actions .btn {
  min-width: 0;
  padding: 0.7rem 1.4rem;
  font-size: 1rem;
}

/* --- game over ------------------------------------------------------------ */

.gameover-title {
  font-size: clamp(2.6rem, 10vw, 5rem);
  font-weight: 900;
  color: var(--red);
  letter-spacing: 0.06em;
  text-shadow: 3px 3px 0 var(--gold), 6px 6px 0 rgba(0, 0, 0, 0.2);
}

.gameover-sub {
  font-size: clamp(1rem, 3.5vw, 1.4rem);
  font-weight: 700;
  color: var(--green-dark);
}

.gameover-stats {
  display: flex;
  gap: 0.7rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* --- combo popup ---------------------------------------------------------- */

.combo-popup {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.6);
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
}

.combo-popup.pop {
  animation: combo-pop 0.7s ease forwards;
}

@keyframes combo-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  25% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%) scale(1.1);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.5);
  }
  100% {
    transform: scale(1);
  }
}

/* --- toast ---------------------------------------------------------------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  background: var(--panel-dark);
  color: #fff;
  padding: 0.7rem 1.3rem;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.toast.show {
  opacity: 1;
}

/* --- flash overlays ------------------------------------------------------- */

.flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.flash.show {
  animation: flash 0.5s ease-out;
}

.bomb-flash {
  background: radial-gradient(circle, rgba(255, 120, 60, 0.55), rgba(160, 20, 20, 0.75));
}

.miss-flash {
  background: radial-gradient(circle, rgba(255, 60, 60, 0), rgba(200, 30, 30, 0.35));
}

@keyframes flash {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* --- fatal error ---------------------------------------------------------- */

.fatal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  background: #1a1a2e;
  z-index: 100;
}

.fatal:not([hidden]) {
  display: flex;
}

/* --- responsive ----------------------------------------------------------- */

@media (max-width: 560px) {
  .levels-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
    gap: 0.7rem;
  }

  .level-card {
    padding: 0.7rem 0.6rem;
  }

  .result-grid {
    grid-template-columns: repeat(2, minmax(80px, 1fr));
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  .screen {
    gap: 0.5rem;
    padding: 0.6rem;
  }

  .logo-salad {
    font-size: clamp(1.8rem, 7vw, 3rem);
  }

  .logo-ninja {
    font-size: clamp(2rem, 8vw, 3.6rem);
  }

  .btn {
    padding: 0.55rem 1.6rem;
    font-size: 1rem;
  }

  .levels-grid {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 0.6rem;
  }
}
