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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "Trebuchet MS", "Comic Sans MS", system-ui, sans-serif;
  background: #0a1628;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  z-index: 0;
}

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

.screen {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.screen.active {
  display: flex;
  pointer-events: auto;
  opacity: 1;
}

/* ===== TITLE ===== */
#screen-title {
  align-items: center;
  justify-content: center;
  background: transparent;
}

.title-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.2rem;
  text-align: center;
  padding: 1.5rem;
  animation: fadeUp 0.7s ease both;
}

.logo {
  display: flex;
  flex-direction: column;
  line-height: 0.95;
  filter: drop-shadow(0 8px 0 #5a1a6e) drop-shadow(0 14px 24px rgba(0, 0, 0, 0.45));
}

.logo-angry {
  font-size: clamp(2.8rem, 10vw, 5.5rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #ff6b2c;
  text-shadow:
    0 3px 0 #c43a00,
    0 6px 0 #8a2800,
    0 0 30px rgba(255, 120, 40, 0.5);
  transform: rotate(-3deg);
}

.logo-pigs {
  font-size: clamp(3.4rem, 12vw, 6.5rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #ff8fab;
  text-shadow:
    0 3px 0 #e0568a,
    0 6px 0 #b03a68,
    0 0 30px rgba(255, 140, 180, 0.45);
  transform: rotate(2deg);
  position: relative;
}

.logo-pig-face {
  display: inline-block;
  width: 0.72em;
  height: 0.72em;
  vertical-align: middle;
  margin: 0 0.02em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffc0d4, #ff7aa2 55%, #e85a88);
  box-shadow: inset -4px -6px 0 rgba(0, 0, 0, 0.08), 0 4px 0 #c44a72;
  position: relative;
  top: -0.06em;
}

.logo-pig-face::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 48%;
  width: 42%;
  height: 32%;
  transform: translate(-50%, -40%);
  background: #ff9fbc;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(200, 80, 120, 0.35);
}

.logo-pig-face::after {
  content: "◕‿◕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.28em;
  color: #3a2030;
  font-weight: 900;
  transform: translateY(-8%);
}

/* ===== BUTTONS ===== */
.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: 0.06em;
  border-radius: 18px;
  padding: 0.85rem 1.6rem;
  font-size: 1.05rem;
  color: #fff;
  background: #4a90d9;
  box-shadow: 0 6px 0 #2a5f9a, 0 10px 20px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
  pointer-events: auto;
  min-height: 48px;
  min-width: 48px;
}

.btn:hover {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2a5f9a, 0 4px 10px rgba(0, 0, 0, 0.2);
}

.btn-primary {
  background: linear-gradient(180deg, #ff8a3d, #ff5a1f);
  box-shadow: 0 6px 0 #c43a00, 0 10px 22px rgba(255, 90, 30, 0.35);
}

.btn-primary:active {
  box-shadow: 0 2px 0 #c43a00, 0 4px 10px rgba(255, 90, 30, 0.25);
}

.btn-secondary {
  background: linear-gradient(180deg, #6ec6ff, #3a8fd4);
  box-shadow: 0 6px 0 #1f5f9a, 0 10px 18px rgba(0, 0, 0, 0.22);
}

.btn-secondary:active {
  box-shadow: 0 2px 0 #1f5f9a, 0 4px 8px rgba(0, 0, 0, 0.18);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
}

.btn-xl {
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  padding: 1rem 3.2rem;
  border-radius: 24px;
  min-width: 200px;
}

.btn-small {
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: 14px;
}

.btn-icon {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 14px;
  font-size: 1.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 30, 50, 0.55);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

/* ===== MAP SELECT ===== */
#screen-maps {
  flex-direction: column;
  background: linear-gradient(180deg, rgba(10, 20, 40, 0.55), rgba(10, 20, 40, 0.75));
  padding: clamp(0.75rem, 2vw, 1.5rem);
  overflow-y: auto;
  pointer-events: auto;
}

.maps-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  width: 100%;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.screen-title {
  text-align: center;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.total-stars {
  background: rgba(20, 30, 50, 0.65);
  backdrop-filter: blur(8px);
  padding: 0.5rem 0.9rem;
  border-radius: 14px;
  font-weight: 800;
  font-size: 0.95rem;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding-bottom: 1.5rem;
}

.map-card {
  position: relative;
  border: none;
  border-radius: 20px;
  padding: 1rem;
  text-align: left;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  overflow: hidden;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.25), 0 14px 28px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  pointer-events: auto;
}

.map-card.unlocked:hover {
  transform: translateY(-6px);
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.22), 0 20px 32px rgba(0, 0, 0, 0.28);
  filter: brightness(1.06);
}

.map-card.unlocked:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.22);
}

.map-card.locked {
  filter: brightness(0.45) grayscale(0.4);
  cursor: not-allowed;
}

.map-card .map-num {
  font-size: 0.85rem;
  font-weight: 800;
  opacity: 0.9;
  letter-spacing: 0.08em;
}

.map-card .map-name {
  font-size: clamp(1.1rem, 3vw, 1.4rem);
  font-weight: 900;
  letter-spacing: 0.04em;
}

.map-card .map-thumb {
  flex: 1;
  border-radius: 12px;
  min-height: 56px;
  margin: 0.2rem 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
}

.map-card .map-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.map-card .map-stars {
  letter-spacing: 0.15em;
  font-size: 1.15rem;
}

.map-card .map-stars .on {
  color: #ffd84d;
  text-shadow: 0 0 8px rgba(255, 200, 40, 0.6);
}

.map-card .map-stars .off {
  color: rgba(255, 255, 255, 0.28);
}

.map-lock {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  background: rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

/* Map card themes */
.map-card[data-map="0"] {
  background: linear-gradient(145deg, #5ec8ff, #3aa0e0 40%, #6bcb4a);
}
.map-card[data-map="0"] .map-thumb {
  background: linear-gradient(180deg, #87ceeb 50%, #5cb85c 50%);
}
.map-card[data-map="1"] {
  background: linear-gradient(145deg, #ff9a4a, #e06a20 45%, #c4a05a);
}
.map-card[data-map="1"] .map-thumb {
  background: linear-gradient(180deg, #ff8c42 45%, #c4783a 45%, #a06030);
}
.map-card[data-map="2"] {
  background: linear-gradient(145deg, #2a3a6a, #1a2850 40%, #c8e8ff);
}
.map-card[data-map="2"] .map-thumb {
  background: linear-gradient(180deg, #0a1630 40%, #d8eefc 40%, #eef8ff);
}
.map-card[data-map="3"] {
  background: linear-gradient(145deg, #6a1a1a, #3a0a0a 40%, #ff6a20);
}
.map-card[data-map="3"] .map-thumb {
  background: linear-gradient(180deg, #2a0808 35%, #8b1a00 55%, #ff4500);
}

/* ===== HUD ===== */
.hud-screen {
  flex-direction: column;
  justify-content: flex-start;
  background: transparent;
  pointer-events: none !important;
}

.hud-screen.active {
  display: flex;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  width: 100%;
  pointer-events: none;
}

.hud-left,
.hud-center,
.hud-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  pointer-events: auto;
}

.hud-left {
  flex: 1;
  min-width: 0;
}

.hud-center {
  flex-direction: column;
  background: rgba(15, 25, 45, 0.6);
  backdrop-filter: blur(10px);
  padding: 0.4rem 1.1rem;
  border-radius: 16px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  min-width: 120px;
}

.hud-right {
  flex: 1;
  justify-content: flex-end;
  flex-direction: column;
  align-items: flex-end;
  background: rgba(15, 25, 45, 0.55);
  backdrop-filter: blur(10px);
  padding: 0.4rem 0.75rem;
  border-radius: 16px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}

.hud-label {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  opacity: 0.85;
}

.hud-score {
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  font-weight: 900;
  line-height: 1.1;
}

.hud-map-name {
  background: rgba(15, 25, 45, 0.55);
  backdrop-filter: blur(10px);
  padding: 0.45rem 0.75rem;
  border-radius: 14px;
  font-weight: 800;
  font-size: clamp(0.7rem, 2vw, 0.9rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.hud-pigs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 160px;
}

.pig-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffc0d4, #ff7aa2);
  box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.1), 0 2px 0 #c44a72;
  position: relative;
}

.pig-icon.used {
  opacity: 0.25;
  filter: grayscale(0.6);
}

.pig-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 55%;
  width: 40%;
  height: 28%;
  transform: translate(-50%, -50%);
  background: #ff9fbc;
  border-radius: 50%;
}

.score-popups {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.score-popup {
  position: absolute;
  font-weight: 900;
  font-size: 1.1rem;
  color: #ffe066;
  text-shadow: 0 2px 0 #a07000, 0 0 10px rgba(0, 0, 0, 0.5);
  animation: scoreFloat 1s ease forwards;
  white-space: nowrap;
}

/* ===== OVERLAYS ===== */
.overlay-screen {
  align-items: center;
  justify-content: center;
  background: rgba(5, 10, 20, 0.62);
  backdrop-filter: blur(3px);
  padding: 1rem;
}

.panel {
  background: linear-gradient(180deg, rgba(40, 55, 90, 0.95), rgba(20, 30, 55, 0.97));
  border-radius: 28px;
  padding: clamp(1.25rem, 4vw, 2.2rem);
  width: min(440px, 100%);
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.08),
    0 16px 0 rgba(0, 0, 0, 0.25),
    0 28px 50px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: panelIn 0.35s ease both;
}

.panel-final {
  width: min(480px, 100%);
}

.panel-title {
  font-size: clamp(1.6rem, 5vw, 2.3rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  margin-bottom: 1rem;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.panel-title.success {
  color: #7dff9a;
}

.panel-title.fail {
  color: #ff7a7a;
}

.panel-title.gameover {
  color: #ffd84d;
  font-size: clamp(2.2rem, 8vw, 3.4rem);
  text-shadow:
    0 4px 0 #a07000,
    0 0 30px rgba(255, 200, 40, 0.45);
}

.star-row {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1.1rem;
  font-size: clamp(2.2rem, 8vw, 3rem);
}

.star-row .star {
  color: rgba(255, 255, 255, 0.2);
  transform: scale(0.7);
  transition: color 0.2s, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.star-row .star.on {
  color: #ffd84d;
  text-shadow: 0 0 16px rgba(255, 200, 40, 0.7);
  transform: scale(1);
}

.panel-stats {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 1.4rem;
  opacity: 0.95;
}

.panel-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
}

.total-line {
  font-size: 1.2rem;
  font-weight: 800;
}

.final-stars-groups {
  display: flex;
  justify-content: center;
  gap: 0.9rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.final-stars-groups .group {
  display: flex;
  gap: 0.15rem;
  font-size: 1.4rem;
}

.final-stars-groups .on {
  color: #ffd84d;
  text-shadow: 0 0 8px rgba(255, 200, 40, 0.55);
}

.final-stars-groups .off {
  color: rgba(255, 255, 255, 0.22);
}

.rotate-hint {
  display: none;
  position: fixed;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(16px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes scoreFloat {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.7);
  }
  20% {
    transform: translate(-50%, -70%) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -140%) scale(1);
  }
}

@media (max-width: 640px) {
  .map-grid {
    grid-template-columns: 1fr;
  }

  .maps-header {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .maps-header .btn {
    justify-self: start;
  }

  .hud-map-name {
    display: none;
  }

  .panel-buttons {
    flex-direction: column;
  }

  .panel-buttons .btn {
    width: 100%;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .rotate-hint {
    display: block;
  }
}
