:root {
  --leaf: #1f7a3a;
  --leaf-deep: #14331c;
  --tomato: #e23a2b;
  --carrot: #ff8c32;
  --cream: #fff6e8;
  --ink: #1b2416;
  --gold: #f4c430;
  --night: #1a1430;
  --panel: rgba(255, 246, 232, 0.92);
  --shadow: 0 18px 50px rgba(20, 51, 28, 0.28);
  --radius: 22px;
  --focus: #ffd166;
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--leaf-deep);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Nunito, system-ui, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
}

button,
a {
  font: inherit;
}

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
}

#game-canvas,
#trail-canvas,
#fx-flash,
#float-layer,
#ui-root {
  position: absolute;
  inset: 0;
}

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

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

#fx-flash {
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s linear;
}

#fx-flash.is-on {
  opacity: 1;
}

#fx-flash.is-slice {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.18), transparent 55%);
}

#fx-flash.is-gold {
  background: radial-gradient(circle, rgba(255, 214, 80, 0.35), transparent 55%);
}

#fx-flash.is-bomb {
  background: radial-gradient(circle, rgba(255, 60, 30, 0.45), transparent 60%);
}

#float-layer {
  z-index: 3;
  pointer-events: none;
}

#ui-root {
  z-index: 4;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  pointer-events: none;
}

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

#screen-title.is-active,
#screen-maps.is-active,
#screen-pause.is-active,
#screen-results.is-active,
#screen-gameover.is-active,
#screen-loading.is-active {
  pointer-events: auto;
}

.screen-hud.is-active {
  pointer-events: none;
  align-items: flex-start;
}

.screen-hud.is-active button {
  pointer-events: auto;
}

.top-tools {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 6;
  pointer-events: auto;
}

body[data-screen="hud"] .top-tools,
body[data-screen="pause"] .top-tools {
  display: none;
}

.panel {
  width: min(720px, 100%);
  background: var(--panel);
  border: 3px solid #214d2a;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 22px 20px;
  text-align: center;
  backdrop-filter: blur(8px);
}

.title-panel,
.finale-panel {
  width: min(640px, 100%);
}

.maps-panel,
.results-panel {
  width: min(980px, 100%);
}

.slim-panel {
  width: min(460px, 100%);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  text-align: left;
  margin-bottom: 16px;
}

.head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 6px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: #b42318;
  font-weight: 700;
}

.logo {
  margin: 0 0 10px;
  font-size: clamp(2.4rem, 8vw, 4.4rem);
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: var(--leaf);
  text-shadow: 3px 3px 0 #d6f5c8;
}

.logo span {
  color: var(--tomato);
}

h2 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.3rem);
}

.lede,
.loading-copy,
.hint {
  color: #3d4a34;
}

.lede {
  margin: 0 auto 16px;
  max-width: 38ch;
  line-height: 1.45;
}

.hero {
  display: block;
  width: min(100%, 460px);
  margin: 8px auto 14px;
  border-radius: 18px;
  border: 3px solid #214d2a;
  box-shadow: 0 10px 0 #e8c48a;
}

.hint {
  margin: 12px 0 0;
  font-size: 0.9rem;
}

.primary-btn,
.ghost-btn,
.icon-btn,
.map-card {
  cursor: pointer;
  border-radius: 999px;
  border: 3px solid #214d2a;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.12s ease;
}

.primary-btn {
  background: linear-gradient(#ffbf3f, var(--carrot));
  color: var(--ink);
  font-weight: 800;
  font-size: 1.25rem;
  padding: 14px 36px;
  min-width: 180px;
  box-shadow: 0 6px 0 #b45a12;
}

.ghost-btn {
  background: #fff;
  color: var(--leaf-deep);
  font-weight: 700;
  padding: 10px 16px;
}

.ghost-btn.danger {
  color: var(--tomato);
}

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: #fff6e8;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.primary-btn:hover,
.ghost-btn:hover,
.icon-btn:hover,
.map-card.is-unlocked:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
}

.primary-btn:active,
.ghost-btn:active,
.icon-btn:active {
  transform: translateY(1px);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.map-card {
  display: grid;
  gap: 6px;
  text-align: left;
  border-radius: 18px;
  padding: 0 0 12px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 8px 0 #d7c3a0;
}

.map-card.is-locked {
  cursor: not-allowed;
  filter: grayscale(0.55);
  opacity: 0.78;
}

.map-thumb {
  display: block;
  height: 112px;
  background-size: cover;
  background-position: center;
  border-bottom: 3px solid #214d2a;
}

.map-index,
.map-name,
.map-blurb,
.map-meta,
.map-state {
  padding: 0 12px;
}

.map-index {
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  color: #b42318;
  font-weight: 800;
}

.map-name {
  font-size: 1.15rem;
  font-weight: 800;
}

.map-blurb {
  color: #4c5944;
  font-size: 0.88rem;
  min-height: 2.6em;
}

.map-meta {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.stars .star-on {
  color: #d7a000;
}

.stars .star-off {
  color: #c9b7a0;
}

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

.hud-top {
  width: min(1100px, 100%);
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  pointer-events: none;
}

.hud-block,
.hud-lives,
.icon-btn {
  pointer-events: auto;
}

.hud-block {
  background: rgba(255, 246, 232, 0.9);
  border: 3px solid #214d2a;
  border-radius: 16px;
  padding: 6px 12px;
  min-width: 78px;
  text-align: center;
  box-shadow: 0 5px 0 rgba(20, 51, 28, 0.2);
}

.hud-label,
.hud-level {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6a4a22;
}

.hud-block strong {
  font-size: 1.4rem;
}

.hud-bar {
  margin-top: 4px;
  height: 8px;
  border-radius: 999px;
  background: #e8d3b0;
  overflow: hidden;
}

#hud-progress {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #7ed957, #2d8a4e);
}

.hud-lives {
  display: flex;
  gap: 6px;
  background: rgba(255, 246, 232, 0.9);
  border: 3px solid #214d2a;
  border-radius: 16px;
  padding: 8px 10px;
}

.life {
  width: 18px;
  height: 18px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--tomato);
  box-shadow: 0 0 0 2px #7a1810 inset;
}

.life.is-off {
  background: #c9b7a0;
  box-shadow: none;
}

.hud-combo {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  color: #fff8d8;
  text-shadow: 0 3px 0 #b42318, 0 8px 18px rgba(0, 0, 0, 0.35);
  font-weight: 900;
  letter-spacing: 0.08em;
  opacity: 0;
}

.hud-combo.is-hot {
  opacity: 1;
}

.floater {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 0 #214d2a;
  animation: float-up 0.7s ease-out forwards;
  font-size: 1.2rem;
}

.floater.is-gold {
  color: var(--gold);
  font-size: 1.4rem;
}

.floater.is-miss {
  color: #ffd0c8;
}

.result-stars {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 16px;
  min-height: 64px;
}

.result-star {
  font-size: 3rem;
  color: #d7c3a0;
  transform: scale(0.6);
  opacity: 0.4;
}

.result-star.is-filled {
  color: var(--gold);
  opacity: 1;
  transform: scale(1);
  animation: star-pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
  text-shadow: 0 4px 0 #b8860b;
}

.result-star.is-empty {
  opacity: 0.35;
  transform: scale(0.9);
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 16px;
}

.stats div {
  background: #fff;
  border: 2px solid #214d2a;
  border-radius: 14px;
  padding: 8px 6px;
}

.stats dt {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6a4a22;
}

.stats dd {
  margin: 2px 0 0;
  font-size: 1.3rem;
  font-weight: 800;
}

.finale-title {
  font-size: clamp(2.4rem, 8vw, 4rem);
  letter-spacing: 0.08em;
  color: var(--tomato);
  margin-bottom: 6px;
}

.finale-line {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--leaf);
  margin: 0 0 16px;
}

.finale-panel .stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

#boot-fail {
  position: absolute;
  inset: auto 16px 16px;
  z-index: 8;
  background: #fff1f0;
  color: #8a1c13;
  border: 2px solid #8a1c13;
  border-radius: 12px;
  padding: 10px 12px;
}

@keyframes float-up {
  from { opacity: 1; transform: translate(-50%, -50%); }
  to { opacity: 0; transform: translate(-50%, -120%); }
}

@keyframes star-pop {
  0% { transform: scale(0.3) rotate(-12deg); }
  70% { transform: scale(1.15) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

@media (max-width: 820px) {
  .map-grid,
  .stats,
  .finale-panel .stats {
    grid-template-columns: 1fr 1fr;
  }

  .hud-top {
    grid-template-columns: auto 1fr auto auto;
  }

  .hud-lives {
    grid-column: 1 / 2;
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 620px) {
  .panel {
    padding: 16px 14px 14px;
  }

  .map-grid {
    grid-template-columns: 1fr;
    max-height: min(62vh, 540px);
    overflow: auto;
  }

  .hud-top {
    grid-template-columns: 1fr 1fr auto;
    width: 100%;
  }

  .hud-level-wrap {
    grid-column: 1 / -1;
    order: -1;
  }

  .hero {
    max-height: 28vh;
    object-fit: cover;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .hero {
    display: none;
  }

  .panel {
    padding: 12px 16px;
  }

  .logo {
    font-size: 2rem;
  }

  .map-thumb {
    height: 64px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .primary-btn,
  .ghost-btn,
  .icon-btn,
  .map-card,
  .floater,
  .result-star {
    transition: none;
    animation: none;
  }
}
