/* =========================================================
   PULO DO GATO REX82 - ESTILOS
   ========================================================= */

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ---------------------------------------------------------
   TEMAS (variáveis de cor) - Noite / Dia
   --------------------------------------------------------- */
body.theme-night {
  --sky-top: #0b0f2e;
  --sky-bottom: #2a1f5c;
  --building-far: #1a1f45;
  --building-near: #12142f;
  --building-window: #ffd76b;
  --text-primary: #f5f3ff;
  --text-secondary: #b9b3e0;
  --accent: #ff7ab8;
  --accent-2: #7ad7ff;
  --panel-bg: rgba(20, 16, 48, 0.75);
  --panel-border: rgba(255, 255, 255, 0.12);
  --star-opacity: 1;
  --sun-moon-color: #f2f0e2;
  --sun-moon-glow: rgba(242, 240, 226, 0.4);
}

body.theme-day {
  --sky-top: #6ec6ff;
  --sky-bottom: #cdeeff;
  --building-far: #a7c4dd;
  --building-near: #6f89a8;
  --building-window: #fff3b0;
  --text-primary: #1b2340;
  --text-secondary: #3d4a6b;
  --accent: #ff5f7e;
  --accent-2: #1e88b5;
  --panel-bg: rgba(255, 255, 255, 0.8);
  --panel-border: rgba(20, 30, 60, 0.12);
  --star-opacity: 0;
  --sun-moon-color: #ffd23f;
  --sun-moon-glow: rgba(255, 210, 63, 0.55);
}

body {
  background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
  color: var(--text-primary);
  transition: background 0.6s ease;
  width: 100%;
  height: 100%;
  position: relative;
}

/* ---------------------------------------------------------
   TELAS (start / game / result)
   --------------------------------------------------------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.screen--active {
  display: flex;
}

/* ---------------------------------------------------------
   SKYLINE decorativo (fundo de prédios)
   --------------------------------------------------------- */
.skyline {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 45%;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to top, var(--building-near) 0 55%, transparent 55%),
    linear-gradient(to top, var(--building-far) 0 40%, transparent 40%);
  background-size: 100px 100%, 140px 100%;
  background-position: 0 bottom, 40px bottom;
  background-repeat: repeat-x;
  opacity: 0.9;
}

.skyline::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, var(--building-window) 1.5px, transparent 1.5px);
  background-size: 20px 26px;
  opacity: 0.35;
  mix-blend-mode: screen;
}

.stars {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: var(--star-opacity);
  transition: opacity 0.6s ease;
  background-image:
    radial-gradient(2px 2px at 20% 30%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 60% 20%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 80% 45%, #fff, transparent),
    radial-gradient(2px 2px at 35% 65%, #fff, transparent),
    radial-gradient(1px 1px at 90% 15%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 10% 80%, #fff, transparent);
  animation: twinkle 3s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: calc(var(--star-opacity) * 0.5); }
  to { opacity: var(--star-opacity); }
}

.moon-sun {
  position: absolute;
  top: 10%;
  right: 12%;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: var(--sun-moon-color);
  box-shadow: 0 0 50px 20px var(--sun-moon-glow);
  z-index: 0;
  transition: background 0.6s ease, box-shadow 0.6s ease;
  animation: float-glow 5s ease-in-out infinite;
}

@keyframes float-glow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ---------------------------------------------------------
   TELA INICIAL
   --------------------------------------------------------- */
.start-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px;
  max-width: 480px;
  width: 100%;
  animation: content-rise 0.9s cubic-bezier(.2,.8,.2,1) both;
}

@keyframes content-rise {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Gato animado na tela inicial */
.cat-hero {
  position: relative;
  width: 90px;
  height: 100px;
  margin-bottom: 10px;
  animation: cat-bounce 1.4s ease-in-out infinite;
}

@keyframes cat-bounce {
  0%, 100% { transform: translateY(0) scaleY(1); }
  45% { transform: translateY(-22px) scaleY(1.03); }
  55% { transform: translateY(-22px) scaleY(1.03); }
  75% { transform: translateY(0) scaleY(0.92); }
}

.cat-hero__body {
  position: relative;
  width: 64px;
  height: 56px;
  background: #1c1c22;
  border-radius: 45% 45% 50% 50% / 55% 55% 45% 45%;
  margin: 20px auto 0;
  box-shadow: inset -6px -4px 0 rgba(0,0,0,0.35);
}

.cat-hero__ear {
  position: absolute;
  top: -14px;
  width: 0; height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 20px solid #1c1c22;
}
.cat-hero__ear--left { left: 4px; transform: rotate(-12deg); }
.cat-hero__ear--right { right: 4px; transform: rotate(12deg); }

.cat-hero__face { position: absolute; top: 16px; width: 100%; }
.cat-hero__eye {
  position: absolute;
  top: 0;
  width: 8px; height: 10px;
  background: #ffd76b;
  border-radius: 50%;
}
.cat-hero__eye--left { left: 14px; }
.cat-hero__eye--right { right: 14px; }
.cat-hero__nose {
  position: absolute;
  top: 14px; left: 50%;
  width: 6px; height: 5px;
  background: #ff8fb1;
  border-radius: 50%;
  transform: translateX(-50%);
}

.cat-hero__tail {
  position: absolute;
  bottom: 4px;
  right: -14px;
  width: 34px;
  height: 10px;
  background: #1c1c22;
  border-radius: 10px;
  transform-origin: left center;
  animation: tail-wag 1.4s ease-in-out infinite;
}

@keyframes tail-wag {
  0%, 100% { transform: rotate(10deg); }
  50% { transform: rotate(-15deg); }
}

.cat-hero__shadow {
  width: 60px;
  height: 12px;
  background: rgba(0,0,0,0.35);
  border-radius: 50%;
  margin: 6px auto 0;
  animation: shadow-pulse 1.4s ease-in-out infinite;
  filter: blur(2px);
}

@keyframes shadow-pulse {
  0%, 100% { transform: scale(1); opacity: 0.35; }
  50% { transform: scale(0.6); opacity: 0.15; }
}

.game-title {
  line-height: 1.05;
  margin-bottom: 6px;
  text-shadow: 0 4px 18px rgba(0,0,0,0.4);
}
.game-title__line1 {
  display: block;
  font-size: clamp(28px, 7vw, 40px);
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-primary);
}
.game-title__line2 {
  display: block;
  font-size: clamp(38px, 10vw, 58px);
  font-weight: 900;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.game-title__line2 em { font-style: normal; }

.game-subtitle {
  color: var(--text-secondary);
  font-size: clamp(14px, 3.6vw, 17px);
  margin-bottom: 22px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 280px;
  margin-bottom: 20px;
}

.menu-toggle-row {
  display: flex;
  gap: 10px;
}
.menu-toggle-row .btn { flex: 1; font-size: 13px; padding: 10px 8px; }

.instructions {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  backdrop-filter: blur(6px);
}
.instructions strong { color: var(--text-primary); }
.instructions kbd {
  background: rgba(255,255,255,0.15);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
}
.instructions__mobile { display: none; }

.best-score {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---------------------------------------------------------
   TELA DE SELEÇÃO DE FASES
   --------------------------------------------------------- */
.levels-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px;
  max-width: 520px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  animation: content-rise 0.6s cubic-bezier(.2,.8,.2,1) both;
}

.levels-title {
  font-size: clamp(24px, 6vw, 32px);
  font-weight: 900;
  margin-top: 12px;
  color: var(--text-primary);
}
.levels-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 18px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  margin-bottom: 20px;
}
@media (min-width: 480px) {
  .level-grid { grid-template-columns: repeat(3, 1fr); }
}

.level-card {
  position: relative;
  border: none;
  border-radius: 16px;
  padding: 14px 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #fff;
  font-family: inherit;
  overflow: hidden;
  transition: transform 0.12s ease;
  box-shadow: 0 8px 18px rgba(0,0,0,0.28);
}
.level-card:active { transform: scale(0.94); }

.level-card__number {
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}
.level-card__name {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.95;
  line-height: 1.2;
  min-height: 26px;
}
.level-card__tier {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 800;
  background: rgba(0,0,0,0.25);
  padding: 1px 8px;
  border-radius: 8px;
}
.level-card__best {
  font-size: 10px;
  opacity: 0.85;
  margin-top: 2px;
}

.level-card--locked {
  cursor: not-allowed;
  filter: grayscale(0.85);
  opacity: 0.55;
}
.level-card__lock {
  font-size: 20px;
}

.level-card--complete::after {
  content: "✅";
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 14px;
}

.level-card.shake {
  animation: level-shake 0.35s ease;
}
@keyframes level-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Etiqueta com o nome da fase, exibida durante o jogo */
.level-name-tag {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  padding: 3px 12px;
  border-radius: 20px;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

/* ---------------------------------------------------------
   BOTÕES
   --------------------------------------------------------- */
.btn {
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  padding: 14px 22px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.94); }

.btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
}
.btn--primary:hover { filter: brightness(1.08); }

.btn--ghost {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  backdrop-filter: blur(6px);
}

.btn__icon { font-size: 15px; }

.btn-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}
.btn-icon:active { transform: scale(0.9); }

/* ---------------------------------------------------------
   TELA DE JOGO
   --------------------------------------------------------- */
#screen-game { background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom)); justify-content: flex-start; }

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Flash sutil de tela ao avançar de fase */
.phase-flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(circle at 50% 30%, var(--accent-2) 0%, transparent 70%);
  opacity: 0;
}
.phase-flash.flash {
  animation: phase-flash-anim 0.6s ease-out;
}
@keyframes phase-flash-anim {
  0% { opacity: 0.55; }
  100% { opacity: 0; }
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px 0;
}

.hud__item {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 6px 14px;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  min-width: 68px;
}
.hud__label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); }
.hud__value { font-size: 16px; font-weight: 800; color: var(--text-primary); }

.hud .btn-icon { margin-left: auto; }

/* Badge de dificuldade dentro do HUD de fase */
.hud__item--phase { position: relative; }
.hud__tier {
  display: inline-block;
  margin-top: 2px;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 1px 6px;
  border-radius: 6px;
  width: fit-content;
  transition: background 0.3s ease, color 0.3s ease;
}
.hud__tier--facil { background: rgba(74, 222, 128, 0.25); color: #4ade80; }
.hud__tier--medio { background: rgba(251, 146, 60, 0.25); color: #fb923c; }
.hud__tier--dificil { background: rgba(239, 68, 68, 0.25); color: #ef4444; }

/* Banner de transição de fase */
.phase-banner {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 7;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  padding: 10px 22px;
  border-radius: 30px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.phase-banner.show {
  animation: phase-banner-anim 2.1s cubic-bezier(.2,.8,.2,1) forwards;
}
@keyframes phase-banner-anim {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-20px) scale(0.85); }
  12%  { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.05); }
  20%  { transform: translateX(-50%) translateY(0) scale(1); }
  82%  { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(0.95); }
}

.combo-popup {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  font-size: 20px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
}
.combo-popup.show {
  animation: combo-pop 0.9s ease forwards;
}
@keyframes combo-pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  25% { opacity: 1; transform: translate(-50%, -10px) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, -20px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(0.9); }
}

/* Torre de progresso lateral */
.progress-tower {
  position: absolute;
  right: 10px;
  top: 80px;
  bottom: 140px;
  width: 24px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.progress-tower__track {
  position: relative;
  width: 6px;
  flex: 1;
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
  overflow: hidden;
}
.progress-tower__fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: linear-gradient(to top, var(--accent), var(--accent-2));
  border-radius: 4px;
  transition: height 0.25s ease;
}
.progress-tower__cat {
  position: absolute;
  font-size: 16px;
  transform: translateY(50%);
  transition: bottom 0.25s ease;
  bottom: 0%;
}
.progress-tower__flag {
  font-size: 16px;
  margin-top: -4px;
}

/* Controles mobile */
.mobile-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  padding: 0 20px max(20px, env(safe-area-inset-bottom));
  pointer-events: none;
}

.ctrl-btn {
  pointer-events: auto;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  color: var(--text-primary);
  font-size: 26px;
  font-weight: 900;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  transition: transform 0.08s ease, background 0.08s ease;
}
.ctrl-btn:active,
.ctrl-btn.is-active {
  transform: scale(0.88);
  background: var(--accent);
  color: #fff;
}

/* Menu de pausa */
.overlay-menu {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(5, 5, 20, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.overlay-menu.hidden { display: none; }
.overlay-menu__box {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 240px;
  text-align: center;
  animation: content-rise 0.35s ease both;
}
.overlay-menu__box h2 { margin-bottom: 6px; }

/* ---------------------------------------------------------
   TELA DE RESULTADO
   --------------------------------------------------------- */
.result-content {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  animation: content-rise 0.6s cubic-bezier(.2,.8,.2,1) both;
}

.result-title {
  font-size: clamp(30px, 8vw, 44px);
  font-weight: 900;
  margin-bottom: 6px;
}
.result-title.win { background: linear-gradient(90deg, #ffd76b, #ff9a6b); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-title.lose { color: var(--accent); }

.result-emoji {
  font-size: 54px;
  margin-bottom: 16px;
  animation: emoji-pop 0.6s cubic-bezier(.2,1.4,.4,1) both;
}
@keyframes emoji-pop {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.result-stats {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 22px;
  backdrop-filter: blur(6px);
}
.result-stats__row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--panel-border);
}
.result-stats__row:last-child { border-bottom: none; }
.result-stats__row strong { color: var(--text-primary); font-size: 16px; }
.result-stats__row--best strong { color: var(--accent); }

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------------------------------------------------------
   RESPONSIVIDADE
   --------------------------------------------------------- */
@media (hover: none) and (pointer: coarse) {
  .instructions__desktop { display: none; }
  .instructions__mobile { display: block; }
}

@media (min-width: 900px) {
  .mobile-controls { display: none; }
}

@media (max-width: 380px) {
  .ctrl-btn { width: 60px; height: 60px; font-size: 22px; }
  .hud__item { padding: 5px 10px; min-width: 56px; }
  .hud__value { font-size: 14px; }
}

@media (max-height: 600px) {
  .cat-hero { transform: scale(0.75); margin-bottom: -8px; }
  .instructions { padding: 10px 14px; font-size: 12px; }
}

.hidden { display: none !important; }