:root {
  color-scheme: light;
  font-family: "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  --ink: #263047;
  --clay: #9b6d52;
  --stone: #d4b394;
  --sun: #ffd66d;
  --leaf: #54bd7a;
  --sky: #85daf7;
  --rose: #ff6f86;
  --blue: #4178d5;
  --shadow: rgba(38, 48, 71, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 214, 109, 0.85) 0 18%, transparent 18%),
    linear-gradient(180deg, #85daf7 0%, #c9f3ff 52%, #8ed785 100%);
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100vw, 1360px);
  height: 100svh;
  margin: 0 auto;
  padding: clamp(9px, 2vw, 20px);
  gap: clamp(9px, 1.6vw, 16px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #8b4e2f;
  font-size: clamp(0.78rem, 1.6vw, 0.92rem);
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #263047;
  font-size: clamp(1.55rem, 4.2vw, 3.45rem);
  line-height: 0.96;
  letter-spacing: 0;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.58);
}

.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 50vw;
}

.hud-tile {
  min-width: 86px;
  padding: 8px 10px;
  border: 3px solid rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 8px 18px var(--shadow);
  text-align: center;
}

.hud-tile span,
.hud-tile strong {
  display: block;
}

.hud-tile span {
  font-size: clamp(0.7rem, 1.4vw, 0.82rem);
  font-weight: 900;
  text-transform: uppercase;
  color: #76503a;
}

.hud-tile strong {
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  line-height: 1;
}

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 4px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  background: #c59a77;
  box-shadow: 0 16px 34px var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 286px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(66, 79, 94, 0.16);
  backdrop-filter: blur(2px);
}

.overlay.hidden {
  display: none;
}

.overlay-panel {
  width: min(520px, 92vw);
  padding: clamp(20px, 4vw, 32px);
  border: 4px solid rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 20px 40px rgba(38, 48, 71, 0.28);
  text-align: center;
}

.badge {
  display: inline-block;
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #ffe68e;
  color: #77502b;
  font-weight: 950;
}

h2 {
  margin: 0;
  color: #263047;
  font-size: clamp(1.7rem, 6vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

.overlay-panel p:last-of-type {
  max-width: 29rem;
  margin: 12px auto 18px;
  color: #584439;
  font-size: clamp(1rem, 2.8vw, 1.2rem);
  font-weight: 850;
}

.primary,
.control-btn {
  min-height: 58px;
  border-radius: 8px;
  color: #fff;
  font-weight: 1000;
  box-shadow: 0 8px 0 #60412f, 0 14px 22px var(--shadow);
}

.primary {
  padding: 0 24px;
  background: linear-gradient(180deg, #54bd7a, #278c58);
  font-size: clamp(1.05rem, 3vw, 1.38rem);
}

.controls {
  display: grid;
  grid-template-columns: minmax(88px, 160px) minmax(132px, 220px) minmax(88px, 160px);
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-height: 76px;
}

.control-btn {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: linear-gradient(180deg, #4d91f0, #2e57ba);
  box-shadow: 0 8px 0 #233c87, 0 14px 22px var(--shadow);
  font-size: clamp(0.92rem, 2.2vw, 1.08rem);
}

.control-btn.restart {
  background: linear-gradient(180deg, #ff8c58, #db5142);
  box-shadow: 0 8px 0 #8f3028, 0 14px 22px var(--shadow);
}

.control-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.24);
  font-size: 1.3rem;
  line-height: 1;
}

.primary:active,
.control-btn:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #60412f, 0 8px 14px var(--shadow);
}

.control-btn.restart:active {
  box-shadow: 0 3px 0 #8f3028, 0 8px 14px var(--shadow);
}

@media (max-width: 700px) {
  body {
    overflow: auto;
  }

  .game-shell {
    padding: 8px;
  }

  .topbar {
    align-items: flex-start;
  }

  .hud {
    max-width: none;
  }

  .hud-tile {
    min-width: 74px;
    padding: 7px 8px;
  }

  .controls {
    grid-template-columns: 1fr 1.3fr 1fr;
    gap: 8px;
  }

  .control-btn {
    grid-template-columns: 1fr;
    gap: 2px;
    min-height: 64px;
    padding: 6px;
  }

  .control-icon {
    width: 32px;
    height: 28px;
    margin: 0 auto;
  }
}
