:root {
  --leaf: #3c9a45;
  --leaf-dark: #1e5c2b;
  --cream: #fff8e7;
  --sand: #f2d8a7;
  --tomato: #e83838;
  --ink: #2b2b2b;
  --shadow: rgba(20, 40, 20, 0.35);
  --radius: 16px;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  background: var(--leaf);
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#game-canvas,
#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#fx-canvas {
  z-index: 1;
  pointer-events: none;
}

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

.screen {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}

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

#screen-hud {
  pointer-events: none;
}

#screen-hud .btn,
#screen-hud .hint,
#screen-hud .hud-buttons {
  pointer-events: auto;
}

.button-less {
  border: 0;
  background: transparent;
}

.menu-inner,
.maps-inner {
  margin: auto;
  text-align: center;
  padding: 24px 16px;
  width: 100%;
  max-width: 860px;
}

.screen-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
}

.screen-header h2 {
  font-size: 1.6rem;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.logo {
  font-size: clamp(3rem, 9vw, 6rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 4px 0 var(--tomato), 0 8px 22px rgba(0, 0, 0, 0.4);
  animation: float 3.4s ease-in-out infinite;
}

.logo em {
  font-style: normal;
  color: var(--tomato);
  text-shadow:
    0 4px 0 #7a1c1c,
    0 8px 22px rgba(0, 0, 0, 0.4);
}

.tagline {
  font-size: 1.1rem;
  color: #fff;
  margin: 18px 0 26px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  font-weight: 600;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.menu-actions .btn {
  min-width: min(260px, 78vw);
}

.menu-stats {
  display: flex;
  gap: 26px;
  justify-content: center;
  margin-top: 26px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 800;
  padding: 14px 22px;
  border-radius: 999px;
  letter-spacing: 0.03em;
  color: #fff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.22), 0 10px 24px rgba(0, 0, 0, 0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}

.btn:focus-visible {
  outline: 3px solid #ffd24a;
  outline-offset: 3px;
}

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

.btn-primary {
  background: linear-gradient(180deg, #f0b429, var(--tomato));
}

.btn-primary:hover {
  filter: brightness(1.07);
}

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

.btn-secondary:hover {
  filter: brightness(1.07);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35), 0 5px 0 rgba(0, 0, 0, 0.15);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-icon {
  width: 52px;
  height: 52px;
  padding: 0;
  font-size: 1.3rem;
  background: rgba(30, 60, 30, 0.55);
  border-radius: 14px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
}

.btn-icon:hover {
  filter: brightness(1.1);
}

#screen-menu {
  background: radial-gradient(120% 120% at 50% 20%, rgba(255, 255, 255, 0.14) 0%, rgba(0, 0, 0, 0.25) 100%);
  align-items: center;
  justify-content: center;
}

#screen-maps {
  background: rgba(10, 30, 14, 0.35);
  overflow-y: auto;
  text-align: center;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  padding: 4px 0 24px;
}

.map-card {
  position: relative;
  appearance: none;
  border: 0;
  cursor: pointer;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(240, 235, 210, 0.95));
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: left;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  color: var(--ink);
  min-height: 150px;
}

.map-card:hover:not(.locked) {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.32);
}

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

.map-card.locked::after {
  content: 'LOCKED';
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--tomato);
  background: rgba(255, 255, 255, 0.75);
  padding: 4px 9px;
  border-radius: 999px;
}

.map-card-num {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--leaf);
  text-transform: uppercase;
}

.map-card-name {
  font-size: 1.3rem;
  font-weight: 900;
  margin: 4px 0 8px;
}

.map-card-stars {
  color: #e9b62c;
  font-size: 1.15rem;
  line-height: 1;
  margin-bottom: 8px;
}

.map-card-stars .star.empty {
  color: rgba(0, 0, 0, 0.18);
}

.map-card-best {
  font-size: 0.95rem;
  font-weight: 700;
  color: #3a7c45;
}

.map-card-tag {
  font-size: 0.8rem;
  color: #6b6b4d;
  margin-top: 6px;
}

.hud {
  flex-direction: column;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
  gap: 8px;
}

.hud-left,
.hud-center,
.hud-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(20, 50, 25, 0.5);
  padding: 8px 14px;
  border-radius: var(--radius);
  min-width: 86px;
}

.hud-label {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.85);
  text-transform: uppercase;
}

.hud-value {
  font-size: 1.8rem;
  font-weight: 900;
  color: #fff;
  line-height: 1;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.hud-combo {
  margin-top: 4px;
  font-weight: 900;
  color: #ffd24a;
  font-size: 1rem;
  animation: pulse 0.5s ease infinite alternate;
}

.hud-icons {
  display: flex;
}

.hud-buttons {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.hud-lives {
  font-size: 1.3rem;
  color: var(--tomato);
  letter-spacing: 0.06em;
}

.hud-title {
  text-align: center;
  color: #fff;
  font-weight: 900;
  font-size: 1.1rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  margin-top: 10px;
}

.hud-stars {
  text-align: center;
  color: #ffd24a;
  font-size: 1.1rem;
  margin-top: 4px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 14%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.05rem;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.hint.show {
  opacity: 1;
}

.overlay {
  align-items: center;
  justify-content: center;
  background: rgba(8, 26, 12, 0.62);
  backdrop-filter: blur(4px);
}

.panel {
  background: linear-gradient(180deg, #fffdf4, #f6edd6);
  border-radius: 24px;
  padding: 26px 30px;
  max-width: 480px;
  width: min(440px, 92vw);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  animation: pop-in 0.28s ease;
}

.panel h2 {
  font-size: 1.7rem;
  color: var(--leaf);
  margin-bottom: 6px;
}

.panel p {
  color: #555;
  margin-bottom: 12px;
}

.over-title {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--tomato);
  text-shadow: 0 3px 0 #8a1c1c;
  margin-bottom: 4px;
}

.byline {
  font-weight: 700;
  color: #5b7a3d;
  margin-bottom: 14px;
}

.stars-big {
  font-size: 3rem;
  line-height: 1;
  margin: 6px 0 14px;
  color: #d7b52f;
}

.stars-big .star {
  display: inline-block;
  opacity: 0;
  transform: scale(0);
}

.stars-big .star.empty {
  color: #d0d0c2;
  opacity: 1;
  transform: scale(1);
}

.stars-big .star.pop {
  animation: star-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.results-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 18px;
  text-align: left;
}

.row {
  display: flex;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.98rem;
}

.row span {
  color: #777;
  font-weight: 700;
}

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

.panel-actions .btn {
  flex: 1;
  min-width: 120px;
}

.hidden {
  display: none !important;
}

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

@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.08);
  }
}

@keyframes star-pop {
  0% {
    opacity: 0;
    transform: scale(0) rotate(-40deg);
  }
  70% {
    opacity: 1;
    transform: scale(1.3) rotate(10deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes pop-in {
  from {
    transform: translateY(18px) scale(0.96);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .hud-left,
  .hud-center,
  .hud-right {
    min-width: 64px;
    padding: 6px 9px;
  }
  .hud-value {
    font-size: 1.35rem;
  }
  .hud-buttons .btn-icon {
    width: 42px;
    height: 42px;
  }
  .map-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  .panel {
    padding: 20px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .map-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }
  .hud-value {
    font-size: 1.3rem;
  }
  .hint {
    bottom: 8%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .logo,
  .hud-combo {
    animation: none;
  }
  .screen.active .panel {
    animation: none;
  }
}