:root {
  color-scheme: light;
  --ink: #2f3320;
  --muted: #66704f;
  --panel: rgba(255, 247, 214, 0.84);
  --panel-strong: rgba(255, 247, 214, 0.96);
  --line: rgba(93, 82, 44, 0.26);
  --road: #b78957;
  --grass: #8bcf58;
  --sand: #e7c477;
  --gold: #f2c94c;
  --cyan: #2b9faa;
  --red: #d84a3a;
  --green: #66b94e;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(110, 194, 222, 0.55), rgba(255, 231, 152, 0.2) 38%, rgba(107, 178, 76, 0.42)),
    #b7dc72;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 14px;
}

.stage {
  position: relative;
  width: min(100%, 820px);
  height: min(100vh - 28px, 960px);
  min-height: 560px;
  overflow: hidden;
  border: 2px solid rgba(94, 92, 45, 0.34);
  border-radius: 8px;
  background: #8bcf58;
  box-shadow: 0 18px 60px rgba(58, 85, 35, 0.28);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #8bcf58;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: minmax(72px, 0.8fr) minmax(128px, 1.25fr) minmax(128px, 1.25fr) minmax(72px, 0.8fr) 42px 42px;
  gap: 8px;
  align-items: stretch;
  pointer-events: none;
}

.hud-item,
.icon-button {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(75, 68, 38, 0.16);
  backdrop-filter: blur(10px);
}

.hud-item {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  column-gap: 6px;
  row-gap: 2px;
  align-content: center;
  padding: 7px 9px;
}

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

.hud-item span,
.hud-item small {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1;
}

.hud-item strong {
  font-size: 1rem;
  line-height: 1;
  justify-self: end;
}

.hud-item .meter {
  grid-column: 1 / -1;
}

.meter {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.meter--danger i {
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--red));
}

.icon-button {
  display: grid;
  place-items: center;
  pointer-events: auto;
  cursor: pointer;
  font-weight: 800;
}

.icon-button.is-muted {
  color: rgba(47, 51, 32, 0.48);
}

.stage-banner {
  position: absolute;
  z-index: 8;
  top: 68px;
  left: 50%;
  min-width: 138px;
  transform: translate(-50%, -10px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  border: 2px solid rgba(90, 78, 38, 0.28);
  border-radius: 8px;
  background: rgba(255, 246, 194, 0.95);
  color: #3c3a20;
  box-shadow: 0 10px 26px rgba(76, 79, 39, 0.2);
  padding: 9px 18px;
  text-align: center;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.stage-banner.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.touch-controls {
  position: absolute;
  z-index: 6;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(52px, 72px));
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.touch-button {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid rgba(93, 82, 44, 0.24);
  border-radius: 8px;
  background: rgba(255, 247, 214, 0.74);
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 900;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  backdrop-filter: blur(10px);
}

.touch-button--accent {
  border-color: rgba(240, 200, 74, 0.55);
  color: var(--gold);
}

.touch-button:active,
.touch-button.is-active,
.icon-button:active,
.primary-button:active,
.secondary-button:active {
  transform: translateY(1px);
}

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(255, 247, 214, 0.04), rgba(64, 86, 36, 0.38)),
    rgba(42, 66, 28, 0.18);
}

.overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-panel {
  width: min(100%, 430px);
  border: 2px solid rgba(93, 82, 44, 0.25);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 24px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(57, 68, 34, 0.28);
}

.kicker {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.overlay h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.05;
}

.overlay p {
  color: var(--muted);
  line-height: 1.5;
}

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

.primary-button,
.secondary-button {
  min-width: 116px;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  background: var(--gold);
  color: #17170f;
}

.secondary-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.42);
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  .game-shell {
    padding: 0;
  }

  .stage {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .hud {
    grid-template-columns: 1fr 1fr 42px 42px;
    grid-auto-rows: minmax(42px, auto);
  }

  .hud-item:nth-child(3),
  .hud-item:nth-child(4) {
    grid-row: 2;
  }

  #pauseButton {
    grid-column: 3;
    grid-row: 1;
  }

  #musicButton {
    grid-column: 4;
    grid-row: 1;
  }

  .hud-item span,
  .hud-item small {
    font-size: 0.64rem;
  }

  .hud-item strong {
    font-size: 0.92rem;
  }

  .overlay h1 {
    font-size: 1.7rem;
  }

  .stage-banner {
    top: 122px;
    min-width: 126px;
    padding: 8px 14px;
    font-size: 0.92rem;
  }
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls {
    opacity: 0.4;
  }

  .touch-controls:hover {
    opacity: 1;
  }
}
