/* MATHESIS — Design System */

/* ========== RESET & BASE ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #050510;
  --bg-surface: #0a0a1a;
  --bg-card: #111128;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --text-bright: #ffffff;
  --accent: #00f0ff;
  --success: #00ff88;
  --error: #ff4466;
  --warning: #ffaa00;
  --font-serif: Georgia, 'Times New Roman', serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  --font-system: system-ui, -apple-system, sans-serif;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --glow-spread: 60px;
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== TYPOGRAPHY ========== */
.display-title {
  font-size: clamp(2.5rem, 8vw, 6rem);
  font-weight: 300;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-bright);
  text-align: center;
}

.display-subtitle {
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  letter-spacing: 0.15em;
  color: var(--text-dim);
  text-align: center;
  font-family: var(--font-system);
  font-weight: 300;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 300;
  letter-spacing: 0.05em;
  margin-bottom: 0.5em;
}

h2 {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 400;
  margin-bottom: 0.5em;
  color: var(--text-bright);
}

h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.5em;
  font-family: var(--font-system);
}

p { margin-bottom: 1em; }

code, .math-inline {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* ========== LAYOUT ========== */
.app-container {
  position: relative;
  min-height: 100vh;
  transition: opacity 0.3s ease;
}

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  z-index: 1000;
  transition: width 0.5s ease;
}

.nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: rgba(5, 5, 16, 0.85);
  backdrop-filter: blur(12px);
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.nav-bar.visible {
  opacity: 1;
  transform: translateY(0);
}

.nav-logo {
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--font-system);
}

.nav-logo:hover { color: var(--accent); }

.nav-chapter {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-family: var(--font-system);
}

.nav-arrows {
  display: flex;
  gap: 0.5rem;
}

.nav-arrows button {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: var(--transition);
}

.nav-arrows button:hover {
  background: rgba(255,255,255,0.1);
  border-color: var(--accent);
}

.nav-arrows button:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ========== LANDING PAGE ========== */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
}

.landing-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.landing-content {
  position: relative;
  z-index: 1;
  text-align: center;
  pointer-events: none;
}

.landing-content > * {
  pointer-events: auto;
}

.landing .display-title {
  margin-bottom: 0.3em;
  animation: fadeInUp 1.5s ease both;
}

.landing .display-subtitle {
  animation: fadeInUp 1.5s ease 0.3s both;
  margin-bottom: 3em;
}

.begin-btn {
  display: inline-block;
  padding: 0.8em 2.5em;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-system);
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  background: transparent;
  cursor: pointer;
  transition: var(--transition);
  animation: fadeInUp 1.5s ease 0.6s both;
}

.begin-btn:hover {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.3);
}

/* ========== CHAPTER HERO IMAGE ========== */
.chapter-hero {
  width: 100vw;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 3rem;
  overflow: hidden;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.chapter-hero img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1s ease;
}

.chapter-hero img.loaded {
  opacity: 1;
}

.chapter-hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(to top, var(--bg, #050510), transparent);
  pointer-events: none;
}

/* ========== CHAPTER LAYOUT ========== */
.chapter-container {
  max-width: 780px;
  margin: 0 auto;
  padding: 120px 2rem 100px;
  animation: fadeIn 0.6s ease;
}

.chapter-header {
  text-align: center;
  margin-bottom: 4rem;
  padding: 3rem 0;
}

.chapter-number {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 1rem;
  display: block;
}

.chapter-title {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 300;
  margin-bottom: 0.3em;
}

.chapter-subtitle {
  font-size: 1.1rem;
  color: var(--text-dim);
  font-style: italic;
}

/* ========== SECTIONS ========== */
.section {
  margin-bottom: 4rem;
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.section.visible {
  opacity: 1;
  transform: translateY(0);
}

.content-section {
  line-height: 1.8;
}

.content-section p {
  margin-bottom: 1.2em;
}

.content-section strong {
  color: var(--accent);
  font-weight: 600;
}

.content-section em {
  font-style: italic;
  color: var(--text-bright);
}

.content-section ul, .content-section ol {
  margin: 1em 0;
  padding-left: 1.5em;
}

.content-section li {
  margin-bottom: 0.5em;
}

.math-block {
  display: block;
  text-align: center;
  margin: 2em 0;
  padding: 1.5em;
  background: rgba(255,255,255,0.02);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  overflow-x: auto;
}

/* ========== VISUAL SECTION ========== */
.visual-section {
  margin: 3rem -2rem;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.05);
}

.viz-canvas {
  display: block;
  width: 100%;
  cursor: crosshair;
}

.viz-controls {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: rgba(0,0,0,0.4);
  border-top: 1px solid rgba(255,255,255,0.05);
  flex-wrap: wrap;
}

.viz-controls button, .viz-controls select {
  padding: 0.4em 1em;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  font-family: var(--font-system);
  font-size: 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.viz-controls button:hover {
  background: rgba(255,255,255,0.1);
  border-color: var(--accent);
}

.viz-controls button.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.viz-label {
  font-family: var(--font-system);
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 0.4em 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ========== EXERCISE STYLES ========== */
.exercise-wrapper {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 2rem;
  margin: 2rem 0;
  position: relative;
}

.exercise-wrapper.completed {
  border-color: rgba(0, 255, 136, 0.2);
}

.exercise-wrapper.completed::after {
  content: '\2713';
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 28px;
  height: 28px;
  background: var(--success);
  color: var(--bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.9rem;
}

.exercise-title {
  font-family: var(--font-system);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin-bottom: 1rem;
}

.exercise-prompt {
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

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

.mc-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.8em 1.2em;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.mc-option:hover { background: rgba(255,255,255,0.06); border-color: var(--accent); }
.mc-option.correct { background: rgba(0,255,136,0.1); border-color: var(--success); color: var(--success); }
.mc-option.wrong { background: rgba(255,68,102,0.1); border-color: var(--error); }

.exercise-feedback {
  margin-top: 1rem;
  min-height: 1.5em;
}

.correct-msg { color: var(--success); font-weight: 600; }
.wrong-msg { color: var(--error); }

.hint-btn {
  margin-top: 1rem;
  padding: 0.4em 1em;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-dim);
  font-family: var(--font-system);
  font-size: 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.hint-btn:hover { border-color: var(--warning); color: var(--warning); }
.hint-btn:disabled { opacity: 0.3; cursor: default; }

.hint-box {
  margin-top: 0.5rem;
}

.hint {
  padding: 0.6em 1em;
  background: rgba(255, 170, 0, 0.05);
  border-left: 2px solid var(--warning);
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--warning);
  animation: fadeIn 0.4s ease;
}

/* Drag & Drop */
.drag-drop-area {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dd-source, .dd-target {
  min-height: 60px;
  padding: 1rem;
  border: 1px dashed rgba(255,255,255,0.15);
  border-radius: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
  align-content: flex-start;
}

.dd-target {
  background: rgba(255,255,255,0.02);
  border-color: var(--accent);
  border-style: dashed;
  min-height: 80px;
}

.dd-target.drag-over {
  background: rgba(0, 240, 255, 0.05);
  border-color: var(--accent);
  border-style: solid;
}

.dd-label {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-family: var(--font-system);
  width: 100%;
}

.dd-item {
  padding: 0.4em 0.8em;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  cursor: grab;
  font-size: 0.9rem;
  transition: var(--transition);
  user-select: none;
}

.dd-item:hover { border-color: var(--accent); }
.dd-item.dragging { opacity: 0.5; }

.check-btn {
  padding: 0.6em 1.5em;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  font-family: var(--font-system);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  align-self: flex-start;
}

.check-btn:hover { box-shadow: 0 0 20px rgba(0, 240, 255, 0.3); }

/* Proof Steps */
.proof-chain {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.proof-step {
  padding: 1rem;
  background: rgba(255,255,255,0.02);
  border-radius: 4px;
  animation: fadeIn 0.4s ease;
}

.proof-premise {
  margin-bottom: 0.5rem;
  font-style: italic;
}

.proof-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.proof-option {
  padding: 0.4em 0.8em;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.proof-option:hover { border-color: var(--accent); }
.proof-option.correct { background: rgba(0,255,136,0.1); border-color: var(--success); }
.proof-option.wrong { background: rgba(255,68,102,0.1); border-color: var(--error); }

.proof-conclusion {
  color: var(--success);
  font-weight: 600;
  margin-top: 0.5rem;
}

/* Builder */
.builder-area {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.builder-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.builder-piece {
  padding: 0.4em 0.8em;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.builder-piece:hover { border-color: var(--accent); background: rgba(0,240,255,0.05); }

.builder-workspace {
  min-height: 80px;
  padding: 1rem;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.8;
}

/* ========== BRIDGE SECTION ========== */
.bridge-section {
  position: relative;
  padding: 2.5rem 2rem;
  margin: 3rem 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.02), rgba(255,255,255,0.04));
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.06);
}

.bridge-section::before {
  content: 'Bridge to Consciousness';
  position: absolute;
  top: -0.6em;
  left: 1.5rem;
  padding: 0 0.5em;
  background: var(--bg);
  font-family: var(--font-system);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.bridge-section p {
  font-style: italic;
  color: var(--text-dim);
  line-height: 1.9;
}

.bridge-section strong {
  color: var(--accent);
}

/* ========== CHAPTER NAVIGATION ========== */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  padding: 3rem 0;
  margin-top: 4rem;
  border-top: 1px solid rgba(255,255,255,0.05);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-family: var(--font-system);
  color: var(--text-dim);
  transition: var(--transition);
  text-decoration: none;
  max-width: 45%;
}

.chapter-nav a:hover { color: var(--accent); }

.chapter-nav .nav-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.chapter-nav .nav-title {
  font-size: 0.95rem;
  color: var(--text);
}

/* ========== ANIMATIONS ========== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake { animation: shake 0.4s ease; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 5px var(--accent); }
  50% { box-shadow: 0 0 25px var(--accent); }
}

/* ========== TRANSITIONS ========== */
.chapter-transition-enter {
  opacity: 0;
  transform: translateX(40px);
}

.chapter-transition-enter-active {
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.chapter-transition-exit {
  opacity: 1;
  transform: translateX(0);
}

.chapter-transition-exit-active {
  opacity: 0;
  transform: translateX(-40px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  html { font-size: 16px; }

  .chapter-container {
    padding: 80px 1.2rem 60px;
  }

  .visual-section {
    margin: 2rem -1.2rem;
  }

  .exercise-wrapper {
    padding: 1.2rem;
  }

  .chapter-nav {
    flex-direction: column;
    gap: 1.5rem;
  }

  .chapter-nav a {
    max-width: 100%;
  }

  .nav-bar {
    padding: 0 0.8rem;
  }
}

@media (max-width: 480px) {
  .display-title {
    letter-spacing: 0.15em;
  }

  .chapter-header {
    margin-bottom: 2.5rem;
    padding: 2rem 0;
  }
}

/* ========== KATEX OVERRIDES ========== */
.katex-display {
  margin: 1.5em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.katex {
  font-size: 1.1em;
}

/* ========== MISC ========== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.math-error {
  color: var(--error);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

::selection {
  background: rgba(0, 240, 255, 0.2);
  color: var(--text-bright);
}
