:root {
  --bg: #0a0e0c;
  --panel: #161c22;
  --accent: #4ade80;
  --accent-dark: #22c55e;
  --gold: #facc15;
  --gold-dark: #eab308;
  --wood: #8b5e34;
  --wood-dark: #5d4037;
  --text: #e7f1e8;
  --muted: #8a9a93;
  --grass: #2e7d32;
  --water: #1565c0;
  --rock: #5d4037;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: linear-gradient(180deg, #1a2118 0%, var(--panel) 100%);
  border-bottom: 2px solid var(--gold);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: 0.5px;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  font-size: 1.4rem;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #1f2a1c, #0a0e0c);
  border: 2px solid var(--gold);
  box-shadow: inset 0 0 0 2px rgba(74, 222, 128, 0.35), 0 0 10px rgba(250, 204, 21, 0.35);
}

.brand-name {
  color: var(--gold);
  text-shadow: 0 1px 6px rgba(250, 204, 21, 0.25);
}

.nav {
  display: flex;
  gap: 18px;
}

.nav a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  padding: 6px 4px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.nav a:hover,
.nav a.active {
  color: var(--text);
  border-bottom-color: var(--gold);
}

.social-link {
  display: inline-flex;
  align-items: center;
  border-bottom-color: transparent !important;
}

.social-link:hover {
  color: var(--gold) !important;
}

.balance-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: rgba(250, 204, 21, 0.08);
  border: 1px solid rgba(250, 204, 21, 0.25);
  border-radius: 10px;
  padding: 6px 14px;
  min-width: 140px;
}

.balance-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

#balance, #farmBalance {
  font-weight: 700;
  color: var(--gold);
}

main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.hero {
  text-align: center;
  margin-bottom: 24px;
  padding: 32px 16px;
  border-radius: 12px;
  border: 1px solid rgba(250, 204, 21, 0.15);
  background:
    radial-gradient(1.5px 1.5px at 12% 22%, rgba(255,255,255,0.55) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 78% 14%, rgba(255,255,255,0.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 28%, rgba(255,255,255,0.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 35% 12%, rgba(255,255,255,0.4) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 92% 38%, rgba(255,255,255,0.3) 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 45%, rgba(255,255,255,0.3) 50%, transparent 51%),
    linear-gradient(180deg, #0a0e14 0%, #0c1410 55%, #16331c 100%);
}

.hero h1 {
  font-size: 1.9rem;
  margin: 0 0 8px;
  color: var(--gold);
  text-shadow: 0 2px 10px rgba(250, 204, 21, 0.25);
}

.hero p {
  color: var(--muted);
  max-width: 640px;
  margin: 0 auto;
  line-height: 1.5;
}

.hero p a {
  color: var(--gold);
}

.game-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#game {
  background: var(--panel);
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  max-width: 100%;
}

.hud {
  width: 100%;
  max-width: 800px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.06);
  border-top: 3px solid var(--gold);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.9rem;
  color: var(--muted);
}

.hud-row {
  margin: 4px 0;
}

.hud-row strong {
  color: var(--text);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 8px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.dot.grass { background: var(--grass); }
.dot.water { background: var(--water); }
.dot.rock { background: var(--rock); }

.rarity-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.online-pill #onlineCount {
  color: var(--accent);
}

#levelDisplay {
  font-weight: 700;
  color: var(--accent);
}

.canvas-frame {
  position: relative;
  max-width: 100%;
}

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(1.5px 1.5px at 12% 22%, rgba(255,255,255,0.55) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 78% 14%, rgba(255,255,255,0.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 28%, rgba(255,255,255,0.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 35% 12%, rgba(255,255,255,0.4) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 92% 38%, rgba(255,255,255,0.3) 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 45%, rgba(255,255,255,0.3) 50%, transparent 51%),
    linear-gradient(180deg, #0a0e14 0%, #0c1410 55%, #16331c 100%);
}

.start-screen.hidden {
  display: none;
}

.start-screen-card {
  max-width: 480px;
  padding: 32px 24px;
}

.start-logo {
  font-size: 4rem;
  margin-bottom: 8px;
}

.start-screen-card h1 {
  font-size: 3rem;
  margin: 0 0 12px;
  color: var(--gold);
  letter-spacing: 3px;
  text-shadow: 0 2px 10px rgba(250, 204, 21, 0.25);
}

.start-screen-card p {
  color: var(--muted);
  line-height: 1.5;
  margin: 0 auto 24px;
}

.start-btn {
  font-size: 1.1rem;
  padding: 14px 40px;
  cursor: pointer;
  border: none;
}

.start-stats {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--muted);
}

.start-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  box-shadow: 0 0 6px var(--accent);
}

.wallet-gate {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 16, 0.82);
  border-radius: 8px;
  backdrop-filter: blur(2px);
}

.wallet-gate.hidden {
  display: none;
}

.wallet-gate-card {
  text-align: center;
  max-width: 320px;
  padding: 24px;
}

.wallet-gate-card h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.wallet-gate-card p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.wallet-gate-card .note {
  min-height: 1.2em;
}

.wallet-gate-card input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  text-align: center;
}

#usernamePill {
  cursor: pointer;
}

#usernamePill:hover {
  border-color: rgba(250, 204, 21, 0.5);
}

#usernameDisplay {
  font-weight: 700;
  color: var(--accent);
}

.player-emoji {
  font-size: 1.1rem;
}

.leaderboard {
  width: 100%;
  max-width: 800px;
  margin: 24px auto 0;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.06);
  border-top: 3px solid var(--gold);
  border-radius: 8px;
  padding: 16px 20px;
}

.leaderboard h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: var(--gold);
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  background: rgba(255,255,255,0.03);
  font-size: 0.9rem;
}

.leaderboard-list li.self {
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.3);
}

.leaderboard-list .rank {
  color: var(--muted);
  font-weight: 700;
  width: 28px;
}

.leaderboard-list .wallet {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
}

.leaderboard-list .level {
  color: var(--gold);
  font-weight: 700;
}

.leaderboard-list .xp {
  color: var(--muted);
  font-size: 0.8rem;
  min-width: 80px;
  text-align: right;
}

.leaderboard-empty {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 12px;
}

footer {
  text-align: center;
  padding: 16px;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* Swap page */
.swap-card {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.06);
  border-top: 3px solid var(--gold);
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}

.swap-card h2 {
  margin-top: 0;
  color: var(--gold);
}

.wallet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.wallet-info {
  color: var(--muted);
  font-size: 0.85rem;
}

button {
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: filter 0.15s;
}

button:hover {
  filter: brightness(1.1);
}

.btn-primary {
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dark) 100%);
  color: #2b1d05;
  padding: 10px 18px;
  box-shadow: 0 2px 8px rgba(250, 204, 21, 0.25);
}

.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  padding: 10px 18px;
}

.balance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.balance-box {
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.balance-box .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.balance-box .value {
  font-size: 1.2rem;
  font-weight: 700;
}

.swap-form .field {
  margin-bottom: 12px;
}

.swap-form label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.swap-form input, .swap-form select {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}

.swap-arrow {
  text-align: center;
  color: var(--muted);
  margin: -4px 0 8px;
}

.swap-form button {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  margin-top: 4px;
}

.note {
  margin-top: 16px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}
