/* ============================================
   Design System & Global Styles
   ============================================ */

:root {
  /* Color Palette - Cyberpunk Theme */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #8b5cf6;
  --accent: #ec4899;
  --accent-cyan: #06b6d4;

  /* Background Colors */
  --bg-main: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.8);
  --bg-glass: rgba(15, 23, 42, 0.7);

  /* Text Colors */
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;

  /* Rarity Colors */
  --ssr-gold: linear-gradient(135deg, #ffd700 0%, #ffed4e 50%, #ff6b6b 100%);
  --ssr-glow: rgba(255, 215, 0, 0.5);
  --sr-purple: linear-gradient(135deg, #9333ea 0%, #c084fc 100%);
  --sr-glow: rgba(147, 51, 234, 0.5);
  --n-gray: linear-gradient(135deg, #64748b 0%, #94a3b8 100%);
  --n-glow: rgba(100, 116, 139, 0.3);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--primary);

  /* Transitions */
  --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

/* ============================================
   Reset & Base Styles
   ============================================ */

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

html {
  font-size: 16px;
}

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  position: relative;
}

/* Animated Background */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(
      circle at 20% 50%,
      rgba(99, 102, 241, 0.1) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(236, 72, 153, 0.1) 0%,
      transparent 50%
    );
  z-index: -1;
  animation: bgPulse 10s ease-in-out infinite;
}

@keyframes bgPulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.8;
  }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-light);
}

/* ============================================
   Typography
   ============================================ */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1rem;
}

h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: 2rem;
  color: var(--primary-light);
}

h3 {
  font-size: 1.5rem;
}

p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

code {
  background: rgba(99, 102, 241, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Fira Code", monospace;
  font-size: 0.9em;
  color: var(--primary-light);
}

pre {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: 1rem;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

/* ============================================
   Title Screen (index.html)
   ============================================ */

.title-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
}

.title-container {
  text-align: center;
  z-index: 10;
  animation: fadeInUp 1s var(--transition-smooth);
}

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

.title-content h1 {
  font-size: 4rem;
  margin-bottom: 1rem;
  text-shadow: 0 0 40px rgba(99, 102, 241, 0.8);
  animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
  0%,
  100% {
    text-shadow: 0 0 40px rgba(99, 102, 241, 0.8);
  }
  50% {
    text-shadow: 0 0 60px rgba(236, 72, 153, 1);
  }
}

.title-content p {
  font-size: 1.3rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

#start-btn {
  display: inline-block;
  background: var(--ssr-gold);
  color: var(--bg-main);
  font-size: 1.5rem;
  font-weight: 700;
  padding: 1rem 3rem;
  border-radius: var(--radius-lg);
  text-decoration: none;
  box-shadow: 0 0 30px var(--ssr-glow);
  transition: all 0.3s var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

#start-btn::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    transparent,
    rgba(255, 255, 255, 0.5),
    transparent
  );
  transform: rotate(45deg);
  animation: btnShine 3s linear infinite;
}

@keyframes btnShine {
  0% {
    transform: translateX(-100%) translateY(-100%) rotate(45deg);
  }
  100% {
    transform: translateX(100%) translateY(100%) rotate(45deg);
  }
}

#start-btn:hover {
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 0 50px var(--ssr-glow);
}

/* ============================================
   Chapter Selection Screen
   ============================================ */

/* Course Tabs */
.course-tabs {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.course-tab {
  background: var(--bg-card);
  border: 2px solid transparent;
  color: var(--text-secondary);
  padding: 1rem 2rem;
  border-radius: var(--radius-lg);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s var(--transition-smooth);
}

.course-tab:hover {
  border-color: var(--primary);
  color: var(--text-primary);
}

.course-tab.active {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  border-color: transparent;
}

.course-description {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 1rem;
}

.select-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem 2rem;
  animation: fadeInUp 0.8s var(--transition-smooth);
  height: 100vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.select-container h1 {
  text-align: center;
  margin-bottom: 0.5rem;
  font-size: 2.5rem;
  flex-shrink: 0;
}

.chapter-grid {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1;
  overflow-y: auto;
  padding-right: 0.5rem;
  padding-bottom: 2rem;
  margin-bottom: 1rem;
}

.chapter-card {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  padding: 1.2rem 1.8rem;
  cursor: pointer;
  transition: all 0.3s var(--transition-smooth);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-shrink: 0;
}

.chapter-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(99, 102, 241, 0.1),
    rgba(236, 72, 153, 0.1)
  );
  opacity: 0;
  transition: opacity 0.3s var(--transition-smooth);
  z-index: 0;
}

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

.chapter-card:hover {
  transform: translateX(8px);
  border-color: var(--primary);
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.3);
}

.chapter-num {
  position: static;
  background: var(--primary);
  color: white;
  min-width: 50px;
  height: 50px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1.5rem;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chapter-card h3 {
  margin: 0;
  color: var(--text-primary);
  position: relative;
  z-index: 1;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.3;
}

.chapter-card p {
  color: var(--text-secondary);
  font-size: 1rem;
  margin: 0.4rem 0 0 0;
  position: relative;
  z-index: 1;
  line-height: 1.6;
}

.chapter-card-content {
  flex: 1;
}

/* Navigation Button */
.nav-btn {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  color: var(--text-primary);
  border: 2px solid var(--primary);
  padding: 0.8rem 1.5rem;
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s var(--transition-smooth);
  text-decoration: none;
  display: inline-block;
}

.nav-btn:hover {
  background: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--text-muted);
}

.nav-btn:disabled:hover {
  transform: none;
  background: var(--bg-card);
  box-shadow: none;
}

/* ============================================
   App Screen (3-Column Layout)
   ============================================ */

body:not(.title-body) {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  padding: 1rem 2rem;
  border-bottom: 2px solid rgba(99, 102, 241, 0.3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  z-index: 100;
}

header h1 {
  font-size: 1.5rem;
  margin: 0;
}

#nav-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  justify-content: center;
}

#chapter-title {
  color: var(--text-secondary);
  font-size: 1rem;
  min-width: 200px;
  text-align: center;
}

#status {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

main {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  padding: 1rem;
  height: calc(100vh - 80px);
  overflow: hidden;
}

/* Left Pane - Instructions */
#left-pane {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  padding: 2rem;
  overflow-y: auto;
  border: 1px solid rgba(99, 102, 241, 0.2);
}

#instruction-area h2 {
  margin-top: 0;
}

.mission {
  background: rgba(236, 72, 153, 0.1);
  border-left: 4px solid var(--accent);
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin: 1rem 0;
}

.mission strong {
  color: var(--accent);
  display: block;
  margin-bottom: 0.5rem;
}

/* Hint Box */
.hint-box {
  background: rgba(6, 182, 212, 0.1);
  border-left: 4px solid var(--accent-cyan);
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin: 1rem 0;
}

.hint-box strong {
  color: var(--accent-cyan);
  display: block;
  margin-bottom: 0.5rem;
}

/* Answer Box (Collapsible) */
.answer-box {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  margin: 1rem 0;
  overflow: hidden;
}

.answer-box summary {
  padding: 0.8rem 1rem;
  cursor: pointer;
  color: var(--primary-light);
  font-weight: 600;
  transition: background 0.3s var(--transition-smooth);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.answer-box summary::-webkit-details-marker {
  display: none;
}

.answer-box summary::before {
  content: "▶";
  font-size: 0.7rem;
  transition: transform 0.3s var(--transition-smooth);
}

.answer-box[open] summary::before {
  transform: rotate(90deg);
}

.answer-box summary:hover {
  background: rgba(99, 102, 241, 0.2);
}

.answer-box pre {
  margin: 0;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  border-top: 1px solid rgba(99, 102, 241, 0.3);
}

/* Middle Pane - Editor */
#middle-pane {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#editor-container {
  flex: 1;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

#editor {
  width: 100%;
  height: 100%;
  font-size: 16px;
}

#controls {
  display: flex;
  gap: 0.5rem;
}

#run-btn {
  flex: 1;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s var(--transition-smooth);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

#run-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.6);
}

#run-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Console Output (for early chapters) */
#console-container {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 1rem;
  border: 1px solid rgba(99, 102, 241, 0.3);
  max-height: 200px;
  overflow-y: auto;
  transition: all 0.3s var(--transition-smooth);
}

#console-container.hidden {
  display: none;
}

#console-output {
  margin: 0;
  padding: 0;
  color: var(--text-primary);
  font-family: "Fira Code", monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Right Pane - Gacha Stage */
#right-pane {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  padding: 2rem;
  overflow: hidden;
  border: 1px solid rgba(99, 102, 241, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* ============================================
   Chapter Menu Overlay
   ============================================ */

#chapter-menu {
  position: fixed;
  top: 80px;
  left: 2rem;
  width: 300px;
  max-height: calc(100vh - 100px);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  border: 2px solid var(--primary);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  transition: all 0.3s var(--transition-smooth);
}

#chapter-menu.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-20px);
}

.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(99, 102, 241, 0.3);
}

.menu-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

#close-menu-btn {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

#close-menu-btn:hover {
  color: var(--accent);
}

#chapter-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}

#chapter-list li {
  padding: 1rem 1.5rem;
  cursor: pointer;
  transition: all 0.2s var(--transition-smooth);
  border-bottom: 1px solid rgba(99, 102, 241, 0.1);
}

#chapter-list li:hover {
  background: rgba(99, 102, 241, 0.2);
  padding-left: 2rem;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1200px) {
  main {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
  }

  #left-pane {
    grid-column: 1 / -1;
    max-height: 300px;
  }

  #middle-pane {
    grid-column: 1;
  }

  #right-pane {
    grid-column: 2;
  }

  /* When right pane is hidden, expand middle pane */
  #right-pane[style*="display: none"] ~ #middle-pane {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }

  #left-pane,
  #middle-pane,
  #right-pane {
    grid-column: 1;
  }

  .title-content h1 {
    font-size: 2.5rem;
  }

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

/* Correct Answer Overlay */
.correct-answer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    pointer-events: none; /* Make clicks pass through */
    opacity: 0;
    transition: opacity 0.3s;
}

.correct-answer-overlay.show {
    opacity: 1;
}

.correct-content {
    text-align: center;
    transform: scale(0.5);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.correct-answer-overlay.show .correct-content {
    transform: scale(1);
}

.correct-text {
    font-size: 5rem;
    font-weight: 900;
    color: #ffd700; /* Gold */
    text-transform: uppercase;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5), 0 4px 0 #b8860b;
    margin-bottom: 2rem;
    animation: bounce 1s infinite alternate;
}

.correct-subtext {
    font-size: 2rem;
    color: white;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}
