:root {
  --stone-900: #23262b;
  --stone-800: #2f333a;
  --stone-700: #3c414a;
  --stone-600: #4d5561;
  --stone-500: #6b7480;
  --chalk-100: #f6f4ee;
  --chalk-200: #e9e5d8;
  --rope-500: #c19a6b;
  --rope-600: #a87d4d;
  --sky-500: #4a90d9;
  --sky-600: #3a75b3;
  --rock-orange: #e07a3f;
  --rock-orange-dark: #c15f28;
  --success: #4caf7d;
  --danger: #c0453a;
  --radius: 10px;
  --shadow: 0 2px 6px rgba(0,0,0,0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--chalk-100);
  background: linear-gradient(180deg, #274b6e 0%, #3a678f 18%, #5b7c8d 38%, #6d716a 58%, #4a4640 78%, #2f2c28 100%);
  background-attachment: fixed;
}

h1, h2, h3 { margin: 0 0 4px 0; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: rgba(20, 22, 26, 0.55);
  border-bottom: 2px solid var(--rope-600);
  backdrop-filter: blur(4px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon { font-size: 2rem; }
.brand h1 { font-size: 1.4rem; letter-spacing: 0.5px; }
.tagline { margin: 0; font-size: 0.75rem; color: var(--chalk-200); opacity: 0.8; }

.stats {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  margin-left: auto;
}
.stat { display: flex; flex-direction: column; min-width: 110px; }
.stat-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.7; }
.stat-value { font-size: 1.15rem; font-weight: 700; color: var(--chalk-100); }
#stat-badges-wrap #stat-badges { color: var(--rock-orange); }

.topbar-actions { display: flex; gap: 8px; }
.btn-small {
  background: var(--stone-700);
  color: var(--chalk-100);
  padding: 8px 12px;
  font-size: 0.8rem;
  box-shadow: var(--shadow);
}
.btn-small:hover { background: var(--stone-600); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #a8382e; }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1fr 1fr;
  gap: 16px;
  padding: 20px;
  max-width: 1700px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 1650px) {
  .layout { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: rgba(20, 22, 26, 0.55);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

/* ---------- Climb panel ---------- */

.climb-button {
  width: 100%;
  padding: 28px 12px;
  margin: 10px 0 4px 0;
  background: radial-gradient(circle at 30% 20%, var(--rock-orange) 0%, var(--rock-orange-dark) 70%);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 4px 0 #8a4a1f, var(--shadow);
  transition: transform 0.05s ease;
  user-select: none;
}
.climb-button:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #8a4a1f, var(--shadow);
}
.climb-icon { font-size: 2.2rem; }
.click-power {
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.8;
  margin: 0 0 14px 0;
}

.prestige-box {
  background: rgba(224, 122, 63, 0.12);
  border: 1px solid rgba(224, 122, 63, 0.4);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}
.prestige-desc { font-size: 0.78rem; opacity: 0.85; margin: 4px 0 8px 0; }
.prestige-preview { font-size: 0.85rem; margin: 0 0 8px 0; }
#prestige-preview { font-weight: 700; color: var(--rock-orange); }
.btn-prestige {
  width: 100%;
  padding: 10px;
  background: var(--rock-orange);
  color: #fff;
  font-weight: 700;
}
.btn-prestige:disabled {
  background: var(--stone-600);
  color: var(--chalk-200);
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-prestige:not(:disabled):hover { background: var(--rock-orange-dark); }

.log-box h3 { font-size: 0.9rem; }
.log-feed {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  padding-right: 4px;
}
.log-entry {
  font-size: 0.78rem;
  line-height: 1.35;
  padding: 6px 8px;
  background: rgba(255,255,255,0.05);
  border-left: 3px solid var(--sky-500);
  border-radius: 4px;
  opacity: 0.9;
}

/* ---------- Generators ---------- */

.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.buy-amount-toggle { display: flex; gap: 4px; }
.buy-amount-toggle button {
  background: var(--stone-700);
  color: var(--chalk-100);
  padding: 5px 10px;
  font-size: 0.75rem;
}
.buy-amount-toggle button.active { background: var(--sky-500); }
.buy-amount-toggle button:hover { background: var(--sky-600); }

.generator-list, .upgrade-list, .achievement-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.generator-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s ease;
}
.generator-row:hover:not(.disabled) { background: rgba(255,255,255,0.09); }
.generator-row.disabled { opacity: 0.45; cursor: not-allowed; }
.generator-row.hidden { display: none; }

.gen-icon { font-size: 1.7rem; width: 40px; text-align: center; flex-shrink: 0; }
.gen-info { flex: 1; min-width: 0; }
.gen-name { font-weight: 700; font-size: 0.95rem; }
.gen-flavor { font-size: 0.72rem; opacity: 0.65; margin: 1px 0 4px 0; }
.gen-meta { font-size: 0.75rem; opacity: 0.85; display: flex; gap: 10px; flex-wrap: wrap; }
.gen-owned { font-weight: 700; color: var(--sky-500); }
.gen-cost { text-align: right; flex-shrink: 0; font-size: 0.85rem; font-weight: 700; color: var(--success); min-width: 90px; }
.gen-cost.cant-afford { color: var(--danger); }

/* ---------- Upgrades ---------- */

.panel-upgrades h2:nth-of-type(2) { margin-top: 18px; }

.upgrade-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  cursor: pointer;
}
.upgrade-row:hover:not(.disabled) { background: rgba(255,255,255,0.09); }
.upgrade-row.disabled { opacity: 0.45; cursor: not-allowed; }
.upgrade-row.hidden { display: none; }
.up-icon { font-size: 1.4rem; width: 30px; text-align: center; flex-shrink: 0; }
.up-info { flex: 1; min-width: 0; }
.up-name { font-weight: 700; font-size: 0.85rem; }
.up-desc { font-size: 0.7rem; opacity: 0.7; }
.up-cost { font-size: 0.8rem; font-weight: 700; color: var(--success); flex-shrink: 0; }
.up-cost.cant-afford { color: var(--danger); }

.list-empty { font-size: 0.8rem; opacity: 0.6; }

.achievement-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.ach-badge {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  filter: grayscale(1);
  opacity: 0.35;
  position: relative;
}
.ach-badge.unlocked { filter: none; opacity: 1; background: rgba(224, 122, 63, 0.18); border-color: var(--rock-orange); }
.ach-badge[title] { cursor: help; }

/* ---------- Toasts ---------- */

.toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--stone-800);
  border-left: 4px solid var(--rock-orange);
  padding: 10px 14px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  max-width: 280px;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.toast-action {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
}
.toast-action span { flex: 1; }
.toast-btn {
  flex-shrink: 0;
  background: var(--rock-orange);
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 5px 9px;
  white-space: nowrap;
}
.toast-btn:hover { background: var(--rock-orange-dark); }
.toast-x {
  flex-shrink: 0;
  background: none;
  color: var(--chalk-200);
  opacity: 0.55;
  font-size: 0.8rem;
  padding: 2px 4px;
}
.toast-x:hover { opacity: 1; }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--stone-800);
  border: 1px solid var(--rope-600);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow);
}
.modal-content h2 { margin-bottom: 10px; }
.modal-content p { font-size: 0.9rem; line-height: 1.4; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- Gym Membership panel ---------- */

.panel-membership h3 { font-size: 0.9rem; margin-top: 16px; }

.signin-box {
  background: rgba(74, 144, 217, 0.12);
  border: 1px solid rgba(74, 144, 217, 0.4);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
  text-align: center;
}
.signin-stats { font-size: 0.82rem; margin: 0 0 8px 0; }
.btn-signin {
  width: 100%;
  padding: 10px;
  background: var(--sky-500);
  color: #fff;
  font-weight: 700;
}
.btn-signin:hover:not(:disabled) { background: var(--sky-600); }
.btn-signin:disabled {
  background: var(--stone-600);
  color: var(--chalk-200);
  opacity: 0.6;
  cursor: not-allowed;
}
.signin-hint { font-size: 0.72rem; opacity: 0.75; margin: 6px 0 0 0; }

.grade-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px;
  margin-bottom: 6px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
}
.grade-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.7; }
.grade-value { font-size: 1.05rem; font-weight: 700; color: var(--rock-orange); }

.perk-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.perk-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  opacity: 0.55;
}
.perk-row.unlocked { opacity: 1; background: rgba(76, 175, 125, 0.12); border-color: rgba(76, 175, 125, 0.4); }
.perk-icon { font-size: 1.2rem; width: 24px; text-align: center; flex-shrink: 0; }
.perk-info { flex: 1; min-width: 0; }
.perk-name { font-weight: 700; font-size: 0.8rem; }
.perk-desc { font-size: 0.68rem; opacity: 0.75; }
.perk-progress { font-size: 0.68rem; opacity: 0.6; margin-top: 1px; }

.leaderboard { display: flex; flex-direction: column; gap: 6px; }
.lb-empty { font-size: 0.78rem; opacity: 0.6; margin: 4px 0 0 0; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
}
.lb-row.lb-current { border-color: var(--sky-500); background: rgba(74, 144, 217, 0.12); }
.lb-row.lb-top { border-color: var(--rock-orange); background: rgba(224, 122, 63, 0.12); }
.lb-row.lb-you { border-color: var(--success); background: rgba(76, 175, 125, 0.14); }
.lb-rank { width: 26px; text-align: center; font-weight: 700; font-size: 0.95rem; flex-shrink: 0; }
.lb-info { flex: 1; min-width: 0; }
.lb-title { font-weight: 700; font-size: 0.82rem; }
.lb-badges { font-weight: 400; opacity: 0.75; font-size: 0.72rem; }
.lb-meta { font-size: 0.7rem; opacity: 0.7; margin-top: 1px; }

/* ---------- Online: climber identity, avatars, global board ---------- */

.avatar { display: block; border-radius: 22%; flex-shrink: 0; }

.climber-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: var(--radius);
}
.ci-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ci-name { font-weight: 700; font-size: 0.9rem; }
.ci-name.ci-anon { font-weight: 600; opacity: 0.7; }
.link-btn {
  align-self: flex-start;
  background: none;
  color: var(--sky-500);
  padding: 0;
  font-size: 0.74rem;
  text-decoration: underline;
}
.link-btn:hover { color: var(--sky-600); }

.global-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}
.global-head h3 { margin-bottom: 4px; }
.climber-count { font-size: 0.72rem; opacity: 0.75; }
.climber-count strong { color: var(--rock-orange); font-size: 0.85rem; }

.global-toggle { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 8px 0; }
.global-toggle button {
  background: var(--stone-700);
  color: var(--chalk-100);
  padding: 5px 10px;
  font-size: 0.72rem;
}
.global-toggle button.active { background: var(--sky-500); }
.global-toggle button:hover { background: var(--sky-600); }
.global-toggle .global-submit { margin-left: auto; background: var(--rock-orange); font-weight: 700; }
.global-toggle .global-submit:hover { background: var(--rock-orange-dark); }
.global-toggle .global-submit:disabled { opacity: 0.5; cursor: progress; }

/* ---------- Profile modal / avatar builder ---------- */

.btn-primary { background: var(--sky-500); color: #fff; font-weight: 700; }
.btn-primary:hover:not(:disabled) { background: var(--sky-600); }
.btn-primary:disabled { opacity: 0.5; cursor: progress; }

.profile-modal-content { max-width: 340px; }
.avatar-preview {
  display: flex;
  justify-content: center;
  margin: 4px 0 10px 0;
}
.avatar-preview .avatar { width: 96px; height: 96px; }
.profile-label {
  display: block;
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
  margin: 10px 0 4px 0;
}
.profile-input {
  width: 100%;
  padding: 9px 10px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--chalk-100);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius);
}
.profile-input:focus { outline: 2px solid var(--sky-500); border-color: transparent; }

.avatar-builder { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.avatar-line { display: flex; align-items: center; gap: 10px; }
.avatar-line > span {
  width: 42px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.72rem;
  opacity: 0.75;
}
.swatch-row { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.2) inset;
  padding: 0;
}
.swatch.active { border-color: var(--chalk-100); box-shadow: 0 0 0 2px var(--sky-500); }

.profile-error { color: var(--danger); font-size: 0.76rem; min-height: 1em; margin: 10px 0 4px 0; }

/* ---------- Footer ---------- */

.footer {
  text-align: center;
  padding: 16px;
  font-size: 0.72rem;
  opacity: 0.55;
}
