* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2b2b2b;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #eee;
  user-select: none;
  -webkit-user-select: none;
}

#view {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: crosshair;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}
#voxel-canvas { position: fixed; inset: 0; display: block; touch-action: none; }
.map-prev3d {
  width: 100%; aspect-ratio: 1 / 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; font-size: 44px;
  background: linear-gradient(135deg, #2a3a5a, #161e2e); border-radius: 6px;
}
.map-prev3d span { font-size: 15px; font-weight: 700; color: #9ab4d6; }

/* ---- HUD (top-left status) ---- */
#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

#status, #cooldown {
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  gap: 8px;
}

#status .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #888;
  transition: background 0.2s;
}
#status.online .dot { background: #46d160; }
#status.offline .dot { background: #e55; }
#status.connecting .dot { background: #ffd24a; }

#cooldown { color: #ffd24a; font-variant-numeric: tabular-nums; min-width: 72px; }
/* Connection state pill: fixed width when "online" so it doesn't jitter. */
#status { font-variant-numeric: tabular-nums; }
#status.online { min-width: 84px; }
#charge {
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(4px);
  color: #8fc0ff;
  /* Fixed width + tabular digits so the regen timer doesn't jitter. */
  font-variant-numeric: tabular-nums;
  min-width: 168px;
  display: inline-block;
}
/* On non-coins maps the pill is just a short cooldown — compact, still stable. */
#charge.cd-only { min-width: 86px; }
#charge.full { color: #ffd24a; }
#event-hud {
  background: rgba(110, 70, 190, 0.32);
  border: 1px solid rgba(165, 125, 245, 0.5);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #e6dcff;
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.event-hud .ev-line, #event-hud .ev-line { white-space: nowrap; }
#event-hud .ev-global { color: #ffd24a; }
.adm-evlbl { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: #ccc; }
#viewonly {
  background: rgba(0, 131, 199, 0.85);
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}
#banned {
  background: rgba(229, 0, 0, 0.85);
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}
.hidden { display: none !important; }

/* Transient toast */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(20, 20, 20, 0.92);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 320;
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Top bar (right controls) ---- */
#topbar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn {
  background: rgba(0, 0, 0, 0.55);
  color: #eee;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  /* Uniform height everywhere (top bar + every modal), independent of content. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  line-height: 1.1;
}
.btn:hover { background: rgba(0, 0, 0, 0.75); }
.btn.sm { min-height: 30px; }
/* Dropdown menu items stay left-aligned despite the centered .btn default. */
#topbar-menu .btn, #topbar-menu .perk { justify-content: flex-start; }

.perk {
  background: rgba(0, 0, 0, 0.55);
  color: #8ef0a3;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  min-height: 38px;
}
.perk:hover { background: rgba(0, 0, 0, 0.75); }

#lang-switch {
  display: flex;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  overflow: hidden;
  backdrop-filter: blur(4px);
}
.lang {
  padding: 7px 11px;
  font-size: 13px;
  cursor: pointer;
  color: #aaa;
}
.lang.active { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* Donate modal */
#donate-modal .auth-box { width: min(440px, 95vw); }
#donate-body .section-title { margin-top: 14px; }
.donate-card {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-top: 8px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.08);
}
.donate-ic { font-size: 28px; flex: none; width: 36px; text-align: center; }
.donate-info { flex: 1; min-width: 0; }
.donate-name { font-size: 15px; font-weight: 700; color: #fff; }
.donate-desc { font-size: 12px; color: #aaa; margin-top: 2px; }
.donate-card .buy { flex: none; font-weight: 700; color: #ffd24a; }

/* Rules / guide modal */
#rules-modal .rules-box { width: min(640px, 95vw); max-height: 86vh; overflow-y: auto; }
.rules-tabs { display: flex; gap: 8px; margin-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.rules-tab {
  background: none; border: none; border-bottom: 2px solid transparent; color: #aaa;
  padding: 8px 14px; font-size: 14px; cursor: pointer;
}
.rules-tab:hover { color: #ddd; }
.rules-tab.active { color: #fff; border-bottom-color: #ffd24a; }
#rules-body { font-size: 14px; line-height: 1.55; color: #ddd; }
#rules-body h3 { font-size: 15px; color: #fff; margin: 16px 0 6px; }
#rules-body h3:first-child { margin-top: 6px; }
#rules-body p { margin: 6px 0; }
#rules-body ul { margin: 6px 0; padding-left: 22px; }
#rules-body li { margin: 3px 0; }
#rules-body b { color: #ffd24a; }

/* Language modal */
#lang-modal .auth-box { width: min(320px, 92vw); }
#lang-body { display: flex; flex-direction: column; gap: 8px; }
.lang-opt {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; font-size: 15px; cursor: pointer;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); color: #eee;
}
.lang-opt:hover { background: rgba(255, 255, 255, 0.14); }
.lang-opt.active { border-color: #ffd24a; color: #fff; }
.lang-flag { font-size: 20px; }

/* ---- Palette ---- */
#palette-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 12px;
  backdrop-filter: blur(4px);
}
.current-color {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px #000;
}

#palette-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px #000;
}
/* 3D eraser swatch (color 0 = remove block). */
.swatch.eraser {
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #444; font-weight: 700;
  background: repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 50% / 10px 10px;
}
#current-color { display: flex; align-items: center; justify-content: center; font-size: 16px; color: #444; font-weight: 700; }

/* ---- Template controls (in the palette bar) ---- */
#tpl-controls { display: flex; align-items: center; gap: 10px; padding-left: 6px; border-left: 1px solid rgba(255,255,255,0.15); }
.tpl-check { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #eee; cursor: pointer; white-space: nowrap; }
.tpl-check.disabled { opacity: 0.4; cursor: not-allowed; }
.tpl-progress { font-size: 12px; color: #8ef0a3; white-space: nowrap; }

/* ---- Template modal ---- */
#template-modal .auth-box { width: min(440px, 95vw); }
.tpl-form { display: flex; flex-direction: column; gap: 12px; }
.tpl-form > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #ccc; }
.tpl-form input[type="number"], .tpl-form select {
  padding: 8px 10px; border-radius: 8px; font-size: 14px; width: 100%;
  border: 1px solid rgba(255,255,255,0.15); background: #2a2a2a; color: #eee; outline: none;
}
.tpl-form input[type="file"] { font-size: 13px; color: #ccc; max-width: 100%; }
.tpl-coords { display: flex; gap: 10px; }
/* min-width:0 lets the X/Y fields shrink instead of overflowing the modal. */
.tpl-coords label { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #ccc; }
.tpl-preview-wrap { text-align: center; background: rgba(0,0,0,0.25); border-radius: 8px; padding: 8px; }
.tpl-preview { max-width: 100%; max-height: 200px; image-rendering: pixelated; }
.tpl-info { font-size: 12px; color: #aaa; text-align: center; }
.tpl-warn { color: #ffb24a; }
.tpl-actions { display: flex; gap: 8px; }
.tpl-actions .btn { flex: 1; }

#hint {
  position: fixed;
  bottom: 16px;
  right: 16px;
  font-size: 12px;
  color: #aaa;
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 10px;
  border-radius: 8px;
}

/* ---- Modal ---- */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#modal-box {
  background: #1f1f1f;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 20px;
  width: min(960px, 94vw);
  max-height: 86vh;
  overflow: auto;
}
#modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
#modal-header h2 { margin: 0; font-size: 18px; }

#map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
  align-items: stretch; /* all cards in a row share the same height */
}
.map-card {
  position: relative;
  background: #2a2a2a;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.1s, transform 0.08s;
  display: flex;
  flex-direction: column;
}
.map-card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.25); }
.map-card.current { border-color: #46d160; }
/* current marker as an overlay (doesn't change card height) */
.map-card.current::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 8px;
  background: #46d160;
  color: #04210d;
  font-weight: 800;
  font-size: 13px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  image-rendering: pixelated;
  background: #111;
  border-radius: 6px;
  display: block;
}
.map-card .name {
  margin-top: 10px;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.map-card .map-online {
  font-size: 12px;
  font-weight: 700;
  color: #8ef0a3;
  white-space: nowrap;
  flex: none;
}
.map-card .meta {
  margin-top: 3px;
  font-size: 12px;
  color: #aaa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Reserved registered-only slot: same height on every card (empty when N/A),
   wraps instead of being clipped so the full label always fits. */
.map-card .map-regonly {
  margin-top: 5px;
  min-height: 1.25em;
  white-space: normal;
  overflow: visible;
  color: #6fc3e8;
  font-weight: 600;
}

.map-card .votes {
  display: flex;
  gap: 8px;
  margin-top: auto; /* pin to bottom so all cards line up */
  padding-top: 10px;
}
.vote-btn {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ddd;
  border-radius: 7px;
  padding: 5px 0;
  font-size: 13px;
  cursor: pointer;
}
.vote-btn:hover { background: rgba(255, 255, 255, 0.16); }
.vote-btn.like.on { background: rgba(70, 209, 96, 0.25); border-color: #46d160; color: #8ef0a3; }
.vote-btn.dislike.on { background: rgba(229, 0, 0, 0.22); border-color: #e55; color: #ff9a9a; }

/* ---- Auth / pixel / user / palette / leaderboard / admin modals ---- */
#auth-modal, #pixel-modal, #user-modal, #palette-modal, #lb-modal, #admin-modal, #shop-modal, #clan-modal, #template-modal, #lang-modal, #rules-modal, #donate-modal, #privacy-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
}
/* First-visit notice bar (local-storage + adblock). */
#notice {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  z-index: 95; width: min(680px, calc(100vw - 24px));
  display: flex; align-items: center; gap: 14px;
  background: rgba(20, 22, 30, 0.96); border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px; padding: 12px 16px; backdrop-filter: blur(6px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}
#notice.hidden { display: none; }
.notice-inner { flex: 1; min-width: 0; }
.notice-inner p { margin: 0; font-size: 12.5px; line-height: 1.45; color: #cdd3e0; }
.notice-inner p + p { margin-top: 6px; color: #e7c98f; }
.notice-inner a { color: #8fb4ff; cursor: pointer; text-decoration: underline; }
#notice-ok { flex: none; white-space: nowrap; }
#privacy-body { font-size: 13.5px; line-height: 1.5; color: #d3d8e2; }
#privacy-body h3 { font-size: 14px; margin: 12px 0 4px; color: #fff; }
#privacy-body ul { margin: 4px 0; padding-left: 18px; }
#privacy-body li { margin: 3px 0; }
.auth-box {
  background: #1f1f1f;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 20px;
  width: min(360px, 92vw);
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.auth-field label { font-size: 12px; color: #aaa; }
.auth-field input {
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #2a2a2a;
  color: #eee;
  font-size: 14px;
}
.auth-note { font-size: 12px; color: #888; margin: 0 0 12px; }
.captcha-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.captcha-box {
  flex: 1; min-height: 64px; display: flex; align-items: center; justify-content: center;
  background: #1b1b1b; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 8px; overflow: hidden;
}
.captcha-box svg { display: block; max-width: 100%; height: auto; }
.captcha-row .btn.sm { flex: none; font-size: 16px; padding: 8px 10px; }
.captcha-timer { flex: none; font-size: 12px; color: #aaa; min-width: 30px; text-align: center; font-variant-numeric: tabular-nums; }
.captcha-timer.low { color: #ff9a9a; font-weight: 700; }
.auth-error { color: #ff6b6b; font-size: 13px; min-height: 18px; margin: 4px 0; }
.auth-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.auth-actions .btn { flex: 1; text-align: center; white-space: nowrap; }
/* Inputs/selects in modals share the button height so rows line up. */
.auth-box input:not([type="checkbox"]):not([type="file"]),
.auth-box select,
#modal-box input:not([type="checkbox"]):not([type="file"]),
#modal-box select { min-height: 38px; }

/* ---- Pixel / user info ---- */
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 14px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.info-row .k { color: #aaa; }
.info-row .v { font-weight: 600; text-align: right; }

.pix-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  vertical-align: middle;
}

.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge-tag {
  font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
}
.badge-vip { color: #ffd24a; }
.badge-old { color: #4fe3ec; }
.badge-reg { color: #ccc; }
/* Status badge rendered inline inside the account button. */
.acct-badge {
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 800;
  vertical-align: middle;
  background: rgba(255, 255, 255, 0.12);
}
.acct-badge.badge-vip { color: #ffd24a; }
.acct-badge.badge-old { color: #4fe3ec; }
.acct-badge.badge-admin { color: #ff9a9a; }

.stats-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
.stats-table th, .stats-table td { padding: 5px 8px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.07); }

/* Modifier formula */
.formula-box { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.formula-row { display: flex; flex-direction: column; gap: 2px; }
.formula-row .f-name { color: #aaa; font-size: 12px; }
.formula-row .f-calc { color: #eee; font-variant-numeric: tabular-nums; }
.formula-row .f-calc b { color: #ffd24a; }
.f-lbl { color: #888; font-size: 11px; }
.f-note { font-size: 12px; color: #6fc3e8; margin-top: 2px; }
.stats-table th { color: #aaa; font-weight: 600; }
.stats-table td.num, .stats-table th.num { text-align: right; }
.section-title { margin: 14px 0 4px; font-size: 13px; color: #aaa; }

/* ---- Leaderboard: columns side by side, scroll if they don't fit ---- */
#lb-modal .auth-box { width: min(1180px, 95vw); }
.lb-cols {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 6px;
}
.lb-col {
  flex: 1 0 250px;
  min-width: 250px;
  max-height: 62vh;
  overflow-y: auto;
}
.lb-col .section-title { margin-top: 0; position: sticky; top: 0; background: #1f1f1f; padding: 4px 0; }
.lb-note { font-size: 12px; color: #888; margin: 12px 0 0; }

/* Leaders/Statistics tabs */
.lb-tabs { display: flex; gap: 8px; margin-bottom: 14px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.lb-tab {
  background: none; border: none; border-bottom: 2px solid transparent; color: #aaa;
  padding: 8px 14px; font-size: 14px; cursor: pointer;
}
.lb-tab:hover { color: #ddd; }
.lb-tab.active { color: #fff; border-bottom-color: #ffd24a; }
.stats-daybar { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 12px; }
.stats-date { font-size: 14px; font-weight: 600; color: #ddd; min-width: 150px; text-align: center; }
.stats-charts { display: flex; flex-wrap: wrap; gap: 18px; }
.stats-chart-wrap { flex: 1 1 320px; min-width: 280px; }
.st-canvas { width: 100%; max-width: 560px; background: rgba(0,0,0,0.2); border-radius: 8px; cursor: crosshair; }
.clan-legend .lg-map { color: #86a2d6; }
.clan-legend .lg-all { color: #46d160; }
.stats-pies { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 6px; }
.pie-wrap { flex: 1 1 260px; min-width: 240px; }
.pie-row { display: flex; align-items: center; gap: 14px; }
.pie-canvas { flex: none; }
.pie-legend { display: flex; flex-direction: column; gap: 3px; font-size: 12px; min-width: 0; }
.pie-leg { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pie-dot { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* ---- Admin panel ---- */
#admin-modal .admin-box { width: min(720px, 95vw); max-height: 86vh; overflow-y: auto; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.adm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.adm-row em { color: #ff9a9a; font-style: normal; font-size: 12px; }
.adm-actions { display: flex; gap: 6px; }
.adm-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
/* All admin-form controls share one dark style (text, number, select). */
.adm-form input:not([type="checkbox"]), .adm-form select {
  padding: 7px 10px; border-radius: 8px; font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.15); background: #2a2a2a; color: #eee;
  outline: none; transition: border-color 0.12s;
}
.adm-form input[type="text"], .adm-form input:not([type]) { flex: 1; min-width: 140px; }
.adm-form input:focus, .adm-form select:focus { border-color: rgba(255, 210, 74, 0.6); }
.adm-form select { cursor: pointer; }
/* Hide the ugly default number spinners for a cleaner look. */
.adm-form input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.adm-form input[type="number"]::-webkit-outer-spin-button,
.adm-form input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.adm-chk { font-size: 13px; color: #ccc; display: flex; align-items: center; gap: 4px; }
.adm-announce { display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
.adm-announce textarea {
  padding: 8px 10px; border-radius: 8px; font-size: 13px; font-family: inherit; resize: vertical;
  border: 1px solid rgba(255,255,255,0.15); background: #2a2a2a; color: #eee; outline: none;
}
.adm-announce textarea:focus { border-color: rgba(255,210,74,0.6); }
.adm-announce .btn { align-self: flex-start; }
.adm-cfg { display: flex; flex-direction: column; gap: 6px; }
.adm-cfgrow { display: flex; align-items: center; gap: 8px; }
.adm-cfgrow label { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.adm-cfgname { font-size: 13px; color: #ddd; }
.adm-cfgkey { font-size: 11px; color: #777; font-family: monospace; }
.adm-cfgrow input { width: 110px; flex: none; padding: 5px 8px; border-radius: 7px; border: 1px solid rgba(255,255,255,0.15); background: #2a2a2a; color: #eee; }

.map-card.disabled { opacity: 0.55; }
.map-card.disabled .name::after { content: ' ⛔'; }

#highlight-clear {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(207, 110, 228, 0.85);
  border-color: rgba(255,255,255,0.3);
}

/* ---- Coins / wallet (top bar, pushed to the left) ---- */
#wallet {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Top-bar dropdown menu (positioned under the fixed top bar) */
#topbar-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 190px;
  background: rgba(20, 20, 20, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 10px;
  z-index: 120;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
#topbar-menu .btn, #topbar-menu .perk { width: 100%; text-align: left; }
#topbar-menu #lang-switch { width: 100%; }
#topbar-menu #lang-switch .lang { flex: 1; text-align: center; }
.coin {
  background: rgba(0, 0, 0, 0.55);
  color: #ffd24a;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  backdrop-filter: blur(4px);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  min-height: 40px; /* a touch taller than the buttons */
}

/* ---- Item bar (bottom, left of the palette/current color) ---- */
#item-bar { display: flex; gap: 6px; align-items: center; }
.item-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.08);
  color: #eee;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.item-chip .cnt { font-size: 12px; color: #cfcfcf; font-weight: 700; }
.item-chip:hover { background: rgba(255, 255, 255, 0.16); }
.item-chip.selected { border-color: #ffd24a; background: rgba(255, 210, 74, 0.18); }
.item-chip.rotate { font-size: 15px; }

/* ---- Shop ---- */
#shop-modal .auth-box { width: min(560px, 95vw); }
#shop-balance { font-size: 14px; color: #ffd24a; font-weight: 700; margin: 2px 0 10px; }
#shop-body { display: flex; flex-direction: column; gap: 10px; }
.shop-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.shop-icon { font-size: 30px; line-height: 1; flex: none; width: 40px; text-align: center; }
.shop-info { flex: 1; min-width: 0; }
.shop-name { font-size: 15px; font-weight: 700; color: #fff; }
.shop-desc { font-size: 12px; color: #aaa; margin: 2px 0; }
.shop-owned { font-size: 12px; color: #8ef0a3; }
.shop-card .buy { flex: none; white-space: nowrap; font-weight: 700; color: #ffd24a; }
.shop-card .buy[disabled] { opacity: 0.45; cursor: not-allowed; color: #bbb; }

/* ---- Clans ---- */
#clan-modal .clan-box { width: min(620px, 95vw); }
.clan-note { font-size: 13px; color: #bbb; margin: 4px 0 12px; }
.clan-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.clan-actions .btn { flex: 1 1 auto; text-align: center; white-space: nowrap; }
.clan-head { font-size: 20px; font-weight: 700; margin-top: 4px; }
.clan-tag { color: #ffd24a; font-weight: 800; }
.clan-name { color: #fff; }
.clan-meta { font-size: 13px; color: #aaa; margin: 4px 0 14px; }
.clan-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.clan-panel-title { font-size: 15px; font-weight: 700; color: #ddd; }
.clan-form { display: flex; flex-direction: column; gap: 10px; }
.clan-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #ccc; }
.clan-form input, .clan-form select {
  padding: 8px 10px; border-radius: 8px; font-size: 14px;
  border: 1px solid rgba(255,255,255,0.15); background: #2a2a2a; color: #eee; outline: none;
}
.clan-form input:focus, .clan-form select:focus { border-color: rgba(255,210,74,0.6); }
.clan-inline { display: flex; gap: 8px; align-items: center; }
.clan-inline input { flex: 1; }
.clan-list { display: flex; flex-direction: column; gap: 6px; max-height: 48vh; overflow-y: auto; }
.clan-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 7px 4px; border-bottom: 1px solid rgba(255,255,255,0.07); font-size: 14px;
}
.clan-dim { color: #888; font-size: 12px; }
/* ---- Clan upgrade tree ---- */
.clan-up-list { display: flex; flex-direction: column; gap: 10px; }
.clan-up-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
}
.clan-up-main { flex: 1; min-width: 0; }
.clan-up-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.clan-up-eff { color: #8fd6a0; font-weight: 700; }
.clan-up-sub { font-size: 11px; color: #999; margin: 2px 0 6px; }
.clan-up-bar { height: 5px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
.clan-up-bar > span { display: block; height: 100%; background: linear-gradient(90deg,#4f8cff,#8fd6a0); }
.clan-up-lvl { font-size: 11px; color: #aaa; margin-top: 4px; }
.clan-up-buy { flex: none; display: flex; align-items: center; }
.clan-up-buy .btn.sm { white-space: nowrap; }
.clan-up-max { font-size: 12px; font-weight: 700; color: #ffd24a; }
.clan-err { font-size: 13px; color: #ff9a9a; min-height: 1em; }
.clan-audit-row { font-size: 13px; padding: 4px 2px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.clan-legend { display: flex; gap: 14px; font-size: 12px; margin-bottom: 8px; }
.clan-legend .lg-px { color: #86a2d6; }
.clan-legend .lg-on { color: #46d160; }
#clan-chart { width: 100%; max-width: 560px; background: rgba(0,0,0,0.2); border-radius: 8px; }
.btn.danger { border-color: rgba(229,80,80,0.6); color: #ff9a9a; }
.btn.danger:hover { background: rgba(229,80,80,0.18); }

/* ---- Chat (bottom-left) ---- */
#chat {
  position: fixed;
  bottom: 16px;
  left: 12px;
  width: 320px;
  max-width: 80vw;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 40;
}
#chat-header { display: flex; gap: 6px; align-items: center; }
#chat-channel {
  flex: 1; min-width: 0; padding: 6px 8px; border-radius: 8px; font-size: 12px;
  border: 1px solid rgba(255,255,255,0.15); background: rgba(0,0,0,0.65); color: #eee;
  backdrop-filter: blur(4px); cursor: pointer;
}
#chat-panel {
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(0,0,0,0.55); border-radius: 10px; padding: 8px; backdrop-filter: blur(4px);
}
#chat.collapsed #chat-panel { display: none; }
#chat-messages {
  height: 220px; max-height: 38vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 1.35;
}
.ct-msg { word-break: break-word; }
.ct-tag { color: #ffd24a; font-weight: 700; }
.ct-badge { font-size: 11px; }
.ct-user { font-weight: 700; }
.ct-user.ct-admin { color: #ff7a7a; }
.ct-user.ct-vip { color: #ffd24a; }
.ct-user.ct-old { color: #4fe3ec; }
.ct-user.ct-reg { color: #cfcfcf; }
.ct-text { color: #e6e6e6; }
#chat-input-row { display: flex; gap: 6px; }
#chat-input {
  flex: 1; min-width: 0; padding: 7px 10px; border-radius: 8px; font-size: 13px;
  border: 1px solid rgba(255,255,255,0.15); background: #2a2a2a; color: #eee; outline: none;
}
#chat-input:focus { border-color: rgba(255,210,74,0.5); }
#chat-login-note { font-size: 12px; color: #aaa; text-align: center; padding: 4px; }

/* ---- Centered broadcast banner ---- */
#announce {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 11vh; /* sit higher up, not dead center */
  pointer-events: none; /* don't block the map; only the box is interactive */
}
#announce-box {
  pointer-events: auto;
  position: relative;
  width: fit-content;        /* frame hugs the text */
  max-width: min(680px, 90vw);
  background: rgba(20, 20, 20, 0.92);
  border: 1px solid rgba(255, 210, 74, 0.5);
  border-radius: 14px;
  padding: 22px 48px 22px 28px;
  color: #fff;
  font-size: 20px;
  line-height: 1.4;
  text-align: center;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  animation: announce-in 0.2s ease;
}
@keyframes announce-in { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
#announce-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; color: #aaa; font-size: 16px; cursor: pointer;
}
#announce-close:hover { color: #fff; }

/* ===================== Mobile / narrow screens ===================== */
@media (max-width: 640px) {
  /* HUD + top bar: tighter, smaller. */
  #hud { top: 8px; left: 8px; gap: 5px; }
  #status, #cooldown { font-size: 12px; padding: 5px 9px; }
  #charge { font-size: 12px; min-width: 0; }
  #charge.cd-only { min-width: 78px; }
  #event-hud { font-size: 11px; padding: 4px 9px; }
  #topbar { top: 8px; right: 8px; gap: 6px; }
  .btn { min-height: 36px; padding: 0 11px; font-size: 12.5px; }
  .btn.sm { min-height: 28px; }
  .coin { min-height: 36px; padding: 0 11px; font-size: 13px; }
  /* Long usernames mustn't blow out the top bar. */
  #account-btn { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #topbar-menu { min-width: 168px; max-width: calc(100vw - 16px); }
  /* Guest CTA (only shown logged-out, when wallet/badge are hidden): keep it slim. */
  #perk-note { font-size: 11px; padding: 0 9px; min-height: 34px; max-width: calc(100vw - 70px); }
  /* The account button, now a menu item on mobile, spans the menu width. */
  #topbar-menu #account-btn { max-width: none; width: 100%; }

  /* Palette bar: allow wrapping, hug the viewport. */
  #palette-bar { bottom: 10px; gap: 8px; padding: 6px 8px; max-width: calc(100vw - 16px); flex-wrap: wrap; justify-content: center; }
  #hint { display: none; } /* mouse-only hint, irrelevant on touch */

  /* Modals: use the screen, smaller padding. */
  #modal-box { padding: 14px; max-height: 90vh; width: 94vw; }
  .auth-box { padding: 16px; }
  #modal-header { margin-bottom: 12px; }
  #modal-header h2 { font-size: 16px; }
  #map-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .map-card { padding: 10px; }
  #lb-body { overflow-x: auto; }

  /* Chat: when collapsed, show ONLY the toggle button (no channel select, no
     wide transparent box) so it doesn't cover the template controls. */
  #chat { width: 240px; max-width: 64vw; left: 8px; bottom: 10px; }
  #chat-messages { height: 150px; }
  #chat.collapsed { width: auto; }
  #chat.collapsed #chat-channel { display: none; }

  #announce-box { padding: 18px 30px 18px 20px; max-width: 92vw; }
  #notice { bottom: 10px; flex-direction: column; align-items: stretch; gap: 8px; }
  #notice-ok { width: 100%; }
}

@media (max-width: 430px) {
  .btn { font-size: 12px; padding: 0 9px; }
  #map-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  #account-btn { max-width: 30vw; }
  #chat { max-width: 58vw; }
}
