:root {
  --text: #f8e8c5;
  --muted: #d8b98b;
  --ink: #2a170e;
  --warm-1: rgba(62, 33, 18, 0.9);
  --warm-2: rgba(37, 20, 12, 0.94);
  --wood-line: rgba(255, 199, 129, 0.3);
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at top, #5d321b 0%, #1a0f08 58%);
  color: var(--text);
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
}

body {
  overflow: hidden;
  touch-action: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#stage-wrap,
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  touch-action: none;
}

.btn {
  border: 1px solid rgba(255, 202, 136, 0.24);
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease, filter 120ms ease;
  color: #f8e8c5;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #f6f6f6, #bcbcbc 58%, #8b8b8b);
  color: #21140d;
  border-color: rgba(255, 255, 255, 0.42);
}

.btn-secondary {
  background: linear-gradient(180deg, rgba(92, 92, 92, 0.94), rgba(40, 40, 40, 0.96));
}

.btn-ghost {
  background: linear-gradient(180deg, rgba(111, 60, 32, 0.92), rgba(58, 31, 18, 0.95));
  color: #ffdca0;
}

.hud-minimal {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 68px);
  right: 10px;
  z-index: 40;
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--wood-line);
  background: linear-gradient(180deg, var(--warm-1), var(--warm-2));
  box-shadow: var(--shadow);
}

.hud-btn {
  min-height: 42px;
  padding: 8px 14px;
  font-size: 22px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(180deg, rgba(10, 6, 4, 0.46), rgba(10, 6, 4, 0.68));
  z-index: 30;
}

.overlay-visible {
  display: flex;
}

.overlay-card {
  border-radius: 18px;
  border: 1px solid rgba(255, 201, 131, 0.28);
  background: linear-gradient(180deg, rgba(52, 29, 18, 0.9), rgba(28, 16, 11, 0.94));
  box-shadow: var(--shadow);
  text-align: center;
}

.gate-card,
.pause-card,
.gameover-card,
.menu-card {
  width: min(760px, calc(100vw - 24px));
  padding: clamp(18px, 2.8vw, 28px);
}

.gate-card,
.pause-card,
.gameover-card {
  display: grid;
  gap: 12px;
}

.menu-card {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
}

.gate-card h2,
.pause-card h2,
.gameover-card h2,
.menu-card h2 {
  margin: 0;
  font-size: clamp(44px, 6vw, 66px);
  color: #ffe4b5;
}

.gate-card p,
.menu-subtitle {
  margin: 0;
  font-size: clamp(20px, 2.2vw, 30px);
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
  text-align: left;
}

.field span {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #f0c986;
}

.field input {
  min-height: 46px;
  border: 1px solid rgba(255, 197, 120, 0.2);
  border-radius: 10px;
  background: rgba(24, 13, 9, 0.85);
  color: var(--text);
  padding: 8px 12px;
  font-size: 24px;
}

.main-btn {
  min-height: 52px;
  padding: 12px 18px;
  font-size: 30px;
}

.profile-hint {
  margin: 4px 0;
  min-height: 20px;
  color: var(--muted);
  font-size: 16px;
}

.profile-hint.error {
  color: #ff9b90;
}

.menu-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.menu-actions.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.menu-actions .btn,
.menu-links .btn {
  min-height: 42px;
  font-size: 21px;
}

.menu-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.gameover-card p {
  margin: 0;
  font-size: 38px;
}

.gameover-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.leaderboard-panel {
  border-radius: 12px;
  border: 1px solid rgba(255, 199, 127, 0.2);
  background: rgba(25, 14, 10, 0.72);
  padding: 10px;
  display: grid;
  gap: 8px;
  text-align: left;
}

.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.leaderboard-head h3 {
  margin: 0;
  font-size: 24px;
  color: #f0c986;
  text-transform: uppercase;
}

.leaderboard-tabs {
  display: inline-flex;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(38, 20, 12, 0.8);
}

.lb-tab {
  border: 0;
  background: transparent;
  color: #f2ce92;
  font-size: 16px;
  font-weight: 700;
  padding: 7px 12px;
  cursor: pointer;
}

.lb-tab.is-active {
  background: rgba(255, 204, 126, 0.92);
  color: #2a170f;
}

.leaderboard-status,
.leaderboard-empty {
  margin: 0;
  font-size: 16px;
  color: var(--muted);
}

.leaderboard-status.error {
  color: #ff9b90;
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 8px;
  align-items: center;
  border-radius: 10px;
  border: 1px solid rgba(255, 205, 140, 0.2);
  background:
    linear-gradient(180deg, rgba(5, 10, 18, 0.82), rgba(5, 10, 18, 0.9)),
    url("./assets/images/game_bg.png") center / cover no-repeat;
  padding: 8px 10px;
}

.leaderboard-row.me {
  box-shadow: inset 0 0 0 2px rgba(255, 205, 140, 0.42);
  background:
    linear-gradient(180deg, rgba(117, 72, 36, 0.62), rgba(33, 20, 12, 0.84)),
    url("./assets/images/game_bg.png") center / cover no-repeat;
}

.leaderboard-rank {
  font-weight: 800;
  color: #ffe4b8;
  font-size: 22px;
}

.leaderboard-name {
  display: grid;
  line-height: 1.15;
}

.leaderboard-name strong {
  color: #fff2d9;
  font-size: 22px;
}

.leaderboard-wallet {
  color: #e1c391;
  font-size: 15px;
}

.leaderboard-score {
  color: #ffe4b5;
  font-size: 26px;
  font-weight: 800;
}

.leaderboard-me {
  min-height: 28px;
}

@media (max-width: 880px) {
  .menu-actions,
  .menu-links {
    grid-template-columns: 1fr;
  }

  .menu-actions.compact {
    grid-template-columns: 1fr;
  }

  .hud-btn {
    min-height: 38px;
    font-size: 18px;
  }

  .main-btn {
    min-width: 220px;
    font-size: 24px;
  }

  .gate-card h2,
  .pause-card h2,
  .gameover-card h2,
  .menu-card h2 {
    font-size: clamp(38px, 10vw, 56px);
  }
}
