/* ═══════════════════════════════════════════════════════
   LIZARD RUN  —  style.css
   Palette: sun-scorched desert with cold-blooded green
   ═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Syne:wght@700;800&display=swap');

/* ── TOKENS ─────────────────────────────────────────── */
:root {
  --sand:        #e8d5a3;
  --sand-dark:   #c4a96a;
  --rock:        #2a2318;
  --rock-mid:    #3d3325; 
  --rock-light:  #5a4d38;
  --green:       #4ade80;
  --green-dim:   #22c55e;
  --sun:         #f59e0b;
  --danger:      #ef4444;
  --text-main:   #f0e6cc;
  --text-muted:  #a89060;
  --radius:      6px;
  --mono:        'Space Mono', monospace;
  --display:     'Syne', sans-serif;
}

/* ── RESET / BASE ───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: var(--rock);
  color: var(--text-main);
  font-family: var(--mono);
  overflow: hidden;
}

/* ── GAME WRAPPER ───────────────────────────────────── */
#game-wrapper {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* p5 canvas — fill the full viewport */
#game-wrapper > canvas,
#game-wrapper canvas:not(#preview-canvas) {
  position: absolute;
  top: 0; left: 0;
  width: 100% !important;
  height: 100% !important;
  z-index: 0;
}

/* ── SCREEN LAYER (start / gameover / store) ────────── */
#start-screen,
#gameover-screen,
#store-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 16px;
  background: rgba(20, 16, 10, 0.82);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.hidden { display: none !important; }

/* ── START CONTENT ──────────────────────────────────── */
#start-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 12px);
  overflow-y: auto;
  padding: 28px 28px 24px;
  background: var(--rock-mid);
  border: 1px solid var(--rock-light);
  border-radius: 12px;
  box-shadow: 0 0 60px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.04);
  scrollbar-width: none;
}
#start-content::-webkit-scrollbar { display: none; }

#logo-lizard {
  font-size: 3.2rem;
  line-height: 1;
  filter: drop-shadow(0 0 12px rgba(74,222,128,0.5));
  animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.06); }
}

#start-content h1 {
  font-family: var(--display);
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--sand);
  text-shadow: 0 0 24px rgba(245,158,11,0.35);
  line-height: 1;
  white-space: nowrap;
}

.subtitle {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--green);
  margin-top: -8px;
}

/* ── BUTTONS ────────────────────────────────────────── */
#start-buttons {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

button {
  font-family: var(--mono);
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
}

button:active { transform: scale(0.96); }

#start-btn {
  background: var(--green);
  color: var(--rock);
  font-size: 1rem;
  font-weight: 700;
  padding: 11px 36px;
  letter-spacing: 0.06em;
  box-shadow: 0 0 20px rgba(74,222,128,0.35);
}

#start-btn:hover {
  background: #6ee79a;
  box-shadow: 0 0 30px rgba(74,222,128,0.55);
}

#store-btn,
#multiplayer-btn {
  background: transparent;
  color: var(--sand);
  font-size: 0.85rem;
  padding: 11px 20px;
  border: 1px solid var(--rock-light);
}

#store-btn:hover,
#multiplayer-btn:hover {
  background: var(--rock-light);
  border-color: var(--sand-dark);
}

#multiplayer-btn {
  min-width: 140px;
}

#multiplayer-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 16px;
  background: rgba(20, 16, 10, 0.88);
  backdrop-filter: blur(4px);
}

#multiplayer-content {
  width: min(520px, calc(100vw - 32px));
  padding: 28px;
  background: var(--rock-mid);
  border: 1px solid var(--rock-light);
  border-radius: 14px;
  box-shadow: 0 0 60px rgba(0,0,0,0.5);
  display: grid;
  gap: 14px;
}

#multiplayer-content h2 {
  font-family: var(--display);
  font-size: 1.5rem;
  letter-spacing: 0.1em;
  color: var(--sand);
}

#mp-status {
  color: var(--text-main);
  font-size: 0.95rem;
}

#mp-server-row {
  display: grid;
  gap: 6px;
}

#mp-server-row label {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

#mp-server {
  width: 100%;
  background: var(--rock);
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
  color: var(--text-main);
  padding: 10px 12px;
}

#mp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#mp-actions button {
  flex: 1 1 140px;
  background: var(--green);
  color: var(--rock);
  font-weight: 700;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius);
}

#mp-actions button:hover {
  background: #6ee79a;
}

#mp-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#mp-log {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 120px;
  overflow-y: auto;
}

#mp-log-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

#mp-log-list div {
  font-size: 0.85rem;
  color: var(--text-main);
}

/* ── AUTH PANEL ─────────────────────────────────────── */
.auth-panel {
  width: 100%;
}

#auth-toggle-btns,
#auth-toggle-btns-go {
  display: flex;
  gap: 0;
  margin-bottom: 10px;
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
  overflow: hidden;
}

.auth-tab {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  padding: 7px 0;
  border-radius: 0;
  border: none;
}

.auth-tab.active {
  background: var(--rock-light);
  color: var(--sand);
}

.auth-tab:hover:not(.active) {
  background: rgba(255,255,255,0.04);
  color: var(--text-main);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.auth-form input {
  background: var(--rock);
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
  color: var(--text-main);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
}

.auth-form input:focus {
  border-color: var(--green-dim);
}

.auth-form input::placeholder {
  color: var(--text-muted);
}

.auth-submit {
  background: var(--rock-light);
  color: var(--sand);
  font-size: 0.8rem;
  padding: 9px;
  letter-spacing: 0.06em;
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius);
  margin-top: 2px;
}

.auth-submit:hover {
  background: var(--sand-dark);
  color: var(--rock);
}

.auth-error {
  font-size: 0.72rem;
  color: var(--danger);
  text-align: center;
  margin-top: 2px;
}

.auth-logged-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--rock);
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
}

.auth-greeting {
  font-size: 0.8rem;
  color: var(--sand);
}

.auth-username {
  color: var(--green);
  font-weight: 700;
}

.auth-logout-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 4px 10px;
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
}

.auth-logout-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* ── GAME OVER ──────────────────────────────────────── */
#gameover-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(420px, 92vw);
  padding: 36px 32px 32px;
  background: var(--rock-mid);
  border: 1px solid var(--rock-light);
  border-radius: 12px;
  box-shadow: 0 0 60px rgba(0,0,0,0.6);
}

#go-icon {
  font-size: 3rem;
  animation: shake 0.4s ease both;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px) rotate(-4deg); }
  40%      { transform: translateX(6px) rotate(4deg); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

#gameover-content h2 {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--danger);
}

#go-buttons {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

#restart-btn {
  background: var(--green);
  color: var(--rock);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 11px 32px;
  letter-spacing: 0.06em;
  box-shadow: 0 0 20px rgba(74,222,128,0.3);
}

#restart-btn:hover {
  background: #6ee79a;
}

/* ── STORE ──────────────────────────────────────────── */
#store-screen {
  align-items: stretch;
  padding: 0;
}

#store-layout {
  display: flex;
  width: 100%;
  height: 100%;
  background: var(--rock-mid);
  border: none;
  border-radius: 0;
  overflow: hidden;
}

/* left preview pane */
#store-preview {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 16px;
  background: var(--rock);
  border-right: 1px solid var(--rock-light);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rock-light) transparent;
}

#store-preview::-webkit-scrollbar { width: 4px; }
#store-preview::-webkit-scrollbar-track { background: transparent; }
#store-preview::-webkit-scrollbar-thumb { background: var(--rock-light); border-radius: 2px; }

#preview-canvas {
  border-radius: var(--radius);
  border: 1px solid var(--rock-light);
  background: #111;
  flex-shrink: 0;
}

#preview-name {
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--sand);
  letter-spacing: 0.06em;
}

#store-bal {
  font-size: 0.85rem;
  color: var(--green);
  letter-spacing: 0.05em;
}

#store-bal span { font-weight: 700; }

/* right grid pane */
#store-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#store-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--rock-light);
  flex-shrink: 0;
}

#store-header h2 {
  font-family: var(--display);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--sand);
}

#store-close {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 6px 12px;
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
}

#store-close:hover {
  color: var(--danger);
  border-color: var(--danger);
}

#store-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
  align-content: start;
}

#store-grid::-webkit-scrollbar { width: 4px; }
#store-grid::-webkit-scrollbar-track { background: transparent; }
#store-grid::-webkit-scrollbar-thumb { background: var(--rock-light); border-radius: 2px; }

/* individual store items — game's JS should add class .store-item */
.store-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  background: var(--rock);
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-align: center;
}

.store-item:hover,
.store-item.selected {
  border-color: var(--green-dim);
  background: rgba(74,222,128,0.06);
  color: var(--text-main);
}

.store-item.owned  { border-color: var(--sand-dark); color: var(--sand); }
.store-item canvas { image-rendering: pixelated; }

/* ── LEADERBOARD BUTTON (start screen) ──────────────── */
#leaderboard-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 8px 20px;
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
  letter-spacing: 0.06em;
  width: 100%;
}

#leaderboard-btn:hover {
  background: var(--rock-light);
  color: var(--sand);
}

/* ── LEADERBOARD OVERLAY ────────────────────────────── */
#leaderboard {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: min(380px, 88vw);
  background: var(--rock-mid);
  border: 1px solid var(--rock-light);
  border-radius: 12px;
  box-shadow: 0 0 60px rgba(0,0,0,0.7);
  overflow: hidden;
}

#leaderboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--rock-light);
  background: var(--rock);
}

#leaderboard-header h2,
#leaderboard h2 {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--sand);
  margin: 0;
}

#leaderboard-close,
#leaderboard .close-btn,
#leaderboard button[id*="close"],
#leaderboard > button:first-of-type {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 5px 10px;
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
}

#leaderboard-close:hover { color: var(--danger); border-color: var(--danger); }

#leaderboard-list,
#leaderboard ol,
#leaderboard ul {
  list-style: none;
  margin: 0;
  padding: 12px 0;
  max-height: 340px;
  overflow-y: auto;
}

#leaderboard-list::-webkit-scrollbar,
#leaderboard ol::-webkit-scrollbar { width: 4px; }
#leaderboard-list::-webkit-scrollbar-thumb,
#leaderboard ol::-webkit-scrollbar-thumb { background: var(--rock-light); border-radius: 2px; }

#leaderboard li,
#leaderboard .lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  font-size: 0.82rem;
  color: var(--text-main);
  border-bottom: 1px solid rgba(90,77,56,0.4);
  transition: background 0.1s;
}

#leaderboard li:last-child,
#leaderboard .lb-row:last-child { border-bottom: none; }
#leaderboard li:hover { background: rgba(255,255,255,0.03); }

/* rank number */
#leaderboard .lb-rank,
#leaderboard li .rank {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  width: 22px;
  text-align: right;
  flex-shrink: 0;
}

/* medal emoji or icon */
#leaderboard .lb-medal { font-size: 1rem; flex-shrink: 0; }

/* username */
#leaderboard .lb-name,
#leaderboard li .name {
  flex: 1;
  color: var(--sand);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* score */
#leaderboard .lb-score,
#leaderboard li .score {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--green);
  font-weight: 700;
  flex-shrink: 0;
}

/* top-3 highlight */
#leaderboard li:nth-child(1) .lb-name { color: #f59e0b; }
#leaderboard li:nth-child(2) .lb-name { color: var(--sand); }
#leaderboard li:nth-child(3) .lb-name { color: #c4a96a; }

/* leaderboard tabs */
#leaderboard-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--rock-light);
  background: var(--rock);
}

.lb-tab-btn {
  padding: 8px 16px;
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.lb-tab-btn:hover {
  color: var(--sand);
  border-color: var(--sand);
}

.lb-tab-btn.active {
  background: var(--sand);
  color: var(--rock);
  border-color: var(--sand);
}

/* multiplayer-specific stats */
#leaderboard .lb-mp .lb-stat {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--gold);
  flex-shrink: 0;
  min-width: 35px;
  text-align: right;
}

/* backdrop dim when leaderboard is open */
#leaderboard-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20,16,10,0.6);
  z-index: 19;
}

/* ── IN-GAME HUD (if JS injects HTML elements) ──────── */
#hud {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  gap: 20px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--sand);
  pointer-events: none;
}

/* ── START SCREEN EXTRAS ────────────────────────────── */
.start-instructions {
  display: flex;
  gap: 16px;
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  flex-wrap: wrap;
  justify-content: center;
}

.start-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

.green-zone { color: var(--green); font-style: normal; }

.scales-display {
  font-size: 0.9rem;
  color: var(--green);
  letter-spacing: 0.06em;
}

/* ── STORE TABS ─────────────────────────────────────── */
.store-tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.tab-btn.active {
  background: var(--rock-light);
  color: var(--sand);
  border-color: var(--rock-light);
}

.tab-btn:hover:not(.active) {
  color: var(--text-main);
  background: rgba(255,255,255,0.04);
}

/* ── STORE CARDS ────────────────────────────────────── */
.store-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 12px 8px 10px;
  background: var(--rock);
  border: 1px solid var(--rock-light);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
  position: relative;
}

.store-card:hover   { border-color: var(--sand-dark); background: rgba(255,255,255,0.03); }
.store-card.equipped { border-color: var(--green-dim); background: rgba(74,222,128,0.06); }
.store-card.selected { border-color: var(--sand); }

.card-icon { font-size: 1.4rem; line-height: 1; }
.card-name { font-size: 0.65rem; color: var(--text-muted); letter-spacing: 0.05em; }
.card-price { font-size: 0.62rem; color: var(--sun); }

.card-badge {
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
}

.card-badge.equipped-badge { background: rgba(74,222,128,0.15); color: var(--green); }
.card-badge.owned          { background: rgba(196,169,106,0.15); color: var(--sand-dark); }

.store-action {
  width: calc(100% - 32px);
  margin: 0 16px;
  padding: 10px;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  border-radius: var(--radius);
  background: var(--green);
  color: var(--rock);
  font-weight: 700;
  border: none;
  flex-shrink: 0;
}

.store-action:disabled {
  background: var(--rock-light);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ── GAME OVER STATS ────────────────────────────────── */
.go-stats {
  display: flex;
  gap: 20px;
  margin: 4px 0;
}

.go-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.go-stat-label {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.go-stat-val {
  font-size: 1rem;
  font-weight: 700;
  color: var(--sand);
}

.go-stat-val.green { color: var(--green); }
.go-stat-val.amber { color: var(--sun); }

#go-reason {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: -8px;
}

#go-lb-msg {
  font-size: 0.75rem;
  color: var(--green);
  text-align: center;
}

#go-store-btn {
  background: transparent;
  color: var(--sand);
  font-size: 0.85rem;
  padding: 11px 20px;
  border: 1px solid var(--rock-light);
}

#go-store-btn:hover {
  background: var(--rock-light);
}