:root {
  --bg: #f8efe0;
  --panel: #fff8ec;
  --ink: #3b2b1f;
  --accent: #c8793d;
  --accent-dark: #8d4d24;
  --green: #73a65b;
  --green-dark: #456c37;
  --canvas-bg: #f4d9b8;
  --danger: #8d3230;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

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

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, #fff7e9 0 18%, transparent 38%),
    radial-gradient(circle at 90% 20%, #dceec8 0 14%, transparent 32%),
    linear-gradient(180deg, #fff4e1 0%, var(--bg) 48%, #dec29d 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  display: grid;
  place-items: start center;
  padding: 7px;
  overflow-x: hidden;
}

.game-shell {
  width: min(100%, 398px);
}

.game-header,
.controls,
.menu-card,
.drawer-panel,
.modal-box {
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: 0 6px 0 rgba(59, 43, 31, 0.18);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 20px;
  padding: 8px 10px;
  margin-bottom: 7px;
}

.header-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.local-best-pill {
  min-width: 86px;
  padding: 6px 10px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
  text-align: center;
  box-shadow: 0 4px 0 rgba(59, 43, 31, 0.18);
}

.local-best-pill span,
.local-best-pill strong {
  display: block;
  line-height: 1.05;
}

.local-best-pill strong {
  margin-top: 2px;
  font-size: 0.98rem;
}

.install-counter-line {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  line-height: 1;
  font-size: 0.74rem;
  font-weight: 900;
}

.install-counter-line strong {
  font-size: 0.86rem;
}

.install-arrow {
  font-weight: 950;
  transform: translateY(-1px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.3rem;
  line-height: 1;
}

.game-header p,
.install-counter-line,
.hint,
.menu-note,
.menu-title small,
.mode-option small,
.local-best-pill span {
  font-size: 0.76rem;
  opacity: 0.82;
  font-weight: 750;
}

button,
select {
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 10px 8px;
  background: var(--accent);
  color: white;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--accent-dark);
  touch-action: manipulation;
  font-family: inherit;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--accent-dark);
}

select {
  background: #fff;
  color: var(--ink);
  box-shadow: none;
  padding: 8px 10px;
}

.trophy-button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 999px;
  font-size: 1.35rem;
  background: #ffcf57;
  box-shadow: 0 5px 0 #b77722;
}

.game-stage {
  position: relative;
}

canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 360 / 540;
  display: block;
  background: var(--canvas-bg);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 6px 0 rgba(59, 43, 31, 0.2);
  image-rendering: auto;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 4;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 78px;
  justify-content: center;
  padding: 7px 10px;
  background: rgba(255, 248, 236, 0.92);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(59, 43, 31, 0.2);
  backdrop-filter: blur(3px);
}

.score-hud {
  left: 12px;
}

.lives-hud {
  right: 12px;
}

.hud strong {
  font-size: 1rem;
}

.floating-menu {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(59, 43, 31, 0.48);
  border-radius: 22px;
}

.hidden {
  display: none !important;
}

.menu-card {
  width: min(100%, 326px);
  border-radius: 26px;
  padding: 15px;
}

.compact-card {
  width: min(100%, 292px);
}

.menu-title {
  display: grid;
  gap: 3px;
  text-align: center;
  margin-bottom: 12px;
}

.menu-title strong {
  font-size: 1.45rem;
  line-height: 1;
}

.primary-action {
  width: 100%;
  background: var(--green);
  box-shadow: 0 5px 0 var(--green-dark);
  font-size: 1rem;
}

.mode-instruction {
  text-align: center;
  margin-top: 8px;
  font-size: 0.78rem;
  font-weight: 900;
  opacity: 0.82;
}

.mode-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.mode-option {
  display: grid;
  gap: 2px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(59, 43, 31, 0.26);
  padding: 9px 6px;
}

.mode-option.active {
  background: #e4f2d6;
  outline: 4px solid rgba(115, 166, 91, 0.32);
}

.menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.secondary-action {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 5px 0 rgba(59, 43, 31, 0.25);
}

.install-action,
.share-action,
.coffee-action {
  width: 100%;
  margin-top: 10px;
}

.install-action {
  background: #ffcf57;
  color: var(--ink);
  box-shadow: 0 5px 0 #b77722;
}

.share-action {
  background: #dceec8;
  color: var(--ink);
  box-shadow: 0 5px 0 #8aa86d;
}

#gameOverMenu .install-action {
  margin-top: 10px;
}

.coffee-action {
  width: 100%;
  margin-top: 10px;
  background: #f4dfc1;
  color: var(--ink);
  box-shadow: 0 5px 0 #b6854a;
}

.utility-actions {
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
}

.inline-coffee {
  margin-top: 0;
}

.menu-note {
  text-align: center;
  margin-top: 10px;
}


.controls {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  gap: 8px;
  border-radius: 18px;
  padding: 8px;
  margin-top: 8px;
}

.hint {
  text-align: center;
  margin: 7px 3px 0;
  line-height: 1.25;
}

.drawer,
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(59, 43, 31, 0.62);
}

.drawer-panel {
  width: min(100%, 430px);
  max-height: min(90vh, 720px);
  overflow: auto;
  border-radius: 26px;
  padding: 14px;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.leaderboard-header h2 {
  font-size: 1.2rem;
}

.icon-close {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 999px;
  font-size: 1.5rem;
  line-height: 1;
}

.leaderboard-actions {
  display: grid;
  grid-template-columns: 1fr 116px;
  gap: 8px;
  margin: 12px 0;
}

.podium {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 8px;
  align-items: end;
  margin: 12px 0 10px;
}

.podium-item {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 7px 4px;
  text-align: center;
  min-height: 78px;
  display: grid;
  align-content: center;
  gap: 4px;
}

.podium-item.first {
  min-height: 98px;
  background: #fff2bd;
}

.podium-item.second {
  background: #f1f1f1;
}

.podium-item.third {
  background: #f2cfad;
}

.medal {
  font-size: 1.7rem;
}

.podium-item strong {
  font-size: 0.88rem;
  word-break: break-word;
}

.podium-item small {
  font-weight: 900;
}

.leaderboard-list {
  max-height: 260px;
  overflow: auto;
  display: grid;
  gap: 7px;
  padding-right: 4px;
}

.rank-row {
  display: grid;
  grid-template-columns: 42px 1fr 80px;
  gap: 8px;
  align-items: center;
  background: #fff;
  border: 2px solid rgba(59, 43, 31, 0.45);
  border-radius: 14px;
  padding: 8px 10px;
  font-size: 0.92rem;
}

.rank-position,
.rank-score {
  font-weight: 950;
}

.rank-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-score {
  text-align: right;
}

.empty-ranking {
  text-align: center;
  padding: 18px 0;
  opacity: 0.75;
}

.modal-box {
  width: min(100%, 420px);
  border-radius: 26px;
  padding: 20px;
}

.modal-box label {
  display: block;
  margin-top: 14px;
  font-weight: 850;
}

.modal-box input {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  font-size: 1rem;
  background: white;
  user-select: text;
  -webkit-user-select: text;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
  margin-top: 14px;
}

.modal-message {
  min-height: 22px;
  font-weight: 800;
  margin-top: 8px;
}

@media (max-width: 480px) {
  body {
    padding: 6px;
  }

  .game-header,
  .controls,
  .menu-card,
  .drawer-panel,
  .modal-box {
    border-width: 2px;
  }

  h1 {
    font-size: 1.08rem;
  }

  .install-counter-line {
    font-size: 0.66rem;
  }

  .install-counter-line strong {
    font-size: 0.78rem;
  }

  button,
  select {
    border-width: 2px;
    border-radius: 13px;
    padding: 8px 6px;
    font-size: 0.8rem;
  }

  .local-best-pill {
    min-width: 74px;
    padding: 5px 8px;
    border-width: 2px;
  }

  .local-best-pill strong {
    font-size: 0.84rem;
  }

  .trophy-button {
    width: 42px;
    height: 42px;
    font-size: 1.15rem;
  }

  .hud {
    border-width: 2px;
    top: 9px;
    min-width: 64px;
    padding: 6px 8px;
  }

  .score-hud {
    left: 9px;
  }

  .lives-hud {
    right: 9px;
  }


  .controls {
    grid-template-columns: 68px 1fr 68px;
  }
}

