:root {
  --bg-1: #fff8ef;
  --bg-2: #ffd7a8;
  --ink: #2b1c0f;
  --accent: #f08c2b;
  --panel: #ffffffcc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, var(--bg-1), var(--bg-2));
  display: grid;
  place-items: center;
}

.app {
  width: min(100%, 1020px);
  padding: 1rem;
}

h1 {
  margin: 0 0 0.4rem;
  letter-spacing: 0.04em;
}

.subtitle {
  margin: 0 0 0.75rem;
}

canvas {
  width: 100%;
  height: auto;
  border: 3px solid #8f5627;
  border-radius: 12px;
  background: linear-gradient(#9fd4ff, #f7f2db 75%);
  display: block;
}

.touch-controls {
  margin-top: 0.65rem;
  display: none;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 0.55rem;
}

.touch-items {
  margin-top: 0.5rem;
  display: none;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 0.55rem;
}

.touch-btn {
  border: 2px solid #8f5627;
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  min-height: 48px;
  font: 700 0.98rem "Trebuchet MS", "Verdana", sans-serif;
  color: #3a220f;
  background: #fff5e6;
  touch-action: manipulation;
}

.touch-btn:active,
.touch-btn.is-active {
  transform: translateY(1px);
  background: #ffe3bd;
}

.touch-btn-jump {
  background: #ffd9b0;
}

.touch-btn-item {
  background: #ffefdb;
  font-size: 0.88rem;
}

.hud {
  margin-top: 0.55rem;
  background: var(--panel);
  border: 2px solid #8f5627;
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-weight: 700;
  align-items: center;
}

.stamina {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stamina-bar {
  width: 140px;
  height: 12px;
  border: 2px solid #7d5a3b;
  border-radius: 999px;
  background: #f0e6d9;
  overflow: hidden;
}

.stamina-fill {
  height: 100%;
  background: linear-gradient(90deg, #66c48a, #2f9b5a);
  transition: width 120ms linear;
}

.coins {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.coin-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #a96a15;
  background: radial-gradient(circle at 30% 30%, #ffe49f, #f2b13c);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
}

.inventory {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.pill {
  width: 18px;
  height: 10px;
  border-radius: 999px;
  border: 2px solid #7b4a2c;
  background: linear-gradient(90deg, #ffffff 0 50%, #f2a6a6 50% 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.pill-speed {
  background: linear-gradient(90deg, #ffffff 0 50%, #9fd0ff 50% 100%);
}

.pill-nostamina {
  background: linear-gradient(90deg, #ffffff 0 50%, #b9a6ff 50% 100%);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 18, 9, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.overlay.is-hidden {
  display: none;
}

.menu-card {
  width: min(92vw, 460px);
  background: #fff7ea;
  border: 3px solid #8f5627;
  border-radius: 18px;
  padding: 1rem 1.2rem 1.2rem;
  box-shadow: 0 14px 30px rgba(44, 24, 8, 0.35);
  text-align: center;
}

.menu-panel {
  display: grid;
  gap: 0.6rem;
}

.menu-panel h3 {
  margin: 0.6rem 0 0.2rem;
}

.menu-panel p {
  margin: 0;
  font-weight: 600;
}

.menu-panel.is-hidden {
  display: none;
}

.menu-btn {
  border: 2px solid #8f5627;
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font: 700 1rem "Trebuchet MS", "Verdana", sans-serif;
  color: #3a220f;
  background: #ffe9c9;
  cursor: pointer;
}

.menu-btn-small {
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
}

.menu-btn:hover {
  background: #ffd9a8;
}

.game-menu {
  margin-top: 0.6rem;
  display: none;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.shop-card {
  width: min(92vw, 420px);
  background: #fff7ea;
  border: 3px solid #8f5627;
  border-radius: 18px;
  padding: 1rem 1.2rem 1.2rem;
  box-shadow: 0 14px 30px rgba(44, 24, 8, 0.35);
  text-align: center;
}

.shop-card h2 {
  margin: 0 0 0.35rem;
}

.shop-coins {
  margin: 0.1rem 0 0.5rem;
  font-weight: 700;
}

.shop-message {
  min-height: 1.2rem;
  margin: 0 0 0.7rem;
  color: #7b3c15;
}

.shop-items {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.shop-btn,
.shop-next {
  border: 2px solid #8f5627;
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font: 700 0.98rem "Trebuchet MS", "Verdana", sans-serif;
  color: #3a220f;
  background: #ffe9c9;
  cursor: pointer;
}

.shop-btn:hover,
.shop-next:hover {
  background: #ffd9a8;
}

.shop-next {
  width: 100%;
  background: #ffd1a1;
}

@media (max-width: 720px) {
  body {
    align-items: start;
  }

  .app {
    padding: 0.75rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 0.95rem;
  }

  .touch-controls {
    display: none;
  }

  .touch-items {
    display: none;
  }

  .hud {
    font-size: 0.9rem;
    gap: 0.5rem;
  }

  .stamina-bar {
    width: 110px;
  }

  .shop-card {
    width: min(92vw, 360px);
  }

  .menu-card {
    width: min(92vw, 360px);
  }
}

body[data-screen="game"] .touch-controls,
body[data-screen="game"] .touch-items {
  display: grid;
}

body[data-screen="game"] .game-menu {
  display: flex;
}
