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

:root {
  --primary: #f59e0b;
  --secondary: #10b981;
  --accent: #8b5cf6;
  --gold: #fcd34d;
  --success: #10b981;
  --danger: #ef4444;
  --dark-bg: #1a1512;
  --card-bg: rgba(35, 25, 20, 0.95);
  --text: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.6);
}

body {
  font-family: 'Rajdhani', sans-serif;
  background: var(--dark-bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Background */
.bg-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
}

.bg-animation::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(
      ellipse at 30% 70%,
      rgba(245, 158, 11, 0.2) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at 70% 30%,
      rgba(16, 185, 129, 0.15) 0%,
      transparent 50%
    );
}

.gold-particles {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(
    circle,
    rgba(252, 211, 77, 0.4) 1px,
    transparent 1px
  );
  background-size: 60px 60px;
  animation: goldShimmer 3s ease-in-out infinite;
}

@keyframes goldShimmer {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.6;
  }
}

.coin-rain {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Screens */
.screen {
  display: none;
  min-height: 100vh;
  padding: 20px;
}

.screen.active {
  display: block;
  animation: fadeIn 0.5s ease-out;
}

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

/* Main Menu */
#main-menu {
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-content {
  text-align: center;
  max-width: 600px;
}

.logo-container {
  margin-bottom: 40px;
}

.logo-icon {
  font-size: 5rem;
  margin-bottom: 20px;
  animation: coinSpin 3s ease-in-out infinite;
}

@keyframes coinSpin {
  0%,
  100% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(180deg);
  }
}

.game-logo {
  font-family: 'Playfair Display', serif;
  font-size: 3.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 60px rgba(252, 211, 77, 0.5);
  letter-spacing: 4px;
}

.game-subtitle {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  color: var(--text-dim);
  margin-top: 10px;
  font-style: italic;
}

.player-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 50px;
  padding: 25px;
  background: var(--card-bg);
  border-radius: 16px;
  border: 2px solid rgba(252, 211, 77, 0.3);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.stat-icon {
  font-size: 1.5rem;
}

.stat-value {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gold);
}

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

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px 40px;
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 600;
  border: 2px solid var(--gold);
  border-radius: 12px;
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  transition: all 0.3s;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.menu-btn:hover {
  background: rgba(252, 211, 77, 0.1);
  transform: translateX(10px);
  box-shadow: 0 0 30px rgba(252, 211, 77, 0.3);
}

.menu-btn.primary {
  background: linear-gradient(135deg, var(--gold), var(--primary));
  border: none;
  color: #1a1512;
}

.menu-btn.primary:hover {
  transform: translateX(10px) scale(1.02);
}

/* Screen Header */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  margin-bottom: 30px;
  background: var(--card-bg);
  border-radius: 16px;
  border: 1px solid rgba(252, 211, 77, 0.2);
}

.screen-header h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  color: var(--gold);
}

.back-btn {
  padding: 10px 20px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.3s;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateX(-5px);
}

.gold-display {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--gold);
}

/* Empire Cards */
.empires-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 25px;
  max-width: 1200px;
  margin: 0 auto;
}

.empire-card {
  position: relative;
  padding: 30px;
  background: var(--card-bg);
  border-radius: 20px;
  border: 2px solid rgba(252, 211, 77, 0.2);
  cursor: pointer;
  transition: all 0.4s;
  overflow: hidden;
}

.empire-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(252, 211, 77, 0.05), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.empire-card:hover {
  transform: translateY(-10px);
  border-color: var(--gold);
  box-shadow: 0 20px 60px rgba(252, 211, 77, 0.3);
}

.empire-card:hover::before {
  opacity: 1;
}

.empire-crown {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 1.5rem;
  opacity: 0.3;
  transition: opacity 0.3s;
}

.empire-card:hover .empire-crown {
  opacity: 1;
}

.empire-icon {
  font-size: 3.5rem;
  margin-bottom: 15px;
}

.empire-card h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  color: var(--gold);
  margin-bottom: 10px;
}

.empire-card p {
  color: var(--text-dim);
  margin-bottom: 20px;
}

.empire-progress {
  display: flex;
  align-items: center;
  gap: 15px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--success));
  border-radius: 4px;
  transition: width 0.5s;
}

/* Quest Select */
.quests-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  max-width: 1000px;
  margin: 0 auto;
}

.quest-card {
  padding: 25px;
  background: var(--card-bg);
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
}

.quest-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.quest-card.completed {
  border-color: var(--success);
}

.quest-card.completed::after {
  content: '✓';
  position: absolute;
  top: 15px;
  right: 15px;
  width: 30px;
  height: 30px;
  background: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: #000;
}

.quest-card:not(.locked):hover {
  transform: translateY(-5px);
  border-color: var(--gold);
  box-shadow: 0 15px 40px rgba(252, 211, 77, 0.2);
}

.quest-number {
  font-family: 'Playfair Display', serif;
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--gold);
  opacity: 0.3;
  margin-bottom: 10px;
}

.quest-card h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.quest-card p {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.quest-gold {
  margin-top: 15px;
  font-family: 'Playfair Display', serif;
  font-size: 0.9rem;
  color: var(--gold);
}

/* Game Screen */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 25px;
  background: var(--card-bg);
  border-radius: 16px;
  margin-bottom: 25px;
}

.level-info h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  color: var(--gold);
}

.level-info p {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.game-stats {
  display: flex;
  gap: 25px;
}

.game-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
}

.game-content {
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Visualization Area */
.visualization-area {
  grid-column: 1 / -1;
  padding: 30px;
  background: var(--card-bg);
  border-radius: 16px;
  min-height: 300px;
}

/* Knapsack Visualization */
.knapsack-visual {
  display: flex;
  gap: 40px;
  align-items: flex-start;
  justify-content: center;
}

.knapsack-bag {
  width: 200px;
  height: 250px;
  background: linear-gradient(180deg, #4a3728, #2d221a);
  border-radius: 20px 20px 40px 40px;
  border: 4px solid #8b7355;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 20px;
  overflow: hidden;
}

.knapsack-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(180deg, var(--gold), #b8860b);
  transition: height 0.5s ease;
  border-radius: 0 0 36px 36px;
}

.knapsack-label {
  position: absolute;
  top: 10px;
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  color: var(--gold);
  z-index: 2;
}

.items-display {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: center;
}

.item-box {
  width: 100px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

.item-box:hover {
  border-color: var(--gold);
  transform: scale(1.05);
}

.item-box.selected {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.2);
}

.item-box.partial {
  border-color: var(--primary);
  background: rgba(245, 158, 11, 0.2);
}

.item-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.item-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  color: var(--gold);
}

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

.item-ratio {
  font-size: 0.8rem;
  color: var(--success);
  margin-top: 5px;
}

/* Timeline / Gantt Chart */
.timeline-container {
  grid-column: 1 / -1;
  padding: 25px;
  background: var(--card-bg);
  border-radius: 16px;
}

.timeline-container h3 {
  color: var(--gold);
  margin-bottom: 20px;
  font-family: 'Playfair Display', serif;
}

.timeline {
  position: relative;
  height: 200px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  overflow: hidden;
}

.timeline-axis {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 30px;
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.3);
}

.timeline-bar {
  position: absolute;
  height: 40px;
  background: linear-gradient(90deg, var(--gold), var(--primary));
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: #000;
  transition: all 0.3s;
  cursor: pointer;
}

.timeline-bar:hover {
  transform: scaleY(1.1);
  box-shadow: 0 5px 20px rgba(252, 211, 77, 0.4);
}

.timeline-bar.selected {
  background: linear-gradient(90deg, var(--success), #059669);
}

.timeline-bar.conflicting {
  background: linear-gradient(90deg, var(--danger), #dc2626);
}

/* Items Panel */
.items-panel {
  padding: 20px;
  background: var(--card-bg);
  border-radius: 16px;
}

.items-panel h3 {
  color: var(--gold);
  margin-bottom: 15px;
  font-family: 'Playfair Display', serif;
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.3s;
}

.item-row:hover {
  border-color: var(--gold);
}

.item-row.selected {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.1);
}

/* Selection Panel */
.selection-panel {
  padding: 20px;
  background: var(--card-bg);
  border-radius: 16px;
}

.selection-panel h3 {
  color: var(--gold);
  margin-bottom: 15px;
  font-family: 'Playfair Display', serif;
}

.selected-items {
  min-height: 100px;
  padding: 15px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  margin-bottom: 15px;
}

.selection-stats {
  padding: 15px;
  background: rgba(252, 211, 77, 0.1);
  border-radius: 10px;
}

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

.stat-row:last-child {
  margin-bottom: 0;
}

/* Action Panel */
.action-panel {
  grid-column: 1 / -1;
  padding: 25px;
  background: var(--card-bg);
  border-radius: 16px;
}

.action-prompt {
  text-align: center;
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: var(--gold);
  font-family: 'Playfair Display', serif;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.action-btn {
  padding: 15px 25px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  transition: all 0.3s;
}

.action-btn:hover {
  border-color: var(--gold);
  background: rgba(252, 211, 77, 0.1);
}

.action-btn.correct {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.2);
}

.action-btn.incorrect {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.2);
}

/* Message Log */
.message-log {
  grid-column: 1 / -1;
  max-height: 150px;
  overflow-y: auto;
  padding: 20px;
  background: var(--card-bg);
  border-radius: 12px;
}

.log-message {
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  font-size: 0.95rem;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.log-message.info {
  background: rgba(245, 158, 11, 0.1);
  border-left: 3px solid var(--primary);
}

.log-message.success {
  background: rgba(16, 185, 129, 0.1);
  border-left: 3px solid var(--success);
}

.log-message.error {
  background: rgba(239, 68, 68, 0.1);
  border-left: 3px solid var(--danger);
}

.log-message.warning {
  background: rgba(252, 211, 77, 0.1);
  border-left: 3px solid var(--gold);
}

/* Sandbox */
.sandbox-content {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 25px;
  max-width: 1400px;
  margin: 0 auto;
}

.sandbox-controls {
  padding: 25px;
  background: var(--card-bg);
  border-radius: 16px;
}

.control-group {
  margin-bottom: 20px;
}

.control-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text-dim);
}

.control-group input,
.control-group select,
.control-group textarea {
  width: 100%;
  padding: 12px 15px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: var(--text);
}

.control-group input:focus,
.control-group select:focus,
.control-group textarea:focus {
  outline: none;
  border-color: var(--gold);
}

.sandbox-buttons {
  display: flex;
  gap: 10px;
}

.sandbox-btn {
  flex: 1;
  padding: 12px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  border: 2px solid var(--gold);
  border-radius: 10px;
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  transition: all 0.3s;
}

.sandbox-btn:hover {
  background: rgba(252, 211, 77, 0.2);
}

.sandbox-visualization {
  padding: 25px;
  background: var(--card-bg);
  border-radius: 16px;
}

.sandbox-display {
  min-height: 300px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  margin-bottom: 20px;
}

.sandbox-log {
  max-height: 200px;
  overflow-y: auto;
  padding: 15px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
}

/* Badges */
.badges-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.badge-card {
  padding: 25px;
  background: var(--card-bg);
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 20px;
}

.badge-card.unlocked {
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(252, 211, 77, 0.1), transparent);
}

.badge-card.locked {
  opacity: 0.5;
}

.badge-icon {
  font-size: 3rem;
  filter: grayscale(100%);
}

.badge-card.unlocked .badge-icon {
  filter: none;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  padding: 40px;
  background: var(--card-bg);
  border-radius: 24px;
  border: 2px solid var(--gold);
  text-align: center;
  max-width: 500px;
  width: 90%;
}

.modal-content.victory {
  border-color: var(--success);
}

.victory-icon {
  font-size: 5rem;
  margin-bottom: 20px;
  animation: crownFloat 1s ease-out;
}

@keyframes crownFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-20px);
  }
}

.modal-content h2 {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  color: var(--gold);
  margin-bottom: 25px;
}

.victory-stats {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-bottom: 30px;
}

.victory-stat {
  text-align: center;
}

.victory-stat .stat-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.victory-stat .stat-value {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  color: var(--gold);
}

.modal-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
}

.modal-btn {
  padding: 15px 30px;
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--gold), var(--primary));
  color: #1a1512;
}

.modal-btn:hover {
  transform: scale(1.05);
}

.modal-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
}

/* Tutorial */
.modal-content.tutorial {
  border-color: var(--accent);
  text-align: left;
}

.modal-content.tutorial h2 {
  color: var(--accent);
  text-align: center;
}

#tutorial-content {
  margin-bottom: 25px;
  line-height: 1.8;
}

#tutorial-content p {
  margin-bottom: 15px;
}

#tutorial-content code {
  background: rgba(252, 211, 77, 0.2);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
}

/* Responsive */
@media (max-width: 1024px) {
  .game-content {
    grid-template-columns: 1fr;
  }

  .sandbox-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .game-logo {
    font-size: 2.2rem;
  }

  .player-stats {
    flex-wrap: wrap;
    gap: 20px;
  }

  .knapsack-visual {
    flex-direction: column;
    align-items: center;
  }
}
