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

:root {
  --primary: #eab308;
  --secondary: #a855f7;
  --accent: #06b6d4;
  --mystic: #c084fc;
  --success: #22c55e;
  --danger: #ef4444;
  --dark-bg: #0c0a15;
  --card-bg: rgba(20, 15, 35, 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 20% 80%,
      rgba(168, 85, 247, 0.2) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at 80% 20%,
      rgba(234, 179, 8, 0.15) 0%,
      transparent 50%
    );
}

.mystical-particles {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(
    circle,
    rgba(192, 132, 252, 0.4) 1px,
    transparent 1px
  );
  background-size: 50px 50px;
  animation: mysticFloat 30s linear infinite;
}

@keyframes mysticFloat {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }
  100% {
    transform: translate(-50px, -50px) rotate(360deg);
  }
}

.tree-branches {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0.1;
  background:
    linear-gradient(
      135deg,
      transparent 45%,
      rgba(168, 85, 247, 0.3) 50%,
      transparent 55%
    ),
    linear-gradient(
      225deg,
      transparent 45%,
      rgba(168, 85, 247, 0.3) 50%,
      transparent 55%
    );
  background-size: 60px 60px;
}

/* 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: chessPiece 3s ease-in-out infinite;
}

@keyframes chessPiece {
  0%,
  100% {
    transform: translateY(0) rotateY(0deg);
  }
  25% {
    transform: translateY(-10px) rotateY(90deg);
  }
  50% {
    transform: translateY(0) rotateY(180deg);
  }
  75% {
    transform: translateY(-10px) rotateY(270deg);
  }
}

.game-logo {
  font-family: 'Uncial Antiqua', cursive;
  font-size: 3rem;
  background: linear-gradient(135deg, var(--primary), var(--mystic));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 60px rgba(192, 132, 252, 0.5);
  letter-spacing: 3px;
}

.game-subtitle {
  font-size: 1.2rem;
  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(192, 132, 252, 0.3);
}

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

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

.stat-value {
  font-family: 'Uncial Antiqua', cursive;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--mystic);
}

.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: 'Rajdhani', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  border: 2px solid var(--mystic);
  border-radius: 12px;
  background: transparent;
  color: var(--mystic);
  cursor: pointer;
  transition: all 0.3s;
  text-transform: uppercase;
  letter-spacing: 2px;
}

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

.menu-btn.primary {
  background: linear-gradient(135deg, var(--secondary), var(--mystic));
  border: none;
  color: #fff;
}

.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(192, 132, 252, 0.2);
}

.screen-header h2 {
  font-family: 'Uncial Antiqua', cursive;
  font-size: 1.6rem;
  color: var(--mystic);
}

.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);
}

.mana-display {
  font-family: 'Uncial Antiqua', cursive;
  font-size: 1.1rem;
  color: var(--mystic);
}

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

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

.island-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 150%;
  height: 150%;
  transform: translate(-50%, -50%);
  background: radial-gradient(
    circle,
    rgba(192, 132, 252, 0.1),
    transparent 70%
  );
  opacity: 0;
  transition: opacity 0.3s;
}

.island-card:hover {
  transform: translateY(-10px);
  border-color: var(--mystic);
  box-shadow: 0 20px 60px rgba(192, 132, 252, 0.3);
}

.island-card:hover .island-glow {
  opacity: 1;
}

.island-icon {
  font-size: 3.5rem;
  margin-bottom: 15px;
  position: relative;
  z-index: 1;
}

.island-card h3 {
  font-family: 'Uncial Antiqua', cursive;
  font-size: 1.3rem;
  color: var(--mystic);
  margin-bottom: 10px;
}

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

.island-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(--mystic), var(--success));
  border-radius: 4px;
  transition: width 0.5s;
}

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

.puzzle-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;
}

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

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

.puzzle-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;
}

.puzzle-card:not(.locked):hover {
  transform: translateY(-5px);
  border-color: var(--mystic);
  box-shadow: 0 15px 40px rgba(192, 132, 252, 0.2);
}

.puzzle-number {
  font-family: 'Uncial Antiqua', cursive;
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--mystic);
  opacity: 0.3;
  margin-bottom: 10px;
}

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

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

.puzzle-mana {
  margin-top: 15px;
  font-family: 'Uncial Antiqua', cursive;
  font-size: 0.9rem;
  color: var(--mystic);
}

/* 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: 'Uncial Antiqua', cursive;
  font-size: 1.4rem;
  color: var(--mystic);
}

.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;
  padding: 30px;
  background: var(--card-bg);
  border-radius: 16px;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Maze Grid */
.maze-grid {
  display: grid;
  gap: 2px;
  background: rgba(0, 0, 0, 0.5);
  padding: 10px;
  border-radius: 12px;
}

.maze-cell {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  border-radius: 6px;
  transition: all 0.3s;
}

.maze-cell.wall {
  background: #1e1b4b;
}

.maze-cell.path {
  background: rgba(192, 132, 252, 0.2);
}

.maze-cell.visited {
  background: rgba(34, 197, 94, 0.3);
}

.maze-cell.current {
  background: var(--primary);
  animation: pulse 0.5s infinite;
}

.maze-cell.backtrack {
  background: rgba(239, 68, 68, 0.3);
}

.maze-cell.start {
  background: var(--success);
}

.maze-cell.end {
  background: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* Chess Board */
.chess-board {
  display: grid;
  gap: 0;
  border: 4px solid var(--mystic);
  border-radius: 8px;
  overflow: hidden;
}

.chess-cell {
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  transition: all 0.3s;
}

.chess-cell.light {
  background: #f0d9b5;
}

.chess-cell.dark {
  background: #b58863;
}

.chess-cell.highlight {
  box-shadow: inset 0 0 20px var(--mystic);
}

.chess-cell.danger {
  box-shadow: inset 0 0 20px var(--danger);
}

.chess-cell.safe {
  box-shadow: inset 0 0 20px var(--success);
}

/* Recursion Panel */
.recursion-panel {
  padding: 20px;
  background: var(--card-bg);
  border-radius: 16px;
  max-height: 500px;
  overflow-y: auto;
}

.recursion-panel h3 {
  color: var(--mystic);
  margin-bottom: 15px;
  font-family: 'Uncial Antiqua', cursive;
}

.tree-container {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
}

.tree-node {
  padding: 8px 12px;
  margin: 3px 0;
  background: rgba(192, 132, 252, 0.1);
  border-left: 3px solid var(--mystic);
  border-radius: 0 8px 8px 0;
  animation: nodeSlide 0.3s ease-out;
}

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

.tree-node.exploring {
  background: rgba(234, 179, 8, 0.2);
  border-left-color: var(--primary);
}

.tree-node.success {
  background: rgba(34, 197, 94, 0.2);
  border-left-color: var(--success);
}

.tree-node.backtrack {
  background: rgba(239, 68, 68, 0.2);
  border-left-color: var(--danger);
}

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

.speed-control {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.speed-control label {
  font-weight: 600;
  color: var(--text-dim);
}

.speed-control input[type='range'] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.speed-control input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--mystic);
  border-radius: 50%;
  cursor: pointer;
}

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

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

.control-btn:hover {
  background: rgba(192, 132, 252, 0.2);
}

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

.state-panel h3 {
  color: var(--mystic);
  margin-bottom: 15px;
  font-family: 'Uncial Antiqua', cursive;
}

.state-info {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
}

.state-info div {
  padding: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  margin-bottom: 8px;
}

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

.solutions-panel h3 {
  color: var(--success);
  margin-bottom: 15px;
  font-family: 'Uncial Antiqua', cursive;
}

.solutions-list {
  max-height: 200px;
  overflow-y: auto;
}

.solution-item {
  padding: 10px;
  background: rgba(34, 197, 94, 0.1);
  border-radius: 8px;
  margin-bottom: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  border-left: 3px solid var(--success);
}

/* 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(192, 132, 252, 0.1);
  border-left: 3px solid var(--mystic);
}

.log-message.success {
  background: rgba(34, 197, 94, 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(234, 179, 8, 0.1);
  border-left: 3px solid var(--primary);
}

/* 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 {
  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 {
  outline: none;
  border-color: var(--mystic);
}

.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(--mystic);
  border-radius: 10px;
  background: transparent;
  color: var(--mystic);
  cursor: pointer;
  transition: all 0.3s;
}

.sandbox-btn:hover {
  background: rgba(192, 132, 252, 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;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sandbox-tree {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 20px;
}

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

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

.spell-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;
}

.spell-card.unlocked {
  border-color: var(--mystic);
  background: linear-gradient(135deg, rgba(192, 132, 252, 0.1), transparent);
}

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

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

.spell-card.unlocked .spell-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(--mystic);
  text-align: center;
  max-width: 500px;
  width: 90%;
}

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

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

@keyframes victoryBurst {
  0% {
    transform: scale(0) rotate(-180deg);
  }
  50% {
    transform: scale(1.2) rotate(10deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

.modal-content h2 {
  font-family: 'Uncial Antiqua', cursive;
  font-size: 2rem;
  color: var(--success);
  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: 'Uncial Antiqua', cursive;
  font-size: 1.5rem;
  color: var(--mystic);
}

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

.modal-btn {
  padding: 15px 30px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--mystic), var(--success));
  color: #000;
}

.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(--secondary);
  text-align: left;
}

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

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

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

#tutorial-content code {
  background: rgba(192, 132, 252, 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: 2rem;
  }

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

  .chess-cell {
    width: 35px;
    height: 35px;
    font-size: 1.5rem;
  }

  .maze-cell {
    width: 30px;
    height: 30px;
  }
}
