:root {
  --bg: #0a0a18;
  --bg2: #12122a;
  --bg3: #1a1a38;
  --card: #1c1c3a;
  --border: #2e2e5e;
  --primary: #6c63ff;
  --primary-glow: #6c63ff88;
  --cyan: #00e5ff;
  --magenta: #ff00cc;
  --gold: #ffd700;
  --text: #e0e0ff;
  --text-dim: #8888bb;
  --success: #00ff9d;
  --danger: #ff4444;
  --warn: #ffaa00;
  --rarity-common: #aaaaaa;
  --rarity-uncommon: #44cc44;
  --rarity-rare: #4488ff;
  --rarity-epic: #aa44ff;
  --rarity-legendary: #ffd700;
  --rarity-mythical: #ff2222;
  --rarity-badge: #ff6a00;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--cyan); }

h1, h2, h3 { font-weight: 700; letter-spacing: 0.03em; }

.navbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px #00000066;
  flex-wrap: nowrap;
}

.nav-hamburger {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.35rem 0.55rem;
  font-size: 1.1rem;
  line-height: 1;
  margin-left: auto;
  transition: all 0.2s;
}
.nav-hamburger:hover { background: var(--bg3); color: var(--text); }

@media (max-width: 1200px) {
  .navbar { height: auto; padding: 0.6rem 1rem; gap: 0.5rem; flex-wrap: wrap; }
  .nav-hamburger { display: flex; margin-left: auto; }
  /* JS controls display of nav-links and nav-right; set their open styles here */
  .navbar .nav-right {
    display: none;
    order: 9;
    width: 100%;
    margin-left: 0;
    gap: 0.5rem;
    padding: 0.4rem 0 0.2rem;
    border-top: 1px solid var(--border);
  }
  .navbar .nav-links {
    display: none;
    flex-direction: row;
    flex-wrap: wrap;
    flex: none;
    width: 100%;
    gap: 0.25rem;
    padding: 0.5rem 0 0.3rem;
    border-top: 1px solid var(--border);
    order: 10;
  }
  .navbar .nav-links a { padding: 0.5rem 0.75rem; font-size: 0.9rem; flex: 1 1 calc(50% - 0.25rem); min-width: 120px; }
  .username-display { display: none; }
}

@media (max-width: 500px) {
  .navbar .nav-links a { flex: 1 1 100%; }
}

.navbar .logo {
  font-size: 1.4rem;
  font-weight: 900;
  background: linear-gradient(90deg, var(--primary), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
  white-space: nowrap;
}

.navbar .nav-links {
  display: flex;
  gap: 0.2rem;
  flex: 1;
}

.navbar .nav-links a {
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  transition: all 0.2s;
  white-space: nowrap;
}

.navbar .nav-links a:hover, .navbar .nav-links a.active {
  color: var(--text);
  background: var(--bg3);
}

.nav-dropdown {
  position: relative;
}

.nav-dropdown-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.nav-dropdown-btn:hover,
.nav-dropdown-btn.active {
  color: var(--text);
  background: var(--bg3);
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem;
  min-width: 160px;
  z-index: 200;
  box-shadow: 0 8px 24px #00000088;
  flex-direction: column;
  gap: 0.15rem;
}
.nav-dropdown-menu a {
  display: block;
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  transition: all 0.2s;
  white-space: nowrap;
}
.nav-dropdown-menu a:hover,
.nav-dropdown-menu a.active {
  color: var(--text);
  background: var(--bg3);
}
.nav-dropdown.open .nav-dropdown-menu { display: flex; }

/* inside hamburger menu, dropdown is inline */
@media (max-width: 1200px) {
  .nav-dropdown { width: 100%; }
  .nav-dropdown-btn { width: 100%; flex: 1 1 calc(50% - 0.25rem); min-width: 120px; justify-content: flex-start; }
  .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    background: var(--bg3);
    border-radius: 8px;
    padding: 0.2rem 0.4rem;
    margin-top: 0.2rem;
    width: 100%;
  }
}

.navbar .nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}

.zpoints-display {
  background: linear-gradient(135deg, var(--bg3), var(--card));
  border: 1px solid var(--gold);
  border-radius: 20px;
  padding: 0.3rem 1rem;
  font-size: 0.9rem;
  color: var(--gold);
  font-weight: 700;
  white-space: nowrap;
}

.username-display {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.nav-badge {
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  margin-left: 0.25rem;
  line-height: 1.5;
  display: inline-block;
  vertical-align: middle;
  pointer-events: none;
}

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1.2rem;
  max-width: 320px;
  min-width: 220px;
  box-shadow: 0 4px 24px #00000088;
  pointer-events: all;
  animation: toast-in 0.3s ease;
  font-size: 0.9rem;
  line-height: 1.4;
}

.toast-friend  { border-color: var(--primary); }
.toast-success { border-color: var(--success); color: var(--success); }
.toast-info    { border-color: var(--cyan); }

@keyframes toast-in {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes toast-out {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(110%); opacity: 0; }
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.page-title {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  transition: border-color 0.2s;
}

.card:hover { border-color: var(--primary); }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: #7c73ff; box-shadow: 0 0 16px var(--primary-glow); color: white; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: #ff6666; }

.btn-success {
  background: var(--success);
  color: #000;
}
.btn-success:hover { opacity: 0.85; }

.btn-gold {
  background: linear-gradient(135deg, #b8860b, var(--gold));
  color: #000;
  font-weight: 700;
}
.btn-gold:hover { filter: brightness(1.1); }

.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.8rem; }
.btn-full { width: 100%; }

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.4rem; }
.form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--primary); }
.form-input::placeholder { color: var(--text-dim); }

select.form-input option { background: var(--bg2); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-common { background: #333; color: var(--rarity-common); border: 1px solid var(--rarity-common); }
.badge-uncommon { background: #1a3a1a; color: var(--rarity-uncommon); border: 1px solid var(--rarity-uncommon); }
.badge-rare { background: #1a2a3a; color: var(--rarity-rare); border: 1px solid var(--rarity-rare); }
.badge-epic { background: #2a1a3a; color: var(--rarity-epic); border: 1px solid var(--rarity-epic); }
.badge-legendary { background: #3a2a00; color: var(--rarity-legendary); border: 1px solid var(--rarity-legendary); }
@keyframes mythical-shimmer {
  0%,100% { box-shadow: 0 0 8px #ff222288; border-color: #ff2222; color: #ff2222; }
  33%      { box-shadow: 0 0 8px #ff660088; border-color: #ff6600; color: #ff6600; }
  66%      { box-shadow: 0 0 8px #ffcc0088; border-color: #ffcc00; color: #ffcc00; }
}
.badge-mythical { background: #1a0000; color: #ff2222; border: 1px solid #ff2222; animation: mythical-shimmer 3s ease-in-out infinite; }
@keyframes badge-rarity-glow {
  0%,100% { box-shadow: 0 0 8px #ff6a0088; border-color: #ff6a00; }
  50%     { box-shadow: 0 0 16px #ff6a00cc; border-color: #ffaa44; }
}
.badge-badge { background: #2a1200; color: var(--rarity-badge); border: 1px solid var(--rarity-badge); animation: badge-rarity-glow 2s ease-in-out infinite; }
.badge-admin { background: #3a0000; color: #ff8888; border: 1px solid #ff4444; }
.badge-banned { background: #3a0000; color: var(--danger); }

.alert {
  padding: 0.8rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error { background: #2a0a0a; border: 1px solid var(--danger); color: #ff8888; }
.alert-success { background: #0a2a1a; border: 1px solid var(--success); color: var(--success); }
.alert-warn { background: #2a1a00; border: 1px solid var(--warn); color: var(--warn); }
.alert-terminated { background: #3a0000; border: 2px solid var(--danger); color: var(--danger); font-weight: 700; padding: 1rem; text-align: center; }

.item-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: all 0.2s;
  position: relative;
}

.item-card.equipped {
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
}

.item-preview {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: var(--bg3);
  position: relative;
  overflow: hidden;
}

.item-name { font-size: 0.9rem; font-weight: 600; }
.item-category { font-size: 0.75rem; color: var(--text-dim); }
.item-equipped-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--primary);
  color: white;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-weight: 700;
}

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.table th { color: var(--text-dim); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.table tr:hover td { background: var(--bg3); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: #00000099;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  max-width: 480px;
  width: 95%;
  box-shadow: 0 8px 40px #00000088;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-title { font-size: 1.3rem; margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center { display: flex; align-items: center; justify-content: center; min-height: 200px; }

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.game-canvas-container {
  position: relative;
  display: inline-block;
}

canvas {
  border: 2px solid var(--border);
  border-radius: 8px;
  display: block;
}

.game-lobby {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  max-width: 400px;
  width: 100%;
}

.game-hud {
  display: flex;
  gap: 2rem;
  align-items: center;
  background: var(--bg2);
  padding: 0.75rem 2rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1.1rem;
  font-weight: 700;
}

.game-score {
  font-size: 2rem;
  padding: 0 1rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  flex-wrap: wrap;
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.5rem 1rem;
  border-radius: 6px 6px 0 0;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.tab-btn:hover { color: var(--text); background: var(--bg3); }
.tab-btn.active { color: var(--primary); border-bottom: 2px solid var(--primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

@media (max-width: 640px) {
  .navbar { gap: 0.5rem; padding: 0 1rem; }
  .navbar .nav-links a { padding: 0.3rem 0.5rem; font-size: 0.8rem; }
  .page { padding: 1rem; }
}

.glow-primary { box-shadow: 0 0 20px var(--primary-glow); }
.glow-gold { box-shadow: 0 0 20px #ffd70066; }

.stat-tile {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem;
  text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.25rem; }

.box-card {
  background: var(--card);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
  border: 1px solid var(--border);
  transition: all 0.3s;
  cursor: pointer;
}
.box-card:hover { transform: translateY(-4px); }
.box-preview {
  width: 100px;
  height: 100px;
  border-radius: 12px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
}
.box-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.25rem; }
.box-cost { color: var(--gold); font-weight: 700; }
.box-desc { font-size: 0.8rem; color: var(--text-dim); margin: 0.5rem 0; }

.loot-reveal {
  text-align: center;
  padding: 2rem;
}
.loot-item-preview {
  font-size: 5rem;
  animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: block;
  margin: 1rem 0;
}
@keyframes popIn {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to { transform: scale(1) rotate(0deg); opacity: 1; }
}

.notif-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  margin-left: 4px;
  vertical-align: middle;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.friend-item:last-child { border-bottom: none; }
.friend-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  color: white;
  flex-shrink: 0;
}
.friend-info { flex: 1; }
.friend-name { font-weight: 600; }
.friend-actions { display: flex; gap: 0.5rem; }

.trade-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.trade-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.trade-sides { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; }
.trade-arrow { color: var(--primary); font-size: 1.5rem; text-align: center; }

.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.search-bar input { flex: 1; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; }

.game-result-overlay {
  position: absolute;
  inset: 0;
  background: #000000cc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 10;
  backdrop-filter: blur(4px);
  gap: 0.5rem;
}
.game-result-title {
  font-size: 2.5rem;
  font-weight: 900;
  text-shadow: 0 0 30px currentColor;
}
.game-result-win { color: var(--success); }
.game-result-lose { color: var(--danger); }
.game-result-draw { color: var(--warn); }

.row-banned td { opacity: 0.5; }
.row-admin td:first-child::after { content: ' 🛡️'; }

/* ── Responsive table scroll wrapper ─────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}

/* ── Trade sides responsive ───────────────────────────────────── */
@media (max-width: 640px) {
  .trade-sides { grid-template-columns: 1fr; }
  .trade-arrow { transform: rotate(90deg); }
}

/* ── 768px breakpoint — tablets / small laptops ──────────────── */
@media (max-width: 768px) {
  .page { padding: 1rem; }
  .page-title { font-size: 1.4rem; }

  .modal-box { padding: 1.25rem; border-radius: 12px; }
  .modal-actions { flex-wrap: wrap; gap: 0.5rem; }

  .tabs { gap: 0.3rem; }
  .tab-btn { font-size: 0.82rem; padding: 0.4rem 0.7rem; }

  .table th, .table td { padding: 0.55rem 0.65rem; font-size: 0.83rem; }

  .game-hud { flex-wrap: wrap; gap: 1rem; padding: 0.6rem 1rem; font-size: 0.95rem; }

  .grid-2 { grid-template-columns: 1fr; }

  .boxes-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

  .btn { font-size: 0.85rem; padding: 0.5rem 1rem; }
}

/* ── 480px breakpoint — phones ────────────────────────────────── */
@media (max-width: 480px) {
  .page { padding: 0.75rem; }
  .page-title { font-size: 1.25rem; }

  .modal-box { padding: 1rem; border-radius: 10px; width: 98%; }
  .modal-title { font-size: 1.1rem; }

  .tab-btn { font-size: 0.78rem; padding: 0.35rem 0.55rem; }

  .table th, .table td { padding: 0.4rem 0.5rem; font-size: 0.78rem; }

  .btn-sm { font-size: 0.75rem; padding: 0.3rem 0.65rem; }

  .game-lobby { padding: 1.25rem; }
  .game-result-title { font-size: 1.8rem; }

  .card { padding: 1rem; }

  .boxes-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; }
  .box-card { padding: 1rem; }
  .box-preview { width: 72px; height: 72px; }

  .toast-container { bottom: 0.75rem; right: 0.75rem; left: 0.75rem; }
  .toast { max-width: 100%; min-width: 0; font-size: 0.83rem; }

  .autosell-grid { gap: 0.4rem; }
  .autosell-chip { font-size: 0.75rem; padding: 0.3rem 0.7rem; }

  .admin-banner { padding: 0.75rem; }
  .admin-banner .shield { font-size: 1.5rem; }
}
