:root {
  --ink: #2a150f;
  --cream: #fff6e8;
  --gold: #ffd24a;
  --gold-dim: #8a7a55;
  --orange: #ff7a18;
  --orange-deep: #e85d00;
  --pink: #ff5d9a;
  --panel: rgba(22, 14, 28, 0.82);
  --panel-border: rgba(255, 214, 120, 0.55);
  --shadow: 0 10px 0 rgba(90, 30, 8, 0.28);
  --hud: rgba(18, 12, 22, 0.55);
  --radius: 22px;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #4ec3ff;
  color: var(--cream);
  font-family: "Nunito", "Trebuchet MS", sans-serif;
  font-weight: 800;
  user-select: none;
  touch-action: none;
}

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

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

#popups {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  font-size: clamp(16px, 2.4vw, 26px);
  color: #ffe27a;
  text-shadow: 0 2px 0 #7a3a00, 0 0 10px rgba(255, 180, 40, 0.55);
  animation: popup-fly 0.85s ease-out forwards;
  white-space: nowrap;
}

@keyframes popup-fly {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -130%) scale(1); }
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.32s ease, visibility 0.32s ease;
}

.screen.is-on {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.logo {
  text-align: center;
  filter: drop-shadow(0 10px 0 rgba(80, 20, 40, 0.25));
  animation: logo-bob 3.4s ease-in-out infinite;
}

@keyframes logo-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.logo-angry,
.logo-pigs {
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  letter-spacing: 0.06em;
  line-height: 0.88;
}

.logo-angry {
  font-size: clamp(56px, 14vw, 118px);
  color: #ff4d88;
  -webkit-text-stroke: 8px #6a1038;
  paint-order: stroke fill;
  text-shadow:
    0 8px 0 #3d0a20,
    0 14px 18px rgba(0, 0, 0, 0.28);
}

.logo-pigs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.02em;
  font-size: clamp(62px, 16vw, 132px);
  color: #ffe14a;
  -webkit-text-stroke: 8px #8a4b00;
  paint-order: stroke fill;
  text-shadow:
    0 8px 0 #5a2e00,
    0 14px 18px rgba(0, 0, 0, 0.25);
}

.logo-pig-slot {
  display: inline-flex;
  width: 0.82em;
  height: 0.92em;
  align-items: center;
  justify-content: center;
  margin: 0 0.02em;
}

.logo-pig {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 6px 0 #5a2e00);
}

.btn {
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  border: none;
  cursor: pointer;
  color: #fffaf0;
  letter-spacing: 0.06em;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}

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

.btn:active {
  transform: translateY(3px) scale(0.96);
  filter: brightness(0.95);
}

.btn-start {
  margin-top: clamp(22px, 4vh, 42px);
  min-width: min(320px, 78vw);
  min-height: 76px;
  padding: 16px 42px;
  font-size: clamp(34px, 6vw, 48px);
  border-radius: 999px;
  background: linear-gradient(#ffb02e, #ff7a18);
  box-shadow:
    0 8px 0 #b34800,
    0 14px 20px rgba(0, 0, 0, 0.28);
}

.btn-start:hover {
  box-shadow:
    0 10px 0 #b34800,
    0 18px 24px rgba(0, 0, 0, 0.3);
}

.btn-start:active {
  box-shadow: 0 3px 0 #b34800;
}

.btn-primary,
.btn-ghost {
  min-height: 54px;
  min-width: 132px;
  padding: 10px 18px;
  font-size: 22px;
  border-radius: 16px;
}

.btn-primary {
  background: linear-gradient(#ffb02e, #ff7a18);
  box-shadow: 0 5px 0 #b34800;
}

.btn-ghost {
  background: linear-gradient(#6d7dff, #4454e8);
  box-shadow: 0 5px 0 #2430a0;
}

.btn-icon,
.btn-hud {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 14, 26, 0.62);
  border: 2px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.btn-hud {
  width: 42px;
  height: 42px;
}

.map-header {
  width: min(920px, 94vw);
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 18px 0 12px;
}

.map-title {
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  font-size: clamp(28px, 5vw, 44px);
  text-align: center;
  color: #fff4c8;
  text-shadow: 0 4px 0 #5a2e12, 0 8px 16px rgba(0, 0, 0, 0.28);
  letter-spacing: 0.04em;
}

.stars-total {
  min-width: 132px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--hud);
  border: 2px solid rgba(255, 210, 74, 0.4);
  text-align: center;
  font-size: 15px;
  color: var(--gold);
}

.map-grid {
  width: min(920px, 94vw);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding-bottom: 24px;
  overflow: auto;
  max-height: calc(100vh - 110px);
}

.map-card {
  position: relative;
  border: none;
  border-radius: 22px;
  overflow: hidden;
  text-align: left;
  color: var(--cream);
  background: #20161c;
  box-shadow: 0 8px 0 rgba(40, 16, 8, 0.35), 0 16px 24px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease;
}

.map-card.unlocked:hover {
  transform: translateY(-6px);
  filter: brightness(1.05);
}

.map-card.unlocked:active {
  transform: translateY(-1px) scale(0.98);
}

.map-card.locked {
  cursor: default;
  filter: saturate(0.25) brightness(0.55);
}

.map-thumb {
  height: 118px;
  position: relative;
  overflow: hidden;
}

.map-thumb::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 28px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.28));
}

.thumb-farm { background: linear-gradient(#6ad0ff 0 52%, #6fc24a 52% 100%); }
.thumb-farm .prop-a {
  position: absolute; right: 18%; bottom: 28%; width: 46px; height: 34px;
  background: #d94040; border-radius: 3px 3px 0 0;
  clip-path: polygon(50% 0, 100% 38%, 100% 100%, 0 100%, 0 38%);
}
.thumb-farm .prop-b {
  position: absolute; left: 12%; bottom: 34%; width: 70px; height: 10px;
  background: #c68642; border-radius: 4px;
}

.thumb-canyon { background: linear-gradient(#ff8a3a 0 40%, #e09a46 40% 70%, #c47a32 70% 100%); }
.thumb-canyon .prop-a {
  position: absolute; left: 10%; bottom: 18%; width: 38px; height: 52px;
  background: #8a4b28; clip-path: polygon(20% 100%, 0 40%, 35% 0, 70% 30%, 100% 100%);
}
.thumb-canyon .prop-b {
  position: absolute; right: 16%; bottom: 18%; width: 50px; height: 70px;
  background: #6b351c; clip-path: polygon(10% 100%, 20% 20%, 60% 0, 100% 45%, 80% 100%);
}

.thumb-forest { background: linear-gradient(#0b1734 0 58%, #d9e7f2 58% 100%); }
.thumb-forest .prop-a,
.thumb-forest .prop-b {
  position: absolute; bottom: 34%;
  width: 0; height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-bottom: 42px solid #163a28;
}
.thumb-forest .prop-a { left: 16%; }
.thumb-forest .prop-b { right: 22%; border-left-width: 20px; border-right-width: 20px; border-bottom: 54px solid #0f2c1e; }
.thumb-forest .moon {
  position: absolute; top: 14px; right: 18px; width: 28px; height: 28px;
  background: #f3f0c8; border-radius: 50%; box-shadow: 0 0 16px #fff6b0;
}

.thumb-volcano { background: linear-gradient(#2a0c10 0 42%, #5a1810 42% 68%, #1a0a0c 68% 100%); }
.thumb-volcano .prop-a {
  position: absolute; left: 18%; bottom: 26%; width: 90px; height: 48px;
  background: #3a3a42; clip-path: polygon(0 100%, 8% 40%, 28% 55%, 42% 18%, 60% 50%, 78% 22%, 100% 100%);
}
.thumb-volcano .prop-b {
  position: absolute; left: 28%; bottom: 22%; width: 56px; height: 10px;
  background: #ff6a18; border-radius: 8px; box-shadow: 0 0 14px #ff5410;
}

.map-body {
  padding: 10px 14px 14px;
}

.map-kicker {
  font-size: 12px;
  letter-spacing: 0.14em;
  color: #ffdca0;
  opacity: 0.85;
}

.map-name {
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  font-size: 22px;
  margin: 2px 0 8px;
}

.map-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.map-best {
  font-size: 13px;
  color: #ffe7b0;
}

.map-stars {
  display: flex;
  gap: 3px;
  font-size: 18px;
}

.star {
  color: var(--gold-dim);
  opacity: 0.45;
  text-shadow: none;
}

.star.on {
  color: #ffd24a;
  opacity: 1;
  text-shadow: 0 0 10px rgba(255, 210, 74, 0.85);
}

.star.pop {
  animation: star-pop 0.42s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

@keyframes star-pop {
  0% { transform: scale(0.2) rotate(-20deg); opacity: 0; }
  70% { transform: scale(1.18) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

.lock-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 6, 10, 0.28);
  font-size: 42px;
  pointer-events: none;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  pointer-events: none;
}

.hud.is-on { display: flex; }

.hud-left,
.hud-center,
.hud-right {
  pointer-events: auto;
  background: var(--hud);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  padding: 8px 10px;
  backdrop-filter: blur(8px);
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 46vw;
}

.hud-map {
  font-size: 13px;
  line-height: 1.15;
  color: #fff3d2;
}

.hud-center {
  text-align: center;
  min-width: 120px;
}

.hud-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: #ffe7a8;
}

.hud-score {
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  font-size: clamp(22px, 3.4vw, 34px);
  color: #fff;
  text-shadow: 0 2px 0 #3a2208;
}

.hud-right {
  text-align: right;
  min-width: 118px;
}

.hud-pigs-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

#hud-pigs-count {
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  font-size: 22px;
}

.hud-pigs {
  display: flex;
  gap: 3px;
}

.pig-ico {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd0e0, #f06292);
  box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.12);
  position: relative;
  opacity: 0.28;
}

.pig-ico.on { opacity: 1; }

.pig-ico::before,
.pig-ico::after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
  width: 5px;
  height: 5px;
  top: 5px;
}

.pig-ico::before { left: 3px; }
.pig-ico::after { right: 3px; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 4, 12, 0.55);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s ease, visibility 0.28s ease;
  padding: 16px;
}

.overlay.is-on {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.panel {
  width: min(520px, 94vw);
  background: var(--panel);
  border: 3px solid var(--panel-border);
  border-radius: 28px;
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
  transform: translateY(10px) scale(0.96);
  animation: panel-in 0.32s ease forwards;
}

@keyframes panel-in {
  to { transform: none; }
}

.panel-title {
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  font-size: clamp(32px, 6vw, 46px);
  letter-spacing: 0.03em;
  margin-bottom: 10px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.win-title { color: #7dff9a; }
.lose-title { color: #ff8aa0; }
.over-title {
  color: #ffd24a;
  font-size: clamp(46px, 9vw, 72px);
  text-shadow: 0 6px 0 #7a3e00, 0 0 24px rgba(255, 180, 40, 0.35);
}

.star-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  font-size: 42px;
  margin: 6px 0 10px;
}

.panel-score {
  font-family: "Lilita One", "Trebuchet MS", sans-serif;
  font-size: 40px;
  color: #fff;
}

.panel-sub {
  margin-top: 4px;
  color: #ffe2b0;
  font-size: 16px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.over-label {
  letter-spacing: 0.16em;
  font-size: 13px;
  color: #ffe7a8;
}

.star-groups {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 14px 0 6px;
  flex-wrap: wrap;
}

.star-group {
  display: flex;
  gap: 3px;
  font-size: 22px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

#rotate-hint {
  display: none;
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 8, 16, 0.72);
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .map-grid { grid-template-columns: 1fr; max-height: calc(100vh - 118px); }
  .map-thumb { height: 86px; }
  .map-body { padding: 8px 12px 12px; }
  .map-header { margin-top: 36px; }
  .hud { flex-wrap: wrap; }
  .hud-left { max-width: 100%; order: 1; }
  .hud-center { order: 3; flex: 1 1 100%; }
  .hud-right { order: 2; margin-left: auto; }
  .logo-angry { -webkit-text-stroke-width: 6px; }
  .logo-pigs { -webkit-text-stroke-width: 6px; }
  .btn-primary, .btn-ghost { min-width: 120px; font-size: 18px; }
}

@media (orientation: portrait) and (max-width: 820px) {
  #rotate-hint { display: block; }
  .hud-map { display: none; }
}

@media (max-height: 500px) {
  .logo { transform: scale(0.78); }
  .btn-start { min-height: 58px; font-size: 30px; margin-top: 8px; }
  .map-thumb { height: 84px; }
}
