:root {
  --bg-mint: #eef8eb;
  --purple-primary: #8c52ff;
  --green-primary: #71c558;
  --text-dark: #1e1e1e;
  --card-bg: #ffffff;
  --border-light: #e0e6ed;
  --red-accent: #e74c3c;
}

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

html {
  -webkit-text-size-adjust: 100%;
  font-family: 'Lexend', sans-serif;
}

body,
button,
input,
select,
textarea {
  font-family: 'Lexend', sans-serif;
}

body {
  background-color: var(--bg-mint);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 40px;
}

.app-header {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  box-sizing: border-box;
}

/* Homepage state: Auto margins center the logo */
.app-logo {
  width: 400px;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  margin: 0 auto;
}

.app-logo-compact {
  width: 80px;
  max-width: 80px;
  height: auto;
}

/* In-game state: Hide logo entirely */
.app-header.game-started .app-logo {
  display: none !important;
}

@media (max-width: 600px) {
  .app-logo {
    width: min(400px, 88vw);
    height: auto;
  }

  .app-logo-compact {
    width: 80px;
    max-width: 80px;
  }
}

/* Countdown overlay */
.countdown-overlay {
  position: fixed;
  left: 0; top: 0; right: 0; bottom: 0;
  display:flex; align-items:center; justify-content:center;
  background: rgba(0,0,0,0.45);
  z-index: 2500;
}
.countdown-number {
  color: #fff;
  font-size: 8rem;
  font-weight: 800;
  text-shadow: 0 8px 30px rgba(0,0,0,0.6);
  transform: scale(1);
  animation: pop 900ms ease forwards;
}
@keyframes pop { 0% { transform: scale(0.6); opacity:0 } 50% { transform: scale(1.1); opacity:1 } 100% { transform: scale(1); opacity:1 } }

/* Fade-in animation for market and results */
.fade-in { animation: fadeInUp 700ms ease forwards; opacity:0; }
@keyframes fadeInUp { from { opacity:0; transform: translateY(8px);} to { opacity:1; transform: translateY(0);} }
.results-section-hidden { opacity: 0; transform: translateY(10px); }
.results-section-visible { opacity: 1; transform: translateY(0); transition: opacity 2s ease, transform 2s ease; }
.results-summary-hidden { opacity: 0; transform: translateY(10px); }
.results-summary-visible { opacity: 1; transform: translateY(0); transition: opacity 2s ease, transform 2s ease; }
.results-header-hidden { opacity: 0; transform: translateY(8px); }
.results-header-visible { opacity: 1; transform: translateY(0); transition: opacity 1.2s ease, transform 1.2s ease; }

h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-dark);
}

.container {
  width: 100%;
  max-width: 900px;
  padding: 0 15px;
}

.card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
  margin-top: 10px;
}

.text-center { text-align: center; }
.hidden { display: none !important; }
.mt-15 { margin-top: 15px; }
.uppercase { text-transform: uppercase; }

/* Buttons */
.btn {
  padding: 12px 24px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-link { background: transparent; color: var(--purple-primary); padding: 8px 10px; font-weight: 600; border-radius: 6px; }
.btn-link:hover { background: rgba(140,82,255,0.06); }

.btn-purple { background-color: var(--purple-primary); color: #fff; }
.btn-purple:hover { background-color: #793df3; }

.btn-green { background-color: var(--green-primary); color: #fff; }
.btn-green:hover { background-color: #5fb247; }

.btn-gray { background-color: #e2e8f0; color: #4a5568; }

.btn-full { width: 100%; max-width: 400px; display: block;}

/* Form inputs */
.input-field {
  width: 100%;
  max-width: 400px;
  padding: 12px;
  margin: 8px 0;
  border: 2px solid var(--border-light);
  border-radius: 10px;
  font-size: 1rem;
  display: block;
}

.input-field:focus {
  outline: none;
  border-color: var(--purple-primary);
}

/* Home Layout */
.home-actions {
  display: flex;
  flex-direction: column;
  align-items: center; /* Centers child cards/boxes horizontally */
  justify-content: center; /* Centers items vertically if container has set height */
  text-align: center;
  gap: 20px;
  margin-top: 25px;
}

.action-box {
  display: flex;
  flex-direction: column;
  align-items: center; /* Centers inputs and button horizontally */
  text-align: center;
  width: 100%;
  max-width: 400px; /* Adjust as needed */
  margin: 0 auto;   /* Ensures box itself stays centered */
}

@media (min-width: 650px) {
  .home-actions { flex-direction: row; align-items: center; }
  .action-box { flex: 1; }
}

.divider { font-weight: 700; color: #a0aec0; }

/* Question Cards */
.quiz-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--bg-mint);
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 20px;
}
@media (min-width: 600px) {
  .options-grid { grid-template-columns: 1fr 1fr; }
}

.option-card {
  padding: 16px;
  border: 2px solid var(--border-light);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 500;
  background: #fff;
  transition: border-color 0.2s;
}

.option-card:hover { border-color: var(--purple-primary); }
.option-card.correct { border-color: var(--green-primary); background-color: #eafaf1; color: #27ae60; font-weight: 700; }
.option-card.wrong { border-color: var(--red-accent); background-color: #fdf2f2; color: var(--red-accent); }

/* Ensure option text color remains readable */


.feedback-box {
  margin-top: 20px;
  padding: 15px;
  border-radius: 10px;
  background-color: var(--bg-mint);
  text-align: center;
}

/* Allocation Phase */
.allocation-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
  margin: 16px 0 10px;
}
@media (min-width: 600px) {
  .allocation-grid { grid-template-columns: 1fr 1fr; }
}

.asset-card {
  border: 2px solid var(--border-light);
  border-radius: 12px;
  padding: 12px;
  background: #fcfdff;
}
.asset-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.asset-desc { font-size: 0.85rem; color: #718096; margin-bottom: 8px; }
.allocation-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.allocation-pill {
  border: 1px solid var(--border-light);
  background: #fff;
  color: var(--text-dark);
  border-radius: 999px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.allocation-pill small {
  font-size: 0.74rem;
  color: #64748b;
}
.allocation-pill.active {
  background: linear-gradient(135deg, var(--purple-primary), #9f7aea);
  color: #fff;
  border-color: var(--purple-primary);
}
.allocation-pill.active small {
  color: rgba(255,255,255,0.85);
}
.asset-amount-display {
  margin-top: 10px;
  font-weight: 700;
  color: var(--green-primary);
}

/* Allocation input smaller for compact view */
.alloc-input { max-width: 120px; }

/* Quick-fill buttons for allocation */
.alloc-quickfills { display:flex; gap:6px; margin-top:8px; }
.alloc-quickfills .btn { padding:6px 8px; font-size:0.85rem; border-radius:8px; }

.asset-row { display:flex; align-items:center; gap:8px; }
.asset-row .input-field { flex: 1; }
.asset-row .alloc-quickfills { margin-top:0; flex-wrap:wrap; }

/* Keep total allocated visible on small screens */
.alloc-summary { position: sticky; bottom: 12px; }

/* Make results table scroll horizontally on small screens */
.personal-results-box { overflow-x: auto; }

/* Add spacing above portfolio performance */
.personal-results-box { margin-top: 6px; padding-top: 0; }

/* Confetti container */
.confetti-canvas { position: fixed; left:0; top:0; width:100%; height:100%; pointer-events:none; z-index:2000; }

/* Home adjustments */
.main-join h3 { margin-bottom: 8px; }
.large-join { padding: 18px; font-size:1.1rem; border-radius:14px; }
.admin-link-box { display:flex; align-items:center; justify-content:center; }

.header-actions {
  display: flex;
  align-items: center;
}

.balance-pill,
.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 17px;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  border-radius: 999px;     /* Matching pill shape */
  box-sizing: border-box;
}

#global-leaderboard-btn {
  font-size: 0.97rem;
}

.balance-pill {
  background: linear-gradient(135deg, var(--green-primary), #a7e36a);
  color: #fff;
  box-shadow: 0 8px 18px rgba(113, 197, 88, 0.18);
}

.balance-pill-icon {
  font-size: 0.95rem;
}

.quiz-preview-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}
.quiz-preview-item:last-child { border-bottom: none; }
.quiz-preview-item ul { margin-top: 8px; padding-left: 18px; }
.quiz-preview-item li { margin-bottom: 6px; }
.quiz-answer-correct { color: var(--green-primary); font-weight: 600; }

.admin-link-below { margin-top: 12px; text-align: center; }
.admin-link-below .btn-link { font-size: 0.95rem; }

.fade-in-slow { animation: fadeInUp 1400ms ease forwards; opacity:0; }

.game-journey-card {
  margin-top: 20px;
  padding: 16px;
  border-radius: 14px;
  background: var(--bg-mint);
  border: 1px solid rgba(140, 82, 255, 0.16);
}

.lobby-quiz-complete .lobby-status-block {
  margin-bottom: 56px;
}
.game-journey-card h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}
.journey-grid {
  display: grid;
  gap: 10px;
}
@media (min-width: 640px) {
  .journey-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.journey-step {
  text-align: left;
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  border: 1px solid var(--border-light);
}
.journey-step h4 {
  margin-bottom: 6px;
  font-size: 0.95rem;
  color: var(--purple-primary);
}
.journey-step p {
  font-size: 0.92rem;
  color: #4a5568;
}

@media (max-width: 480px) {
  .asset-desc { display: none; }
  .alloc-input { max-width: 100px; }
  .alloc-summary { font-size: 0.95rem; }
}

.alloc-summary {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-mint);
  border-radius: 10px;
  margin-top: 10px;
}
.alloc-summary strong {
  font-size: 1.1rem;
}
#total-allocated-value {
  color: var(--green-primary);
}
.alloc-summary-label {
  display: block;
}
.alloc-summary.over-allocated {
  border: 1px solid rgba(231, 76, 60, 0.35);
  box-shadow: inset 0 0 0 1px rgba(231, 76, 60, 0.2);
}

.alloc-submitted-view {
  margin-top: 10px;
  padding: 18px 14px;
  text-align: center;
}

.alloc-submitted-message {
  font-size: 1.02rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: #334155;
}

.alloc-submitted-card {
  border: 1px solid var(--border-light);
  border-radius: 12px;
  background: #f9fcff;
  padding: 14px;
  text-align: left;
}

.alloc-submitted-card h4 {
  margin-bottom: 10px;
}
.alloc-submitted-summary-grid {
  width: 100%;
  border-collapse: collapse;
}
.alloc-submitted-summary-grid td {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
}
.alloc-submitted-summary-grid td:last-child {
  text-align: right;
  font-weight: 600;
}

/* Data Tables */
.table-container { overflow-x: auto; margin-top: 15px; }
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th, .data-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}
.data-table th:nth-child(4), .data-table td:nth-child(4) { min-width: 120px; white-space: nowrap; }
.data-table th { background: #f8fafc; font-weight: 600; }

.market-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}
@media (min-width: 640px) {
  .market-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.market-card {
  background: var(--bg-mint);
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.market-card.positive { border: 2px solid rgba(113, 198, 88, 0.25); background: linear-gradient(180deg, rgba(114,197,89,0.06), transparent); color: var(--green-primary); }
.market-card.negative { border: 2px solid rgba(231,76,60,0.12); background: linear-gradient(180deg, rgba(231,76,60,0.04), transparent); color: var(--red-accent); }

.results-total-row {
  margin-top: 15px;
  width: 100%;
}
.results-quick-summary {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.results-outcome-block {
  margin-top: 42px;
}
.results-outcome-header {
  margin: 0 0 0;
  padding-top: 30px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #334155;
}
.results-quick-card {
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f6f8ff, #eef8eb);
  border: 1px solid rgba(140, 82, 255, 0.18);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}
.results-quick-card span {
  display: block;
  font-size: 0.9rem;
  color: #4a5568;
}
.results-quick-card strong {
  font-size: 1.2rem;
  color: var(--purple-primary);
}

.results-detail {
  margin-top: 14px;
}
.results-detail summary {
  cursor: pointer;
  font-weight: 600;
  color: #334155;
}
.results-outcome-block.results-summary-hidden,
.results-outcome-block.results-summary-visible {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 2s ease, transform 2s ease;
}
.results-outcome-block.results-summary-visible {
  opacity: 1;
  transform: translateY(0);
}
.results-total-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 16px;
  width: 100%;
  max-width: 100%;
  border-radius: 12px;
  background: linear-gradient(135deg, #f6f8ff, #eef8eb);
  border: 1px solid rgba(140, 82, 255, 0.18);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}
.results-total-card span {
  font-size: 0.9rem;
  color: #4a5568;
}
.results-total-card strong {
  font-size: 1.4rem;
  color: var(--purple-primary);
}

.results-actions {
  margin-top: 14px;
  padding-top: 30px;
  display: flex;
  gap: 10px;
  justify-content: center;
}

.admin-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.year-gain-positive {
  color: var(--green-primary);
  font-weight: 700;
}

.year-gain-negative {
  color: var(--red-accent);
  font-weight: 700;
}

.simulation-history-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Modals */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: white;
  padding: 24px;
  border-radius: 16px;
  max-width: 450px;
  width: 90%;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  text-align: center;
}
.modal-large { max-width: 700px; text-align: left; }

.live-games-list { list-style: none; }
.live-games-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  margin-bottom: 8px;
}

.asset-chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0 4px; font-size: 0.85rem; }
.asset-chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.asset-chart-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.close-btn { font-size: 1.5rem; border: none; background: none; cursor: pointer; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

.badge-code { font-family: monospace; font-size: 1.3rem; background: #edf2f7; padding: 2px 8px; border-radius: 6px; }
.admin-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.admin-status-bar { margin: 15px 0; padding: 10px; background: var(--bg-mint); border-radius: 8px; font-weight: 600; }
.pulse-loader { width: 12px; height: 12px; background: var(--purple-primary); border-radius: 50%; margin: 20px auto; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(2.5); opacity: 0.3; } 100% { transform: scale(1); opacity: 1; } }

@media (max-width: 640px) {
  body {
    padding-bottom: 0;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }

  .card {
    border-radius: 0;
    margin-top: 0;
    box-shadow: none;
  }

  .app-header {
    padding: 16px 10px;
  }
}