/* =====================
   Base & Reset
   ===================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-dark:    #080c14;
  --bg-darker:  #060a10;
  --bg-panel:   #131c2e;
  --bg-panel2:  #1a2540;
  --border:     rgba(200,146,42,0.15);
  --border2:    rgba(200,146,42,0.25);
  --gold:       #c8922a;
  --gold-dim:   rgba(200,146,42,0.5);
  --text:       #e2ddd5;
  --text-dim:   #64748b;
  --text-bright:#e2ddd5;
  --grass:      #4a9155;
  --grass-dark: #3a7a44;
  --grass2:     #52a05f;
  --brick:        #c09060;
  --brick-dark:   #a87848;
  --brick-mortar: #ddd3be;
  --highlight:  rgba(200,146,42,0.25);
  --danger:     #e74c3c;
  --success:    #2ecc71;
  --info:       #3498db;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  overflow-x: hidden;
}

/* =====================
   Login Screen
   ===================== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #0f172a 0%, #080c14 100%);
}

.login-box {
  background: var(--bg-panel);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 40px 48px;
  width: 440px;
  max-width: 95vw;
  text-align: center;
  box-shadow: 0 0 40px rgba(0,0,0,0.8), 0 0 80px rgba(200,146,42,0.08);
}

.login-logo {
  font-size: 2.8rem;
  font-weight: bold;
  color: var(--gold);
  letter-spacing: 3px;
  text-shadow: 0 0 20px rgba(200,146,42,0.5);
  margin-bottom: 8px;
  font-family: 'Playfair Display', Georgia, serif;
}

.login-tagline {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 8px;
  letter-spacing: 1px;
}
.login-madbyte {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 24px;
  opacity: 0.7;
}
.login-madbyte a {
  color: var(--gold);
  text-decoration: none;
  opacity: 0.85;
}
.login-madbyte a:hover {
  opacity: 1;
  text-decoration: underline;
}
.btn-beginner-mode {
  display: block;
  text-align: center;
  margin-bottom: 20px;
  padding: 9px 16px;
  background: #0f1f0f;
  border: 1px solid #1e3a1e;
  border-radius: 4px;
  color: #2ecc71;
  font-size: 0.8rem;
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: background 0.15s, border-color 0.15s;
}
.btn-beginner-mode:hover {
  background: #142814;
  border-color: #2a5a2a;
  color: #3ee68a;
}

/* Wallet-first auth */
.btn-connect-wallet {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: #f6851b;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 12px rgba(246,133,27,0.35);
  margin-bottom: 8px;
}

.btn-connect-wallet:hover:not(:disabled) {
  background: #f99630;
  transform: translateY(-1px);
  box-shadow: 0 4px 18px rgba(246,133,27,0.5);
}

.btn-connect-wallet:disabled {
  opacity: 0.65;
  cursor: wait;
}

.login-wallet-note {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 20px;
  letter-spacing: 0.5px;
}

.login-new-player {
  font-size: 0.88rem;
  color: var(--gold);
  margin-bottom: 12px;
}

.login-status {
  font-size: 0.8rem;
  color: #2ecc71;
  min-height: 18px;
  margin-bottom: 10px;
}

.login-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.login-form input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-darker);
  border: 1px solid var(--border2);
  border-radius: 3px;
  color: var(--text-bright);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.login-form input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(200,146,42,0.2);
}

.login-form button,
#enter-btn {
  padding: 10px 18px;
  background: var(--gold);
  color: #111;
  border: none;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
}

.login-form button:hover {
  background: #ffd060;
  transform: translateY(-1px);
}

.error-msg {
  color: var(--danger);
  font-size: 0.8rem;
  min-height: 18px;
  margin-bottom: 16px;
}

.login-instructions {
  text-align: left;
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 8px;
}

.login-instructions h3 {
  font-size: 0.8rem;
  color: var(--gold-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.login-instructions ul {
  list-style: none;
  padding: 0;
}

.login-instructions ul li {
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 3px 0;
  padding-left: 14px;
  position: relative;
}

.login-instructions ul li::before {
  content: '›';
  position: absolute;
  left: 0;
  color: var(--gold-dim);
}

/* =====================
   Top Bar
   ===================== */
#topbar {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--gold);
  letter-spacing: 1px;
  text-shadow: 0 0 12px rgba(200,146,42,0.4);
  text-decoration: none;
  transition: text-shadow 0.2s;
}
.logo:hover {
  text-shadow: 0 0 20px rgba(200,146,42,0.7);
}
.topbar-hub-link {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-decoration: none;
  opacity: 0.6;
  align-self: center;
  letter-spacing: 0.3px;
  margin-left: 8px;
}
.topbar-hub-link:hover { opacity: 1; color: var(--gold); }
.topbar-madbyte {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-decoration: none;
  opacity: 0.75;
  margin-left: 10px;
  align-self: center;
  letter-spacing: 0.5px;
}
.topbar-madbyte:hover {
  opacity: 1;
  color: var(--gold);
}

#topnav {
  display: flex;
  align-items: center;
  gap: 16px;
}

#nav-user {
  color: var(--text-dim);
  font-size: 0.85rem;
}

#nav-user strong {
  color: var(--gold);
}

/* Wallet button */
.btn-wallet {
  background: #f6851b;
  border: none;
  color: #fff;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 3px;
  font-weight: bold;
  transition: background 0.15s, transform 0.1s;
}
.btn-wallet:hover { background: #e8780a; transform: translateY(-1px); }
.btn-wallet.connected { background: #27ae60; }
.btn-wallet.connected:hover { background: #229954; }

.btn-logout {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text-dim);
  padding: 5px 12px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 2px;
  transition: color 0.15s, border-color 0.15s;
}

.btn-logout:hover {
  color: var(--text-bright);
  border-color: var(--text-dim);
}

/* =====================
   Knocked-Out Banner
   ===================== */
#knocked-out-banner {
  background: rgba(200, 30, 30, 0.92);
  border-bottom: 2px solid #e74c3c;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-shrink: 0;
  animation: fadein 0.3s ease;
  z-index: 50;
}

.ko-content {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.ko-icon { font-size: 1.4rem; }

.ko-text {
  font-size: 0.95rem;
  font-weight: bold;
  color: #fff;
  letter-spacing: 1px;
}

.ko-reenter {
  background: #fff;
  color: #c0392b;
  border: none;
  padding: 6px 16px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.ko-reenter:hover:not(:disabled) { background: #ffe0e0; transform: scale(1.03); }
.ko-reenter:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ko-cooldown {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.8);
  font-weight: bold;
  letter-spacing: 0.5px;
}

/* =====================
   Status Bar
   ===================== */
#status-bar {
  background: #1e1e1e;
  border-bottom: 1px solid var(--border);
  padding: 6px 20px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.status-sep {
  color: var(--border2);
  margin: 0 12px;
}

#status-coins   { color: var(--gold); }
#status-balance { color: var(--success); }
#status-moves   { color: var(--info); }
#status-pool    { color: #e67e22; font-weight: bold; }

.status-msg {
  margin-left: 16px;
  color: var(--gold);
  font-style: italic;
  animation: fadein 0.3s ease;
}

/* =====================
   Main Layout
   ===================== */
#game-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* =====================
   Grid
   ===================== */
#grid-wrapper {
  flex: 1;
  overflow: auto;
  background: radial-gradient(ellipse at center, #0a1020 0%, #060a10 100%);
  position: relative;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#grid-scroll {
  display: inline-block;
  border-radius: 6px;
  overflow: hidden;
  box-shadow:
    0 0 0 2px rgba(120, 80, 30, 0.6),
    0 0 0 4px rgba(60, 40, 10, 0.4),
    0 16px 60px rgba(0,0,0,0.9),
    0 4px 20px rgba(0,0,0,0.7),
    0 0 80px rgba(80,160,60,0.08);
}

#game-grid {
  border-collapse: collapse;
  table-layout: fixed;
  /* No outer border — handled by #grid-scroll */
}

#game-grid td {
  width: 32px;
  height: 32px;
  padding: 0;
  position: relative;
  overflow: hidden;
  cursor: default;
  box-sizing: border-box;
  border-right: 1px solid rgba(0,0,0,0.13);
  border-bottom: 1px solid rgba(0,0,0,0.13);
}

/* ── Grass: CSS gradient with depth ── */
#game-grid td.cell-grass {
  background:
    linear-gradient(145deg,
      #56b84a 0%,
      #44a038 30%,
      #368530 60%,
      #2a6e24 100%);
}

/* every other row slightly darker for natural depth variation */
#game-grid tr:nth-child(even) td.cell-grass,
#game-grid tr:nth-child(even) td.cell-player-here,
#game-grid tr:nth-child(even) td.cell-arrow {
  filter: brightness(0.91);
}

/* ── Brick / wall: 3D raised block look ── */
#game-grid td.cell-brick {
  background:
    linear-gradient(145deg,
      #e09050 0%,
      #c07030 25%,
      #a05828 55%,
      #784018 80%,
      #5a2e10 100%);
}

/* ── Current player cell ── */
#game-grid td.cell-player-here {
  background:
    linear-gradient(145deg,
      #56b84a 0%,
      #44a038 30%,
      #368530 60%,
      #2a6e24 100%);
  outline: 2px solid var(--gold);
  outline-offset: -2px;
  z-index: 2;
}

/* ── Walkable adjacent — arrow cells ── */
#game-grid td.cell-arrow {
  background:
    linear-gradient(145deg,
      #62cc55 0%,
      #4eb040 30%,
      #3d9232 60%,
      #2e7826 100%);
  cursor: pointer;
}

#game-grid td.cell-arrow:hover {
  filter: brightness(1.15);
}

/* ── Wall-build target ── */
#game-grid td.cell-wall-target {
  outline: 2px dashed var(--gold);
  outline-offset: -2px;
  cursor: crosshair;
}

#game-grid td.cell-wall-target:hover {
  filter: brightness(1.15);
}

/* ── Break-wall target ── */
#game-grid td.cell-break-target {
  outline: 2px dashed #e74c3c;
  outline-offset: -2px;
  cursor: crosshair;
  animation: pulse-red 0.7s ease-in-out infinite alternate;
}

#game-grid td.cell-break-target:hover {
  filter: brightness(1.2);
}

@keyframes pulse-red {
  from { outline-color: #e74c3c; }
  to   { outline-color: #ff9090; }
}

/* =====================
   Cell Contents
   ===================== */
.cell-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 16px;
  user-select: none;
}

/* Coin */
.cell-coin {
  font-size: 15px;
  line-height: 1;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1;
}

/* Player avatar */
.player-avatar {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background-size: cover;
  background-position: center;
  background-color: transparent;
  border: 2px solid rgba(255,255,255,0.5);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
  flex-shrink: 0;
  font-size: 0;
  color: transparent;
  image-rendering: crisp-edges;
}

.player-avatar.is-me {
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(200,146,42,0.7), 0 2px 6px rgba(0,0,0,0.5);
  width: 28px;
  height: 28px;
}

/* ── CSS-drawn directional arrows (perfectly centered) ── */
.cell-arrow-indicator {
  pointer-events: none;
  user-select: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  opacity: 0.75;
  z-index: 2;
}

/* North — points up */
.cell-arrow-indicator.dir-N {
  border-left:  7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 10px solid rgba(255,255,180,0.85);
  margin-top: -5px; /* nudge up slightly inside the 32px cell */
}

/* South — points down */
.cell-arrow-indicator.dir-S {
  border-left:  7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid rgba(255,255,180,0.85);
  margin-top: 5px;
}

/* East — points right */
.cell-arrow-indicator.dir-E {
  border-top:    7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 10px solid rgba(255,255,180,0.85);
  margin-left: 5px;
}

/* West — points left */
.cell-arrow-indicator.dir-W {
  border-top:    7px solid transparent;
  border-bottom: 7px solid transparent;
  border-right: 10px solid rgba(255,255,180,0.85);
  margin-left: -5px;
}

#game-grid td.cell-arrow:hover .cell-arrow-indicator {
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(255,255,150,0.9));
}

/* Multiple items layering: coin behind player */
.cell-coin-small {
  font-size: 9px;
  position: absolute;
  bottom: 2px;
  right: 2px;
  z-index: 2;
  pointer-events: none;
  opacity: 0.8;
}

/* Mine indicator (only visible to the placer, shown as subtle dot) */
.mine-indicator {
  width: 6px;
  height: 6px;
  background: var(--danger);
  border-radius: 50%;
  position: absolute;
  top: 3px;
  left: 3px;
  z-index: 4;
  pointer-events: none;
  opacity: 0.8;
}

/* =====================
   No moves banner
   ===================== */
.no-moves-overlay {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px 20px;
  font-size: 0.85rem;
  text-align: center;
  border-radius: 3px;
  pointer-events: none;
  z-index: 50;
  white-space: nowrap;
}

/* =====================
   Pending action hint
   ===================== */
.pending-hint {
  position: sticky;
  bottom: 8px;
  left: 8px;
  background: rgba(240, 192, 64, 0.15);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  padding: 8px 14px;
  font-size: 0.8rem;
  border-radius: 3px;
  margin-top: 8px;
  animation: fadein 0.2s ease;
}

.pending-hint kbd {
  background: var(--bg-panel2);
  border: 1px solid var(--border2);
  padding: 1px 5px;
  border-radius: 2px;
  font-family: inherit;
  font-size: 0.75rem;
}

/* =====================
   Sidebar
   ===================== */
#sidebar {
  width: 288px;
  min-width: 288px;
  background: var(--bg-panel);
  border-left: 2px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  flex-shrink: 0;
}

.panel {
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
}

.panel h3 {
  font-size: 0.75rem;
  color: var(--gold-dim);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* =====================
   Wallet Panel
   ===================== */
.wallet-addr {
  font-size: 0.72rem;
  color: var(--text-dim);
  word-break: break-all;
  margin-bottom: 8px;
}

.wallet-balance-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.82rem;
}

.wallet-label { color: var(--text-dim); }
.wallet-value { color: var(--success); font-weight: bold; }

.wallet-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.wallet-btn {
  flex: 1;
  background: var(--bg-panel2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s;
}
.wallet-btn:hover { background: #333; border-color: #f6851b; color: #f6851b; }

.wallet-msg {
  font-size: 0.72rem;
  color: var(--text-dim);
  min-height: 16px;
  line-height: 1.4;
}

/* =====================
   Leaderboard note
   ===================== */
.lb-note {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-style: italic;
}

/* =====================
   Action Buttons
   ===================== */
.action-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--bg-panel2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  border-radius: 3px;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  position: relative;
}

.action-btn:hover:not(:disabled) {
  background: #333333;
  border-color: var(--gold-dim);
  transform: translateX(2px);
}

.action-btn:active:not(:disabled) {
  transform: translateX(0);
}

.action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.action-btn.active {
  border-color: var(--gold);
  background: rgba(200,146,42,0.1);
  box-shadow: 0 0 8px rgba(200,146,42,0.2);
}

.action-btn-highlight {
  border-color: #2ecc71 !important;
  background: rgba(46,204,113,0.08) !important;
}

.action-btn-highlight:hover:not(:disabled) {
  background: rgba(46,204,113,0.18) !important;
  border-color: #27ae60 !important;
}

.action-btn-nuke {
  border-color: #e74c3c !important;
  background: rgba(231,76,60,0.10) !important;
  animation: nuke-pulse 2.5s ease-in-out infinite;
}

.action-btn-nuke:hover:not(:disabled) {
  background: rgba(231,76,60,0.22) !important;
  border-color: #c0392b !important;
  box-shadow: 0 0 14px rgba(231,76,60,0.4) !important;
}

.action-btn-nuke:disabled {
  animation: none;
}

@keyframes nuke-pulse {
  0%, 100% { box-shadow: 0 0 4px rgba(231,76,60,0.2); }
  50%       { box-shadow: 0 0 12px rgba(231,76,60,0.5); }
}

/* =====================
   Admin Panel
   ===================== */
#admin-panel {
  border: 1px solid #f39c12;
  background: rgba(243,156,18,0.05);
}

#admin-panel h3 {
  color: #f39c12;
}

.admin-stats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  background: rgba(0,0,0,0.25);
  border-radius: 4px;
  padding: 8px 10px;
}

.admin-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
}

.admin-stat-label {
  color: var(--text-dim);
}

.admin-stat-value {
  color: #f39c12;
  font-weight: bold;
}

.admin-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.admin-btn {
  padding: 7px 12px;
  border-radius: 4px;
  border: 1px solid #f39c12;
  background: rgba(243,156,18,0.08);
  color: #f39c12;
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  font-family: inherit;
}

.admin-btn:hover {
  background: rgba(243,156,18,0.2);
}

.admin-btn-warn {
  border-color: #e67e22;
  color: #e67e22;
  background: rgba(230,126,34,0.08);
}

.admin-btn-warn:hover {
  background: rgba(230,126,34,0.2);
}

.admin-btn-danger {
  border-color: #e74c3c;
  color: #e74c3c;
  background: rgba(231,76,60,0.08);
}

.admin-btn-danger:hover {
  background: rgba(231,76,60,0.2);
}

.admin-msg {
  font-size: 0.72rem;
  color: #2ecc71;
  min-height: 18px;
  margin-bottom: 8px;
  word-break: break-all;
}

.admin-section {
  margin-top: 10px;
}

.admin-section h4 {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.admin-table-wrap {
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.72rem;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th {
  text-align: left;
  padding: 3px 5px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-weight: normal;
  font-size: 0.7rem;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--bg-panel);
}

.admin-table td {
  padding: 3px 5px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text);
  vertical-align: middle;
}

.admin-table tr:hover td {
  background: rgba(255,255,255,0.03);
}

.admin-username { font-weight: bold; }
.admin-wallet   { color: var(--text-dim); font-size: 0.68rem; }
.admin-tx       { font-size: 0.68rem; }
.admin-tx a     { color: #3498db; text-decoration: none; }
.admin-tx a:hover { text-decoration: underline; }
.admin-dim      { color: var(--text-dim); }
.admin-active   { color: #2ecc71; }
.admin-ko       { color: #e74c3c; }
.admin-empty    { color: var(--text-dim); font-size: 0.75rem; padding: 6px 0; }

.action-icon {
  font-size: 1.1rem;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.action-label {
  flex: 1;
}

.action-cost {
  font-size: 0.72rem;
  color: var(--gold-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

/* =====================
   Leaderboard
   ===================== */
#leaderboard-content {
  font-size: 0.8rem;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}

.lb-row:last-child {
  border-bottom: none;
}

.lb-row-clickable {
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}
.lb-row-clickable:hover {
  background: rgba(240,192,64,0.08);
}

.lb-rank {
  width: 20px;
  color: var(--text-dim);
  text-align: right;
  flex-shrink: 0;
  font-size: 0.72rem;
}

.lb-rank.gold   { color: #ffd700; }
.lb-rank.silver { color: #c0c0c0; }
.lb-rank.bronze { color: #cd7f32; }

.lb-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.2);
}

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-name.is-me { color: var(--gold); }

.lb-balance {
  color: var(--success);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* =====================
   Reports
   ===================== */
#reports-content {
  max-height: 240px;
  overflow-y: auto;
  font-size: 0.75rem;
  line-height: 1.5;
  font-family: 'Courier New', Courier, monospace; /* monospace preserved for game event log */
}

.report-item {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  word-break: break-word;
  animation: fadein 0.3s ease;
}

.report-item:first-child {
  color: var(--text);
}

.report-item:last-child {
  border-bottom: none;
}

.report-time {
  color: var(--text-dim);
  font-size: 0.65rem;
  margin-right: 6px;
  opacity: 0.6;
}

/* =====================
   Toast Notifications
   ===================== */
#toast-container {
  position: fixed;
  bottom: 20px;
  left: 0;
  right: 288px; /* sidebar width — keep toasts within the map area */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: var(--bg-panel2);
  border: 1px solid var(--border2);
  color: var(--text-bright);
  padding: 10px 20px;
  border-radius: 3px;
  font-size: 0.85rem;
  animation: toast-in 0.3s ease forwards;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  text-align: center;
  max-width: 360px;
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger); }
.toast.info    { border-color: var(--info);    color: var(--info); }
.toast.gold    { border-color: var(--gold);    color: var(--gold); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(-10px); }
}

@keyframes fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* =====================
   Scrollbars
   ===================== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track { background: var(--bg-darker); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* =====================
   Responsive / Mobile
   ===================== */

/* ── Tablet: shrink sidebar slightly ── */
@media (max-width: 960px) {
  #sidebar { width: 240px; min-width: 240px; }
  #toast-container { right: 240px; }
  #game-grid td { width: 28px; height: 28px; }
}

/* ── Mobile: full vertical stack ── */

/* ── FAQ Button ── */
.btn-faq {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
}
.btn-faq:hover {
  color: var(--text-bright);
  border-color: var(--text-dim);
}

/* ── FAQ Modal ── */
.faq-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 600;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px;
}

.faq-box {
  background: var(--bg-panel);
  border: 1px solid var(--border2);
  border-radius: 6px;
  width: 100%;
  max-width: 720px;
  padding: 32px 36px;
  position: relative;
}

.faq-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 3px;
  font-family: inherit;
}
.faq-close:hover { color: var(--text-bright); background: var(--bg-panel2); }

.faq-title {
  font-size: 1.3rem;
  color: var(--gold);
  margin-bottom: 24px;
  letter-spacing: 0.03em;
}

.faq-section {
  margin-bottom: 28px;
}
.faq-section h3 {
  font-size: 0.85rem;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 14px;
}

.faq-item {
  margin-bottom: 14px;
}
.faq-q {
  color: var(--text-bright);
  font-size: 0.85rem;
  font-weight: bold;
  margin-bottom: 4px;
}
.faq-q::before {
  content: 'Q: ';
  color: var(--gold-dim);
}
.faq-a {
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.6;
  padding-left: 14px;
}
.faq-a a { color: var(--info); }
.faq-a a:hover { color: var(--text-bright); }
.faq-a strong { color: var(--text-bright); }
.faq-a code {
  background: var(--bg-darker);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.75rem;
  color: var(--success);
}
.faq-a kbd {
  background: var(--bg-panel2);
  border: 1px solid var(--border2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.75rem;
}
.faq-list {
  padding-left: 18px;
  margin-top: 4px;
}
.faq-list li {
  margin-bottom: 5px;
  line-height: 1.5;
}

/* ── Player Profile Modal ─────────────────────────────────────────────────── */
.profile-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.profile-modal-box {
  background: var(--bg-dark);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}

.profile-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
}
.profile-close:hover { color: var(--text); background: var(--border); }

.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background-size: cover;
  border: 3px solid var(--gold-dim);
  flex-shrink: 0;
}

.profile-title { flex: 1; }

.profile-username {
  font-size: 1.3rem;
  font-weight: bold;
  letter-spacing: 1px;
  color: var(--gold);
}

.profile-rank {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.profile-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.profile-stat {
  background: var(--bg-darker);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-stat-value {
  font-size: 1.05rem;
  font-weight: bold;
  color: var(--gold);
}

.profile-stat-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.profile-section { margin-bottom: 16px; }

.profile-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.profile-hist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.profile-hist-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
.profile-hist-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text);
}
.profile-hist-table tr:last-child td { border-bottom: none; }
.profile-hist-table td:not(:first-child) { text-align: right; }
.profile-hist-table th:not(:first-child) { text-align: right; }

.profile-joined {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 8px;
}

.profile-loading {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 12px 0;
}

@media (max-width: 700px) {

  /* Game screen scrolls naturally instead of fixed viewport */
  #game-screen {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  #main-layout {
    flex-direction: column;
    overflow: visible;
    flex: none;
  }

  /* ── Topbar: compact ── */
  #topbar { padding: 0 10px; height: 44px; }
  .logo   { font-size: 1.1rem; letter-spacing: 1px; }
  #nav-user { display: none; } /* "Playing as X" hidden — saves space */
  #topnav { gap: 8px; }
  .btn-wallet { font-size: 0.72rem; padding: 4px 9px; }
  .btn-logout { font-size: 0.72rem; padding: 4px 9px; }

  /* ── Status bar: pill badges, no pipes ── */
  #status-bar {
    padding: 5px 10px;
    gap: 4px;
    flex-wrap: wrap;
  }
  .status-sep { display: none; }
  #status-coins,
  #status-balance,
  #status-moves,
  #status-pool {
    font-size: 0.72rem;
    padding: 2px 7px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.08);
  }

  /* ── Grid: touch-scroll ── */
  #grid-wrapper {
    flex: none;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 6px;
    -webkit-overflow-scrolling: touch;
  }
  #game-grid td { width: 22px; height: 22px; }

  /* Smaller avatars */
  .player-avatar        { width: 17px; height: 17px; border-width: 1.5px; }
  .player-avatar.is-me  { width: 19px; height: 19px; }

  /* Smaller arrow triangles */
  .cell-arrow-indicator.dir-N { border-left-width: 5px; border-right-width: 5px; border-bottom-width: 7px; }
  .cell-arrow-indicator.dir-S { border-left-width: 5px; border-right-width: 5px; border-top-width: 7px; }
  .cell-arrow-indicator.dir-E { border-top-width: 5px; border-bottom-width: 5px; border-left-width: 7px; }
  .cell-arrow-indicator.dir-W { border-top-width: 5px; border-bottom-width: 5px; border-right-width: 7px; }

  /* ── Find Me button (mobile only) ── */
  #find-me-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin: 0 6px 6px;
    padding: 7px 14px;
    background: rgba(200,146,42,0.1);
    border: 1px solid var(--border2);
    color: var(--gold);
    font-family: inherit;
    font-size: 0.78rem;
    border-radius: 3px;
    cursor: pointer;
    width: calc(100% - 12px);
    transition: background 0.15s;
  }
  #find-me-btn:hover { background: rgba(200,146,42,0.2); }

  /* ── Sidebar: full width below grid ── */
  #sidebar {
    width: 100%;
    min-width: unset;
    max-height: none;
    border-left: none;
    border-top: 2px solid var(--border2);
    overflow-y: visible;
    flex-shrink: 0;
  }

  /* ── Collapsible panel headers ── */
  .panel h3 {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
  }

  .panel:not(.collapsed) h3 {
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
  }

  .panel-chevron {
    font-size: 0.75rem;
    color: var(--text-dim);
    transition: transform 0.2s;
    margin-left: 6px;
    flex-shrink: 0;
  }

  .panel.collapsed .panel-chevron { transform: rotate(-90deg); }

  /* Hide panel body when collapsed */
  .panel.collapsed > *:not(h3) { display: none !important; }

  /* ── Action buttons: bigger tap targets ── */
  .action-btn { min-height: 48px; padding: 10px 12px; }

  /* ── KO banner ── */
  .ko-text { font-size: 0.85rem; }

  /* ── Toast: avoid bottom safe area ── */
  #toast-container { bottom: 16px; left: 0; right: 0; transform: none; max-width: none; }
  .toast { font-size: 0.8rem; padding: 8px 16px; max-width: 90vw; }

  /* ── Login box ── */
  .login-box { padding: 28px 18px; }
  .login-logo { font-size: 2rem; }
}

/* Hide Find Me button on desktop */
@media (min-width: 701px) {
  #find-me-btn { display: none; }
}

/* =====================
   Underground Layer
   ===================== */

/* Grid wrapper dark cave background */
#grid-wrapper.underground {
  background: radial-gradient(ellipse at center, #1a0a2a 0%, #080310 100%);
}

/* Underground grass cells — dark cave floor */
#game-grid.underground td.cell-grass {
  background: linear-gradient(145deg, #2d2035 0%, #1e1428 50%, #150e1e 100%);
}
#game-grid.underground td.cell-grass:hover {
  background: linear-gradient(145deg, #3a2a45 0%, #2a1c38 50%, #1e1530 100%);
}

/* Underground brick cells — dark rock */
#game-grid.underground td.cell-brick {
  background: linear-gradient(135deg,
    #3a3040 0%, #2c2435 33%,
    #221820 66%, #2c2435 100%
  );
  border-color: #1a1220;
}
#game-grid.underground td.cell-brick::after {
  border-color: rgba(80, 60, 100, 0.3);
}

/* Underground player cell */
#game-grid.underground td.cell-player-here {
  background: radial-gradient(circle at center, #3d2060 0%, #1e1028 100%);
}

/* Underground arrow cells */
#game-grid.underground td.cell-arrow.cell-grass {
  background: linear-gradient(145deg, #342045 0%, #241834 50%, #180e28 100%);
}
#game-grid.underground td.cell-arrow.cell-grass:hover {
  background: linear-gradient(145deg, #3e2855 0%, #2c2040 50%, #1e1434 100%);
}

/* Underground arrow color — eerie purple glow */
#game-grid.underground .cell-arrow-indicator.dir-N,
#game-grid.underground .cell-arrow-indicator.dir-S {
  border-bottom-color: rgba(200, 150, 255, 0.85);
  border-top-color: rgba(200, 150, 255, 0.85);
}
#game-grid.underground .cell-arrow-indicator.dir-E,
#game-grid.underground .cell-arrow-indicator.dir-W {
  border-left-color: rgba(200, 150, 255, 0.85);
  border-right-color: rgba(200, 150, 255, 0.85);
}

/* Stair cells */
td.cell-stairs {
  background: linear-gradient(145deg, #7a5c30 0%, #5c4020 50%, #3d2810 100%) !important;
  cursor: pointer;
  position: relative;
}
td.cell-stairs:hover {
  background: linear-gradient(145deg, #9a7a40 0%, #7a5828 50%, #5a3c18 100%) !important;
}
#game-grid.underground td.cell-stairs {
  background: linear-gradient(145deg, #5030a0 0%, #381878 50%, #200c50 100%) !important;
}
#game-grid.underground td.cell-stairs:hover {
  background: linear-gradient(145deg, #6a42c0 0%, #4a2898 50%, #301468 100%) !important;
}
.stair-icon {
  font-size: 14px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 0 3px rgba(255,200,50,0.8));
}
.stair-dir {
  font-size: 8px;
  display: block;
  text-align: center;
  color: #ffdd66;
  font-family: monospace;
  line-height: 1;
  margin-top: -4px;
}
#game-grid.underground .stair-dir {
  color: #cc99ff;
}

/* Status bar layer indicator */
.status-layer {
  color: #5dcc82;
  font-weight: bold;
  letter-spacing: 0.02em;
}
.status-layer.underground {
  color: #aa66ff;
  text-shadow: 0 0 8px rgba(170, 100, 255, 0.6);
}
