:root {
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --bg-color: #0f172a;
  --card-bg: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --success: #22c55e;
  --danger: #ef4444;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --dashboard-panel-height: min(70vh, 720px);
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  background-image: radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%), radial-gradient(at 100% 100%, rgba(37, 99, 235, 0.1) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

header {
  background-color: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(20px) saturate(200%);
  -webkit-backdrop-filter: blur(20px) saturate(200%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: all 0.3s ease;
}

header.scrolled {
  padding: 0.75rem 0;
  background-color: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(59, 130, 246, 0.3);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
}

header .container {
  display: flex;
  justify-content: flex-start; /* was space-between */
  align-items: center;
  flex-wrap: wrap; /* allow user-info to drop below on mobile */
  gap: 1rem;
}

.logo {
  font-size: 1.6rem;
  font-weight: 800;
  cursor: pointer;
  color: #ffffff;
  letter-spacing: -0.03em;
  transition: transform 0.2s ease, filter 0.2s ease;
  user-select: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.logo:hover {
  transform: scale(1.02);
  filter: drop-shadow(0 0 12px rgba(239, 68, 68, 0.5)) drop-shadow(0 0 12px rgba(59, 130, 246, 0.3));
}

/* Keep nav on the right on desktop; user-info will sit after it */
#main-nav {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-left: auto;
}

/* Ensure user-info aligns right on desktop */
.user-info {
  /* ...existing code... */
  margin-left: 0; /* default */
}

@media (min-width: 993px) {
  #user-info {
    margin-left: auto;
  }
}

/* Mobile: user-info should be visible and top-of-page (not in sidebar) */
@media (max-width: 992px) {
  #user-info {
    display: flex; /* explicit, in case JS/styles toggle */
    width: 100%;
    margin-left: 0;
    order: 10; /* ensure it wraps below the top row items */
  }

  .user-info {
    /* was: flex-direction: column; align-items: flex-start; ... */
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    width: 100%;
    gap: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
  }

  /* undo stacked-only "full width first row" rule */
  #game-mode-display {
    border-bottom: none;
    padding-bottom: 0;
    width: auto;
  }

  /* main-nav remains your slide-out sidebar per existing rules */
  /* ...existing code... */
}

/* Mobile Menu Toggle */
.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  z-index: 1001;
  padding: 5px;
  margin-left: auto;
}

.menu-toggle span {
  display: block;
  width: 25px;
  height: 3px;
  background-color: var(--text-main);
  border-radius: 3px;
  transition: all 0.3s ease;
}

.menu-toggle.active span:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

@media (max-width: 992px) {
  .menu-toggle {
    display: flex;
  }

  #main-nav {
    position: fixed;
    top: 0;
    right: -100%;
    width: 300px;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(20px);
    flex-direction: column;
    justify-content: flex-start;
    padding: 6rem 2rem 2rem;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    gap: 2.5rem;
  }

  #main-nav.active {
    right: 0;
  }

  .nav-links {
    flex-direction: column;
    width: 100%;
    gap: 1.5rem;
  }

  .nav-links a {
    font-size: 1.2rem;
    display: block;
    padding: 0.5rem 0;
  }

  .auth-buttons {
    flex-direction: column;
    width: 100%;
    gap: 1rem;
  }

  .auth-buttons button {
    width: 100%;
    padding: 0.8rem;
  }
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  list-style: none;
}

.nav-links a {
  color: var(--text-main);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  opacity: 0.8;
}

.nav-links a:hover {
  opacity: 1;
  color: var(--primary-color);
}

.nav-links a.active {
  opacity: 1;
  color: var(--primary-color);
  text-shadow: 0 0 15px rgba(37, 99, 235, 0.4);
}

.auth-buttons {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.auth-buttons button {
  padding: 0.6rem 1.4rem;
  font-size: 0.9rem;
  border-radius: 10px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.auth-buttons button.secondary {
  background: transparent;
  border: 1px solid var(--border-color);
}

.auth-buttons button.secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--text-muted);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  background: rgba(30, 41, 59, 0.6);
  padding: 0.6rem 1.25rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.02);
}

.user-info span {
  font-size: 0.95rem;
  font-weight: 700;
}

#balance-display {
  color: #4ade80; /* Brighter green */
  text-shadow: 0 0 10px rgba(74, 222, 128, 0.2);
}

#net-worth-display {
  color: var(--primary-color);
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.25);
}

#game-mode-display {
  color: var(--text-main);
  opacity: 0.9;
  width: auto; /* <- was 100%, causing wrap */
  border-bottom: none; /* <- was forcing "row" feel */
  padding-bottom: 0; /* <- remove desktop spacing */
}

/* Header user-info: leaderboard rank */
#leaderboard-rank-display {
  color: var(--danger);
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.25);
}

/* Landing Page Styles */
#landing-page {
  padding-top: 1rem;
}

.hero {
  text-align: center;
  padding: clamp(2rem, 8vw, 6rem) 0 clamp(1.25rem, 5vw, 4rem) 0;
  max-width: 900px;
  margin: 0 auto;
}

.hero h1 {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 800;
  margin-bottom: clamp(0.75rem, 3vw, 1.5rem);
  line-height: 1.05;
  color: #fff;
  letter-spacing: -0.02em;
}

.gradient-stocks {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 50%, #1d4ed8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 10px rgba(37, 99, 235, 0.3));
}

.gradient-crypto {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 50%, #991b1b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 10px rgba(220, 38, 38, 0.3));
}

.hero p {
  font-size: 1.25rem;
  color: var(--text-muted);
  margin-bottom: clamp(1rem, 4vw, 3rem);
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.hero-btns {
  display: flex;
  justify-content: center;
  gap: clamp(0.75rem, 3vw, 1.25rem);
}

.large-btn {
  padding: 1rem 2.5rem;
  font-size: 1.1rem;
  border-radius: 12px;
  box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
  transition: all 0.2s;
}

.large-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 25px -5px rgba(37, 99, 235, 0.4);
}

.large-btn.secondary {
  background-color: transparent;
  border: 1px solid var(--border-color);
  box-shadow: none;
}

.large-btn.secondary:hover {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: var(--text-muted);
}

.market-preview {
  margin: clamp(2rem, 6vw, 6rem) 0;
  background: rgba(30, 41, 59, 0.4);
  padding: clamp(1.25rem, 4vw, 3rem);
  border-radius: clamp(16px, 4vw, 32px);
  border: 1px solid var(--border-color);
}

.market-preview h2 {
  text-align: center;
  margin-bottom: clamp(1rem, 4vw, 3rem);
  font-size: 2rem;
  font-weight: 700;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: clamp(0.75rem, 3vw, 1.5rem);
}

@media (max-width: 1200px) {
  .preview-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 900px) {
  .preview-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

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

.asset-card-mini {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  border-radius: 20px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 120px;
}

.asset-card-mini:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 20px -5px rgba(0, 0, 0, 0.3);
  border-color: var(--primary-color);
}

.asset-card-mini::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-color, var(--primary-color));
  opacity: 0.8;
}

.asset-name-mini {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 2px;
}

.asset-symbol-mini {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.asset-price-mini {
  font-size: 1.5rem;
  font-weight: 800;
  margin-top: 1rem;
}

.features-section {
  padding: clamp(2rem, 6vw, 6rem) 0;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0) 0%, rgba(30, 41, 59, 0.4) 100%);
  border-radius: 48px;
  margin-bottom: clamp(2rem, 6vw, 6rem);
  border: 1px solid var(--border-color);
}

.features-section h2 {
  text-align: center;
  margin-bottom: clamp(1.25rem, 5vw, 4rem);
  font-size: 2.5rem;
  font-weight: 800;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: clamp(1rem, 4vw, 2.5rem);
  padding: 0 clamp(1rem, 4vw, 2rem);
}

@media (max-width: 992px) {
  .features-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .features-grid {
    grid-template-columns: 1fr;
  }
  .hero h1 {
    font-size: 3rem;
  }
  .market-preview {
    padding: 1.5rem;
  }
}

.feature-card {
  text-align: left;
  padding: 2.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  transition: all 0.3s;
}

.feature-card:hover {
  border-color: var(--primary-color);
  transform: translateY(-5px);
}

.feature-icon {
  font-size: 2.5rem;
  margin-bottom: 1.5rem;
  background: var(--accent-glow);
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
}

.feature-card h3 {
  margin-bottom: 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.feature-card p {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.6;
}

/* Setup Section Styles */
.setup-container {
  display: flex;
  flex-direction: column;
  gap: 3rem;
  max-width: 1000px;
  margin: 4rem auto;
  min-height: calc(100vh - 200px);
  justify-content: center;
}

.setup-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.setup-header h2 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.setup-header p {
  color: var(--text-muted);
}

.new-game,
.existing-games {
  width: 100%;
}

.new-game-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2rem;
}

.mode-card {
  padding: 2.5rem 2rem;
  border-radius: 24px;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.mode-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  border-color: var(--primary-color);
}

.mode-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.mode-card h3 {
  margin-bottom: 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.mode-card p {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  flex-grow: 1;
}

.mode-card ul {
  list-style: none;
  margin-bottom: 1.5rem;
  padding: 0;
  text-align: left;
  display: inline-block;
  margin-left: auto;
  margin-right: auto;
}

.mode-card li {
  font-size: 0.9rem;
  color: var(--text-main);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
}

.mode-card li::before {
  content: "✓";
  color: var(--success);
  margin-right: 12px;
  font-weight: bold;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.5rem;
}

.game-item {
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  background-color: var(--card-bg);
  border-radius: 20px;
  border: 1px solid var(--border-color);
  border-top: 4px solid var(--accent-color, var(--border-color));
  transition: all 0.3s;
  gap: 1.25rem;
}

.game-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 20px -5px rgba(0, 0, 0, 0.2);
  border-color: var(--primary-color);
}

.game-header-mini {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.game-item .continue-btn {
  width: 100%;
  margin-top: 0;
  padding: 0.75rem 1rem;
}

@media (max-width: 900px) {
  .new-game-options {
    grid-template-columns: 1fr;
  }
  .setup-container {
    gap: 3rem;
  }
  .mode-card {
    padding: 2rem 1.5rem;
  }
}

/* Inline Create Game Form */
.create-game-section {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.6) 0%, rgba(30, 41, 59, 0.4) 100%);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 2.5rem;
  position: relative;
  overflow: hidden;
}

.create-game-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-color) 0%, var(--danger) 100%);
  opacity: 0.8;
}

.inline-create-form {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.form-row .full-width {
  grid-column: 1 / -1;
}

.form-group-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-group label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.label-text {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
}

.label-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.9rem 1.2rem;
  font-size: 1rem;
  color: var(--text-main);
  transition: all 0.2s ease;
  font-family: inherit;
}

.form-group input[type="text"]:focus,
.form-group input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-color);
  background: rgba(15, 23, 42, 0.8);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.game-type-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.type-option {
  cursor: pointer;
}

.type-option input[type="radio"] {
  display: none;
}

.type-card {
  background: rgba(15, 23, 42, 0.6);
  border: 2px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
}

.type-card:hover {
  border-color: var(--text-muted);
  background: rgba(15, 23, 42, 0.8);
  transform: translateY(-2px);
}

.type-option input[type="radio"]:checked + .type-card {
  border-color: var(--primary-color);
  background: rgba(59, 130, 246, 0.1);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.type-option[data-type="multi"] input[type="radio"]:checked + .type-card {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.type-icon {
  font-size: 2rem;
  line-height: 1;
}

.type-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.form-actions {
  display: flex;
  justify-content: center;
  padding-top: 1rem;
}

.create-game-btn {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
  color: white;
  border: none;
  padding: 1.1rem 3rem;
  border-radius: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 10px 25px -5px rgba(59, 130, 246, 0.4);
  position: relative;
  overflow: hidden;
}

.create-game-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.create-game-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 30px -5px rgba(59, 130, 246, 0.5);
}

.create-game-btn:hover::before {
  left: 100%;
}

.create-game-btn:active {
  transform: translateY(-1px);
}

.create-game-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.btn-text {
  line-height: 1;
}

.form-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  color: var(--danger);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: center;
  margin-top: -0.5rem;
}

/* Mobile responsiveness for inline form */
@media (max-width: 768px) {
  .create-game-section {
    padding: 2rem 1.5rem;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .game-type-selector {
    gap: 0.75rem;
  }

  .type-card {
    padding: 1.25rem 0.75rem;
  }

  .create-game-btn {
    width: 100%;
    justify-content: center;
    padding: 1rem 2rem;
  }
}

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

/* Header user-info: add net worth styling + clean separators for 3 fields */
#net-worth-display {
  color: var(--primary-color);
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.25);
}

/* Override the old single border-right approach with consistent separators */
#game-mode-display {
  border-right: none;
  padding-right: 0;
}

.user-info span + span {
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  padding-left: 1.25rem;
}

/* Mobile: 2-column user-info shouldn’t show left borders */
@media (max-width: 992px) {
  .user-info span + span {
    border-left: none;
    padding-left: 0;
  }

  /* remove stacked behavior (it conflicts with 2-column layout) */
  #game-mode-display {
    border-bottom: none;
    padding-bottom: 0;
    width: auto;
  }
}

.text-muted {
  color: var(--text-muted);
}

main {
  padding: 2rem 0;
}

section {
  margin-bottom: 2rem;
}

/* Game interface: stack child blocks with consistent vertical spacing */
#game-interface {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  /* Match existing vertical rhythm between header and content */
  margin-top: 2rem;
}

h2 {
  margin-bottom: 1.5rem;
  font-size: 1.25rem;
}

/* Setup buttons */
.setup-buttons {
  display: flex;
  gap: 1rem;
}

button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s;
}

button:hover {
  background-color: var(--primary-hover);
}

button.secondary {
  background-color: var(--border-color);
  color: var(--text-main);
}

/* Dashboard Layout */
.dashboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  margin-bottom: 0; /* spacing handled by #game-interface gap */
}

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

.portfolio-section {
  background-color: var(--card-bg);
  padding: 2rem;
  border-radius: 24px;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  /* Allow children to become scroll containers inside a grid/flex context */
  min-height: 0;
}

.portfolio-section .section-header {
  flex-shrink: 0;
}


/* Make portfolio list scroll within a fixed vertical space */
#portfolio-list {
  /* Ensure this can shrink inside the fixed-height portfolio-section */
  flex: 1 1 auto;
  min-height: 0;

  max-height: 600px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;

  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  align-content: start;
  /* Prevent grid rows from being squashed when space is tight */
  grid-auto-rows: minmax(min-content, max-content);
}

/* On smaller screens, keep scrolling but collapse to a single column */
@media (max-width: 900px) {
  #portfolio-list {
    grid-template-columns: 1fr;
  }
}

.featured-market-section {
  background: linear-gradient(135deg, var(--card-bg) 0%, rgba(30, 41, 59, 0.8) 100%);
  padding: 1.5rem;
  border-radius: 28px;
  border: 1.5px solid var(--border-color);
  box-shadow: 0 8px 32px -8px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow: visible;
  margin: 0; /* vertical spacing handled by #game-interface gap */
}

.search-market-section {
  background: linear-gradient(135deg, var(--card-bg) 0%, rgba(30, 41, 59, 0.8) 100%);
  padding: 1.5rem;
  border-radius: 28px;
  border: 1.5px solid var(--border-color);
  box-shadow: 0 8px 32px -8px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow: visible;
  margin: 0; /* vertical spacing handled by #game-interface gap */
}
}

.market-section {
  background: linear-gradient(135deg, var(--card-bg) 0%, rgba(30, 41, 59, 0.8) 100%);
  padding: 1.5rem;
  border-radius: 28px;
  border: 1.5px solid var(--border-color);
  box-shadow: 0 8px 32px -8px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow: visible;
}

/* Market section header */
.market-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.market-header-content h2 {
  margin-bottom: 0.5rem;
  font-size: 1.4rem;
}

.market-description {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.4;
}

.market-controls {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
  width: 100%;
  justify-content: space-between;
}

.search-bar {
  position: relative;
  width: 100%;
  min-width: 250px;
  flex: 1 1 auto;
}

.search-bar input {
  width: 100%;
  padding: 0.85rem 1.25rem;
  padding-left: 2.75rem;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.6);
  color: var(--text-main);
  transition: all 0.2s;
  font-size: 0.95rem;
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary-color);
  background: var(--card-bg);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-bar::before {
  content: "🔍";
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0.6;
}

/* Market Tabs */
.market-tabs {
  display: flex;
  gap: 0.75rem;
  background: rgba(30, 41, 59, 0.4);
  padding: 0.4rem;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.tab-btn {
  padding: 0.65rem 1.5rem;
  font-size: 0.9rem;
  border-radius: 10px;
  background-color: transparent;
  color: var(--text-muted);
  border: none;
  transition: all 0.2s ease;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  background-color: var(--primary-color);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.market-note {
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-style: italic;
}

@media (max-width: 900px) {
  .market-header-top {
    flex-direction: column;
    gap: 1.5rem;
  }

  .market-controls {
    flex-direction: column;
    width: 100%;
    justify-content: flex-start;
    align-items: stretch;
  }

  .market-tabs {
    width: auto;
    justify-content: flex-start;
  }

  .search-bar {
    max-width: 100%;
  }
}

@media (max-width: 600px) {
  .market-header-content h2 {
    font-size: 1.2rem;
  }

  .market-description {
    font-size: 0.85rem;
  }

  .search-bar input {
    padding: 0.75rem 1rem;
    padding-left: 2.5rem;
    font-size: 0.9rem;
  }

  .tab-btn {
    padding: 0.55rem 1.25rem;
    font-size: 0.85rem;
  }
}

/* Asset Grid (unified for crypto/stocks) - Dynamic 6-card showcase grid */
.market-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  align-items: stretch;
  align-content: start;
  grid-auto-rows: 1fr;
  max-height: max-content;
  grid-auto-flow: row;
  overflow: hidden;
}

.market-state {
  grid-column: 1 / -1;
  background: rgba(30, 41, 59, 0.5);
  border: 2px dashed var(--border-color);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  min-height: 200px;
  font-size: 1rem;
  font-weight: 500;
}

.market-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: market-spin 0.9s linear infinite;
}

.asset-card {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.05) 0%, rgba(30, 41, 59, 0.8) 100%);
  border: 1.5px solid var(--border-color);
  border-left: 4px solid var(--accent-color, var(--primary-color));
  padding: 1.2rem;
  border-radius: 16px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  height: 100%;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 15px -3px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.4s ease-out forwards;
  gap: 0.6rem;
}

.asset-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.asset-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
}

.asset-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 40px -8px rgba(59, 130, 246, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-color: var(--primary-color);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(37, 99, 235, 0.05) 100%);
}

.asset-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background: linear-gradient(90deg, var(--accent-color, var(--primary-color)), transparent);
  opacity: 1;
  transition: opacity 0.3s ease, height 0.3s ease;
}

.asset-card:hover::after {
  height: 6px;
  opacity: 1;
}

.asset-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  word-break: break-word;
  color: var(--text-main);
  margin: 0;
}

.asset-symbol {
  color: var(--text-main);
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
  font-weight: 600;
  background: var(--accent-color, var(--primary-color));
  opacity: 0.9;
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  max-width: fit-content;
}

.asset-price {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: auto;
  color: #ffffff;
  width: 100%;
  word-break: break-word;
}

@media (max-width: 1200px) {
  .market-section {
    padding: 1.5rem;
  }

  .market-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.9rem;
  }

  .asset-card {
    padding: 1.1rem;
  }

  .asset-price {
    font-size: 1.15rem;
  }
}

@media (max-width: 900px) {
  .market-section {
    gap: 1rem;
    padding: 1.25rem;
  }

  .market-header-top {
    flex-direction: column;
    gap: 0.8rem;
  }

  .market-header-content h2 {
    font-size: 1.1rem;
  }

  .market-controls {
    flex-direction: column;
    width: 100%;
    justify-content: flex-start;
  }

  .market-tabs {
    width: 100%;
    display: flex;
    gap: 0.4rem;
  }

  .search-bar {
    width: 100%;
    min-width: unset;
  }

  .market-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
  }

  .asset-card {
    padding: 1rem;
    border-radius: 14px;
  }

  .asset-name {
    font-size: 0.9rem;
  }

  .asset-price {
    font-size: 1.1rem;
  }
}

@media (max-width: 768px) {
  .market-section {
    padding: 1.25rem;
  }

  .market-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.7rem;
  }

  .asset-card {
    padding: 1rem;
  }

  .asset-price {
    font-size: 1.1rem;
  }
}

@media (max-width: 600px) {
  .market-section {
    padding: 1.25rem;
  }

  .market-header-top {
    flex-direction: column;
  }

  .market-header-content h2 {
    font-size: 1.1rem;
  }

  .market-description {
    font-size: 0.85rem;
  }

  .market-controls {
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
  }

  .market-tabs {
    width: 100%;
    gap: 0.4rem;
    display: flex;
  }

  .tab-btn {
    flex: 1;
    padding: 0.55rem 0.75rem;
    font-size: 0.8rem;
  }

  .search-bar {
    width: 100%;
    min-width: unset;
  }

  .search-bar input {
    padding: 0.7rem 1rem;
    padding-left: 2.4rem;
    font-size: 0.9rem;
  }

  .market-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .asset-card {
    padding: 1rem;
    border-radius: 14px;
  }

  .asset-name {
    font-size: 0.95rem;
  }

  .asset-symbol {
    font-size: 0.75rem;
  }

  .asset-price {
    font-size: 1.1rem;
  }

  .price-change {
    font-size: 0.75rem;
  }
}

.portfolio-item {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1rem;
  margin-bottom: 0;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.8) 0%, var(--card-bg) 100%);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
  flex-shrink: 0;
}

.portfolio-item:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.portfolio-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 4px;
  background: var(--accent-color, var(--primary-color));
}

.portfolio-item:last-child {
  margin-bottom: 0;
}

.portfolio-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 0.5rem;
}

.portfolio-item-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.portfolio-asset-name {
  font-size: 0.95rem;
  color: var(--text-main);
}

.portfolio-symbol {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.portfolio-item-details {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-column {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.detail-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.detail-total {
  color: var(--primary-color);
  font-size: 0.9rem;
}

.portfolio-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.profit-loss-info {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
}

.profit-loss-info.positive {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
}

.profit-loss-info.negative {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.performance-badge {
  font-size: 0.7rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-weight: 700;
  white-space: nowrap;
}

.performance-badge.positive {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.performance-badge.negative {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

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

@media (max-width: 768px) {
  .portfolio-item-details {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .detail-label {
    font-size: 0.7rem;
  }

  .detail-value {
    font-size: 0.9rem;
  }
}

@media (max-width: 500px) {
  .portfolio-item {
    padding: 1rem;
    gap: 0.75rem;
  }

  .portfolio-item-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .portfolio-item-details {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    padding: 0.75rem 0;
  }

  .portfolio-item-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .sell-btn {
    width: 100%;
  }
}

.sell-summary {
  background: var(--bg-color);
  padding: 1rem;
  border-radius: 8px;
  margin: 1rem 0;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.summary-item:last-child {
  margin-bottom: 0;
}

.summary-item .highlight {
  font-weight: 700;
  color: var(--primary-color);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
}

.modal-content {
  background-color: var(--card-bg);
  margin: 2% auto;
  padding: 2.5rem;
  border-radius: 24px;
  width: 1000px;
  max-width: 95vw;
  max-height: 95vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-color);
}

.modal-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 2rem;
  margin-top: 1.5rem;
}

.modal-chart-container {
  background: var(--bg-color);
  border-radius: 16px;
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  height: 450px;
  display: flex;
  flex-direction: column;
}

.chart-intervals {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.interval-btn {
  padding: 4px 8px;
  font-size: 0.75rem;
  border-radius: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.interval-btn:hover {
  border-color: var(--text-muted);
}

.interval-btn.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
}

@media (max-width: 850px) {
  .modal-grid {
    grid-template-columns: 1fr;
  }
  .modal-content {
    width: 95%;
    margin: 2% auto;
    padding: 1.5rem;
    max-height: 96vh;
    overflow-y: auto;
  }
}

.modal-header-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-price-large {
  font-size: 2rem;
  font-weight: 800;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.modal-stat-card {
  background: var(--bg-color);
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  text-align: center;
}

.modal-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-stat-value {
  font-size: 1rem;
  font-weight: 700;
}

.close {
  position: absolute;
  right: 1.5rem;
  top: 1rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

#modal-body h2 {
  margin-bottom: 0.5rem;
}

.buy-input-group {
  margin: 1.5rem 0;
}

.buy-input-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.buy-input-group input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--bg-color);
  color: var(--text-main);
}

.total-cost {
  font-weight: 600;
  font-size: 1.25rem;
  margin-bottom: 2rem;
}

/* Subscription Section */
.subscription-section {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.8) 0%, rgba(30, 41, 59, 0.5) 100%);
  padding: 2rem;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  margin: 0; /* vertical spacing handled by #game-interface gap */
}

.subscription-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
}

.subscription-content {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.subscription-icon {
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background: rgba(34, 197, 94, 0.1);
  border-radius: 16px;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.subscription-info h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.subscription-tier {
  margin: 0;
  color: var(--text-muted);
}

.tier-badge {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
  padding: 0.35rem 0.85rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid rgba(34, 197, 94, 0.3);
  display: inline-block;
}

.upgrade-btn {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  border: none;
  padding: 0.85rem 2rem;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  white-space: nowrap;
}

.upgrade-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
}

.upgrade-btn:active {
  transform: translateY(0);
}

@media (max-width: 600px) {
  .subscription-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 1.5rem;
  }

  .upgrade-btn {
    width: 100%;
  }
}

/* Invites Section */
.invites-section {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.invites-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
}

.invites-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

.invites-icon {
  font-size: 2rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 12px;
}

.invites-info h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.invites-description {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.invites-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.invite-link-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.invite-link-input {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  color: var(--text-main);
  font-size: 0.9rem;
  width: 300px;
  outline: none;
  transition: all 0.2s ease;
}

.invite-link-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.copy-invite-btn,
.make-multi-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.copy-invite-btn:hover,
.make-multi-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.copy-invite-btn:active,
.make-multi-btn:active {
  transform: translateY(0);
}

.copy-invite-btn:disabled,
.make-multi-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 768px) {
  .invites-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 1.5rem;
  }

  .invites-actions {
    width: 100%;
  }

  .invite-link-container {
    flex-direction: column;
    width: 100%;
    gap: 1rem;
  }

  .invite-link-input {
    width: 100%;
  }

  .copy-invite-btn,
  .make-multi-btn {
    width: 100%;
    justify-content: center;
    padding: 1rem;
  }
}

/* Stats Container */
.stats-container {
  margin: 0; /* vertical spacing handled by #game-interface gap */
}

.chart-card {
  background-color: var(--card-bg);
  padding: 2rem;
  border-radius: 24px;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.section-header {
  margin-bottom: 2rem;
}

.section-header h2 {
  margin-bottom: 0.5rem;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
}

.section-description {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.4;
}

canvas#balanceChart {
  max-height: 300px;
  width: 100% !important;
}

/* Price Badges */
.price-change {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 700;
}

.price-change.positive {
  background-color: rgba(34, 197, 94, 0.1);
  color: var(--success);
}

.price-change.negative {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.price-change::before {
  margin-right: 2px;
}

.price-change.positive::before {
  content: "▲";
}

.price-change.negative::before {
  content: "▼";
}

.asset-card {
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s;
  background: var(--card-bg);
  position: relative;
  overflow: hidden;
  animation: fadeIn 0.4s ease-out forwards;
}

.asset-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.5);
  border-color: var(--primary-color);
}

.asset-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-color, var(--primary-color));
}

/* Mobile responsiveness for common elements */
@media (max-width: 768px) {
  .container {
    padding: 0 15px;
  }

  .hero {
    padding: 4rem 0 2rem 0;
  }

  .hero h1 {
    font-size: 2.25rem;
    line-height: 1.2;
  }

  .gradient-stocks,
  .gradient-crypto {
    display: inline-block;
  }

  .hero-btns {
    flex-direction: column;
    gap: 1rem;
  }

  .large-btn {
    width: 100%;
    padding: 0.8rem 1.5rem;
  }

  .features-section {
    padding: 4rem 0;
    margin-bottom: 3rem;
  }

  .features-section h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
  }

  .market-preview h2 {
    font-size: 1.5rem;
    margin-bottom: 2rem;
  }

  /* Dashboard mobile fixes */
  .market-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .market-tabs {
    margin: 0;
    justify-content: center;
  }

  .search-bar input {
    width: 100% !important;
  }

  .stats-container {
    margin: 0; /* keep mobile spacing consistent with #game-interface gap */
  }

  .chart-card {
    padding: 1.25rem;
  }

  canvas#balanceChart {
    max-height: 200px;
  }

  /* Modal mobile fixes */
  .modal-content {
    padding: 1.25rem;
    margin: 0;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    width: 100% !important;
    max-width: 100vw !important;
  }

  .modal-header-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .modal-header-info div:last-child {
    text-align: left !important;
  }

  .modal-price-large {
    font-size: 1.75rem;
  }

  .modal-chart-container {
    height: 300px;
    padding: 1rem;
  }

  .chart-intervals {
    overflow-x: auto;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
  }

  .interval-btn {
    flex-shrink: 0;
  }

  .modal-stats {
    grid-template-columns: 1fr 1fr;
  }

  .modal-stat-card:last-child {
    grid-column: span 2;
  }

  .buy-input-group {
    margin: 1rem 0;
  }

  .total-cost {
    margin-bottom: 1.5rem;
  }

  /* Auth card on mobile */
  .auth-card {
    padding: 2rem 1.5rem;
    border-radius: 24px;
  }

  .new-game-options {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .mode-card {
    padding: 1.5rem;
  }

  .mode-card h3 {
    font-size: 1.25rem;
  }

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

  .auth-header h2 {
    font-size: 1.75rem;
  }
}

/* Desktop only: lock both panels to the same height so neither can expand the row */
@media (min-width: 901px) {
  .portfolio-section,
  .market-section {
    height: var(--dashboard-panel-height);
    overflow: hidden; /* prevent content from increasing panel height */
    min-height: 0;
  }

  .market-section {
    display: flex;
    flex-direction: column;
  }

  /* Market grid should not scroll */
  .market-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.asset-card,
.portfolio-item,
.chart-card {
  animation: fadeIn 0.4s ease-out forwards;
}

.modal-badge {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.12), rgba(37, 99, 235, 0.08));
  color: var(--primary-color);
  border: 1px solid rgba(59, 130, 246, 0.12);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: capitalize;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.06);
}

.modal-form .modal-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 600;
  color: var(--text-main);
}

.modal-form .modal-field input[type="text"],
.modal-form .modal-field input[type="number"] {
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-form .modal-field input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 6px var(--accent-glow);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.modal-actions button {
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  border: none;
}

.modal-actions button.secondary {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.modal-actions button#create-game-submit {
  background: linear-gradient(90deg, var(--primary-color), var(--primary-hover));
  color: white;
  box-shadow: 0 10px 25px rgba(59, 130, 246, 0.18);
  transition: transform 0.12s ease;
}

.modal-actions button#create-game-submit:active {
  transform: translateY(1px);
}

/* Create Game Modal (polished) */
#create-game-modal .modal-content {
  background: radial-gradient(circle at 20% 20%, rgba(59, 130, 246, 0.06), transparent 35%), radial-gradient(circle at 80% 0%, rgba(239, 68, 68, 0.04), transparent 30%), var(--card-bg);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 25px 60px -20px rgba(0, 0, 0, 0.55);
}

#create-game-modal .modal-content::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(120deg, rgba(59, 130, 246, 0.35), rgba(239, 68, 68, 0.25), rgba(59, 130, 246, 0.2));
  mask: linear-gradient(#000, #000) content-box, linear-gradient(#000, #000);
  -webkit-mask: linear-gradient(#000, #000) content-box, linear-gradient(#000, #000);
  mask-composite: exclude;
  -webkit-mask-composite: destination-out;
  pointer-events: none;
}

.create-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-header-text {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.modal-highlight-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-size: 0.85rem;
}

#create-game-modal .modal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 1.25rem;
  backdrop-filter: blur(6px);
}

.modal-summary {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.summary-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.summary-value {
  color: var(--text-main);
  font-weight: 800;
}

.summary-dot {
  color: var(--border-color);
}

.field-helper {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.form-note {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Leaderboard (Game page) */
.leaderboard-section {
  margin-top: 2rem;
}

.leaderboard-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 2rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.leaderboard-meta {
  font-weight: 700;
  opacity: 0.9;
  white-space: nowrap;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
}

.leaderboard-row.is-me {
  border-color: rgba(59, 130, 246, 0.35);
  box-shadow: inset 0 0 0 999px rgba(59, 130, 246, 0.06);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  font-weight: 800;
}

.leaderboard-name {
  font-weight: 800;
}

.leaderboard-sub {
  font-size: 0.85rem;
}

.leaderboard-value {
  font-weight: 900;
  color: #4ade80;
  text-shadow: 0 0 10px rgba(74, 222, 128, 0.15);
}

.leaderboard-empty {
  padding: 1rem;
  text-align: center;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 16px;
}

/* Mobile layout: stack value under name */
@media (max-width: 600px) {
  .leaderboard-card {
    padding: 1.25rem;
  }

  .leaderboard-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .leaderboard-row {
    grid-template-columns: 48px 1fr auto;
    align-items: center;
  }

  .leaderboard-value {
    align-self: center;
  }
}
