/**
 * THRONES OF MEMES — Visual Theme: ROYAL NEXUS
 * Palette:
 * - Deep royal plum: #21152F
 * - Warm ivory: #F7F2E8
 * - Antique gold: #D9AE58
 * - Rich emerald: #286B54
 * - Muted lavender: #B7A3E8
 * - Soft charcoal: #332D3A
 */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700;800;900&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --rn-plum: #21152F;
  --rn-plum-dark: #150D1F;
  --rn-plum-surface: #291B3A;
  --rn-plum-elevated: #322247;
  --rn-ivory: #F7F2E8;
  --rn-ivory-muted: #D8D0C3;
  --rn-gold: #D9AE58;
  --rn-gold-light: #F4D38B;
  --rn-gold-dark: #A37E30;
  --rn-gold-hairline: rgba(217, 174, 88, 0.28);
  --rn-emerald: #286B54;
  --rn-emerald-light: #3A8E72;
  --rn-lavender: #B7A3E8;
  --rn-lavender-subtle: rgba(183, 163, 232, 0.15);
  --rn-charcoal: #332D3A;
  --rn-charcoal-dark: #201A25;
  --rn-shadow: 0 10px 30px -5px rgba(10, 5, 18, 0.7);
  --rn-card-radius: 12px;
}

/* Base Document */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--rn-plum-dark);
  color: var(--rn-ivory);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 48% at 50% 0%, rgba(183, 163, 232, 0.16) 0%, transparent 72%),
    radial-gradient(ellipse 55% 38% at 100% 100%, rgba(40, 107, 84, 0.14) 0%, transparent 72%),
    radial-gradient(ellipse 45% 55% at 0% 45%, rgba(90, 45, 105, 0.13) 0%, transparent 75%),
    linear-gradient(160deg, #150D1F 0%, #21152F 52%, #160E20 100%);
  background-attachment: scroll;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Typography */
.font-cinzel {
  font-family: 'Cinzel', Georgia, serif;
  letter-spacing: 0.04em;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Cinzel', Georgia, serif;
  color: var(--rn-ivory);
  margin-bottom: 0.5rem;
}

.text-gold { color: var(--rn-gold) !important; }
.text-gold-light { color: var(--rn-gold-light) !important; }
.text-ivory { color: var(--rn-ivory) !important; }
.text-ivory-muted { color: var(--rn-ivory-muted) !important; }
.text-lavender { color: var(--rn-lavender) !important; }
.text-emerald { color: var(--rn-emerald) !important; }

/* Top HUD Header */
.rn-topbar {
  background: rgba(21, 13, 31, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rn-gold-hairline);
  position: sticky;
  top: 0;
  z-index: 1030;
  height: 64px;
}

.rn-brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  cursor: pointer;
}

.rn-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--rn-gold) 0%, var(--rn-gold-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--rn-plum-dark);
  font-size: 1.25rem;
  box-shadow: 0 4px 12px rgba(217, 174, 88, 0.3);
}

.rn-resource-strip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rn-resource-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(33, 21, 47, 0.7);
  border: 1px solid rgba(217, 174, 88, 0.2);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--rn-ivory);
  transition: all 0.2s ease;
}

.rn-resource-item:hover {
  border-color: var(--rn-gold);
  background: rgba(41, 27, 58, 0.85);
}

.rn-resource-item .icon {
  font-size: 1rem;
}

.rn-resource-item.rank-pill {
  background: rgba(40, 107, 84, 0.35);
  border-color: rgba(40, 107, 84, 0.5);
  color: #A3E5C8;
}

/* Master Layout Shell */
.rn-shell {
  display: flex;
  min-height: calc(100vh - 64px);
  min-width: 0;
}

/* Left Sidebar Navigation (Desktop) */
.rn-sidebar {
  width: 240px;
  background: rgba(26, 17, 39, 0.75);
  border-right: 1px solid var(--rn-gold-hairline);
  padding: 24px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
}

.rn-nav-heading {
  font-size: 0.68rem;
  font-family: 'Cinzel', serif;
  color: var(--rn-lavender);
  opacity: 0.75;
  letter-spacing: 0.12em;
  padding: 12px 14px 4px 14px;
  text-transform: uppercase;
}

.rn-nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--rn-ivory-muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.rn-nav-btn i {
  font-size: 1.15rem;
  color: var(--rn-lavender);
  transition: transform 0.2s ease, color 0.2s ease;
}

.rn-nav-btn:hover {
  color: var(--rn-ivory);
  background: rgba(183, 163, 232, 0.08);
  border-color: rgba(217, 174, 88, 0.15);
}

.rn-nav-btn:hover i {
  color: var(--rn-gold);
  transform: translateX(2px);
}

.rn-nav-btn.active {
  color: var(--rn-gold-light);
  background: linear-gradient(90deg, rgba(217, 174, 88, 0.15) 0%, rgba(41, 27, 58, 0.5) 100%);
  border-color: rgba(217, 174, 88, 0.4);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--rn-gold);
}

.rn-nav-btn.active i {
  color: var(--rn-gold);
}

/* Main Content Area */
.rn-content-area {
  flex: 1;
  padding: 28px 32px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

/* Cards & Surfaces */
.rn-card {
  background: var(--rn-plum-surface);
  border: 1px solid var(--rn-gold-hairline);
  border-radius: var(--rn-card-radius);
  box-shadow: var(--rn-shadow);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.rn-card:hover {
  border-color: rgba(217, 174, 88, 0.45);
  box-shadow: 0 12px 36px -4px rgba(10, 5, 18, 0.85);
}

.rn-card-header {
  padding: 14px 20px;
  background: rgba(33, 21, 47, 0.65);
  border-bottom: 1px solid var(--rn-gold-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rn-card-body {
  padding: 20px;
}

.rn-card-inner {
  background: rgba(21, 13, 31, 0.5);
  border: 1px solid rgba(217, 174, 88, 0.15);
  border-radius: 8px;
  padding: 14px;
}

/* Buttons */
.btn-nexus-gold {
  background: linear-gradient(135deg, #F0CE84 0%, var(--rn-gold) 50%, var(--rn-gold-dark) 100%);
  color: #170E22;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: 0.05em;
  border: 1px solid #FFE7A8;
  border-radius: 8px;
  padding: 10px 22px;
  box-shadow: 0 4px 14px rgba(217, 174, 88, 0.35);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-nexus-gold:hover {
  background: linear-gradient(135deg, #FFF0B8 0%, #F0CE84 50%, var(--rn-gold) 100%);
  color: #0E0716;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(217, 174, 88, 0.5);
}

.btn-nexus-gold:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(217, 174, 88, 0.25);
}

.btn-nexus-plum {
  background: linear-gradient(135deg, var(--rn-plum-elevated) 0%, var(--rn-plum) 100%);
  color: var(--rn-ivory);
  font-family: 'Cinzel', serif;
  font-weight: 600;
  border: 1px solid var(--rn-gold-hairline);
  border-radius: 8px;
  padding: 9px 20px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-nexus-plum:hover {
  background: linear-gradient(135deg, #3D2B55 0%, var(--rn-plum-elevated) 100%);
  color: var(--rn-gold-light);
  border-color: var(--rn-gold);
  transform: translateY(-1px);
}

.btn-nexus-emerald {
  background: linear-gradient(135deg, var(--rn-emerald-light) 0%, var(--rn-emerald) 100%);
  color: #FFFFFF;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  border: 1px solid rgba(58, 142, 114, 0.6);
  border-radius: 8px;
  padding: 10px 22px;
  box-shadow: 0 4px 14px rgba(40, 107, 84, 0.35);
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-nexus-emerald:hover {
  background: linear-gradient(135deg, #48A786 0%, var(--rn-emerald-light) 100%);
  color: #FFFFFF;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(40, 107, 84, 0.5);
}

/* Canvas Battlefield & Kingdom Framing */
.canvas-wrapper {
  background: #110A1A;
  border: 1px solid rgba(217, 174, 88, 0.3);
  border-radius: var(--rn-card-radius);
  overflow: hidden;
  box-shadow: inset 0 0 35px rgba(0, 0, 0, 0.85), 0 8px 30px rgba(10, 5, 18, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
}

.canvas-wrapper canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Hero Showcase in Lobby */
.rn-hero-showcase {
  display: flex;
  align-items: center;
  gap: 20px;
}

.rn-hero-avatar-frame {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 2px solid var(--rn-gold);
  background: radial-gradient(circle, #3D2B55 0%, #1A0F26 100%);
  box-shadow: 0 0 20px rgba(217, 174, 88, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

#lobby-hero-avatar {
  border-radius: 50%;
}

/* Hero Collection Card Gallery */
.rn-hero-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: var(--rn-card-radius);
  background: linear-gradient(180deg, var(--rn-plum-surface) 0%, rgba(26, 17, 39, 0.95) 100%);
  border: 1px solid var(--rn-gold-hairline);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.rn-hero-card:hover {
  transform: translateY(-4px);
  border-color: var(--rn-gold);
  box-shadow: 0 12px 30px rgba(10, 5, 18, 0.9);
}

.rn-hero-card.active-vanguard {
  border: 2px solid var(--rn-gold);
  box-shadow: 0 0 24px rgba(217, 174, 88, 0.3);
}

.rn-hero-canvas-wrap {
  background: radial-gradient(circle at 50% 60%, rgba(183, 163, 232, 0.15) 0%, rgba(21, 13, 31, 0.8) 75%);
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-bottom: 1px solid rgba(217, 174, 88, 0.15);
}

.rn-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 5px;
}

.rn-stat-bar-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 2px;
}

.rn-stat-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--rn-gold) 0%, var(--rn-gold-light) 100%);
}

/* World Map Territory Cards */
.rn-territory-card {
  background: var(--rn-plum-surface);
  border: 1px solid var(--rn-gold-hairline);
  border-radius: var(--rn-card-radius);
  padding: 22px;
  margin-bottom: 18px;
  transition: all 0.2s ease;
  position: relative;
}

.rn-territory-card:hover {
  border-color: var(--rn-gold);
  transform: translateX(3px);
}

.rn-territory-card.conquered {
  border-color: rgba(40, 107, 84, 0.6);
  background: linear-gradient(90deg, rgba(40, 107, 84, 0.12) 0%, var(--rn-plum-surface) 100%);
}

.rn-territory-card.locked {
  opacity: 0.6;
  filter: grayscale(40%);
}

/* Modals */
.royal-modal .modal-content {
  background: #1C1227;
  border: 1px solid var(--rn-gold);
  border-radius: 14px;
  color: var(--rn-ivory);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.9);
  overflow: hidden;
}

.royal-modal .modal-header {
  border-bottom: 1px solid var(--rn-gold-hairline);
  background: var(--rn-plum-surface);
  padding: 16px 24px;
}

.royal-modal .modal-body {
  padding: 24px;
}

.royal-modal .modal-footer {
  border-top: 1px solid var(--rn-gold-hairline);
  background: var(--rn-plum-surface);
  padding: 14px 24px;
}

/* Tactical Battlefield HUD */
.rn-battle-hud {
  background: rgba(26, 17, 39, 0.95);
  border: 1px solid var(--rn-gold-hairline);
  border-radius: var(--rn-card-radius);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

/* Pulse Gold */
.pulse-gold {
  animation: rnPulseGold 2.2s infinite;
}

@keyframes rnPulseGold {
  0% { box-shadow: 0 0 0 0 rgba(217, 174, 88, 0.7); }
  70% { box-shadow: 0 0 0 12px rgba(217, 174, 88, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 174, 88, 0); }
}

/* Toast Container */
#toast-container {
  position: fixed;
  top: 75px;
  right: 20px;
  z-index: 9999;
}

/* Table styling for Leaderboard */
.table {
  color: var(--rn-ivory);
}

.table-dark {
  --bs-table-bg: var(--rn-plum-surface);
  --bs-table-border-color: rgba(217, 174, 88, 0.15);
}

/* Mobile Responsiveness */
@media (max-width: 991px) {
  .rn-sidebar {
    display: none;
  }

  .rn-shell {
    min-height: calc(100vh - 64px);
  }

  .rn-content-area {
    padding: 24px 20px;
  }

  .rn-topbar {
    height: auto;
    min-height: 64px;
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 10px 16px;
  }

  .rn-topbar > .d-flex:first-child {
    min-width: 0;
  }

  .rn-brand-mark {
    min-width: 0;
  }

  .rn-brand-mark > div:last-child {
    min-width: 0;
  }

  .rn-brand-mark .fs-5 {
    font-size: clamp(0.82rem, 2.8vw, 1.25rem) !important;
    white-space: nowrap;
  }

  .rn-resource-strip {
    flex: 1 0 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    gap: 6px;
    min-width: 0;
  }

  .rn-resource-item {
    justify-content: center;
    min-width: 0;
    font-size: 0.76rem;
    padding: 5px 6px;
    white-space: nowrap;
  }

  .rn-resource-item .icon {
    font-size: 0.9rem;
  }

  .rn-hero-showcase {
    gap: 14px;
  }

  .rn-hero-showcase h4 {
    overflow-wrap: anywhere;
  }

  .game-screen > .d-flex.justify-content-between {
    align-items: flex-start !important;
    flex-wrap: wrap;
    gap: 12px;
  }

  .rn-card-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .rn-battle-hud {
    padding: 12px;
  }
}

@media (max-width: 575px) {
  .rn-content-area {
    padding: 18px 12px;
  }

  .rn-topbar {
    padding: 10px 12px;
  }

  .rn-topbar > .d-flex:first-child {
    gap: 8px !important;
    width: 100%;
  }

  .rn-brand-icon {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
  }

  .rn-brand-mark {
    gap: 8px;
  }

  .rn-brand-mark .text-uppercase {
    font-size: 0.56rem !important;
  }

  .rn-resource-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  }

  .rn-resource-item.rank-pill {
    grid-column: span 2;
  }

  .rn-hero-showcase {
    align-items: flex-start;
  }

  .rn-hero-avatar-frame {
    width: 76px;
    height: 76px;
  }

  .rn-hero-showcase .d-flex.align-items-center.gap-2 {
    flex-wrap: wrap;
  }

  .rn-card-header {
    padding: 12px;
  }

  .rn-card-body,
  .royal-modal .modal-body {
    padding: 16px;
  }

  .game-screen h2 {
    font-size: 1.35rem;
  }

  .rn-battle-hud > .d-flex:last-child {
    width: 100%;
    flex-wrap: wrap;
  }

  .rn-battle-hud > .d-flex:last-child .btn {
    flex: 1 1 auto;
  }

  .game-screen .btn {
    white-space: normal;
  }

  .game-screen .d-flex.justify-content-center.gap-3 {
    flex-wrap: wrap;
  }

  .game-screen .d-flex.justify-content-center.gap-3 > .btn {
    flex: 1 1 180px;
  }

  #toast-container {
    left: 12px;
    right: 12px;
  }

  #toast-container .toast {
    width: 100%;
  }

  .modal-dialog {
    margin: 0.5rem;
  }
}

@media (min-width: 992px) {
  .navbar-toggler {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
