* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --panel-bg: rgba(8, 18, 45, 0.82);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #f3f7ff;
  --muted: #b8c3f2;
  --accent: #7ee7ff;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, rgba(30, 106, 253, 0.2), transparent 28%),
    radial-gradient(circle at right top, rgba(114, 100, 255, 0.12), transparent 20%),
    #020619;
  color: var(--text);
}

body {
  font-size: 14px;
}

/* Navigation */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(8, 18, 45, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
}

.nav-brand {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.nav-links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 32px;
}

.nav-links a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

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

/* Home Page */
.home {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 10;
}

.hero {
  text-align: center;
  max-width: 600px;
  padding: 0 24px;
}

.hero h1 {
  font-size: 3.5rem;
  font-weight: 800;
  margin: 0 0 1rem;
  background: linear-gradient(135deg, var(--accent), #a7fffe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 1.25rem;
  color: var(--muted);
  margin: 0 0 2rem;
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
  display: inline-block;
  padding: 12px 24px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #020619;
  border: 1px solid var(--accent);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(126, 231, 255, 0.3);
}

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

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.3);
}

/* References Page */
.references {
  padding: 100px 24px 40px;
  max-width: 1200px;
  margin: 0 auto;
}

.references h1 {
  font-size: 2.5rem;
  font-weight: 800;
  margin: 0 0 1rem;
  text-align: center;
}

.references > p {
  font-size: 1.125rem;
  color: var(--muted);
  text-align: center;
  margin: 0 0 3rem;
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
}

.videos,
.articles,
.concepts,
.try-it {
  margin-bottom: 3rem;
}

.references h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 1.5rem;
  color: var(--accent);
}

.video-grid,
.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
}

.video-card,
.article-item,
.concept {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(12px);
}

.video-card h3,
.article-item h3,
.concept h3 {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.video-card p,
.article-item p,
.concept p {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.6;
}

.article-list {
  display: grid;
  gap: 16px;
}

.article-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.article-item a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}

.article-item a:hover {
  text-decoration: underline;
}

.try-it {
  text-align: center;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 32px;
  backdrop-filter: blur(12px);
}

.try-it p {
  font-size: 1.125rem;
  color: var(--muted);
  margin: 0 0 1.5rem;
}

/* Playground Page Container */
.playground-container {
  padding-top: 84px; /* Account for fixed nav height + margin */
  min-height: 100vh;
  position: relative;
}

.learn-screen {
  padding-top: 84px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.intro-panel {
  width: min(980px, calc(100vw - 48px));
  max-width: 980px;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 32px;
  align-items: start;
  padding: 24px 0;
}

.panel-content {
  max-width: 440px;
}

.panel-content h1 {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.panel-content p {
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 24px;
}

.learn-steps {
  width: min(980px, calc(100vw - 48px));
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}

.concept {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 22px;
  backdrop-filter: blur(12px);
}

.concept h3 {
  margin-top: 0;
  color: var(--accent);
}

.concept {
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.concept:hover {
  transform: translateY(-2px);
  background: rgba(126, 231, 255, 0.1);
  border-color: rgba(126, 231, 255, 0.3);
}

.concept.active {
  background: rgba(126, 231, 255, 0.12);
  border-color: var(--accent);
}

.nav-links a.active {
  color: var(--accent);
}

.stage-overlay {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 44px));
  max-width: 680px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  z-index: 9;
  pointer-events: none;
}

.stage-overlay.visible {
  pointer-events: auto;
}

.mac-frame {
  width: 100%;
  max-width: 680px;
  height: 380px;
  border-radius: 30px;
  background: #f9fbff;
  box-shadow: 0 36px 90px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.75);
  position: relative;
  overflow: hidden;
  transition: all 0.9s ease;
}

.mac-frame::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(245, 245, 245, 0.92));
  pointer-events: none;
}

.mac-top-bar {
  position: absolute;
  top: 18px;
  left: 24px;
  display: flex;
  gap: 10px;
  z-index: 2;
}

.mac-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff5f57;
  box-shadow: 18px 0 #ffbd2e, 36px 0 #28c940;
}

.mac-screen {
  position: relative;
  width: 100%;
  height: 100%;
  background: #ffffff;
  overflow: hidden;
}

.mac-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(#111 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 1;
  transition: opacity 0.8s ease 0.2s;
  pointer-events: none;
  z-index: -1;
}

.mac-screen.revealed::after {
  opacity: 0;
}

.mac-screen canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.flow-explanation {
  width: 100%;
  max-width: 680px;
  background: rgba(7, 15, 37, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 22px 24px;
  margin-top: 20px;;
  backdrop-filter: blur(18px);
  color: var(--text);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.flow-explanation h2 {
  margin: 0 0 10px;
  color: var(--accent);
}

.stage-overlay.expanded {
  top: 0;
  left: 0;
  transform: none;
  width: 100vw;
  height: calc(100vh - 84px);
  padding: 0;
  justify-content: flex-start;
  gap: 0;
}

.stage-overlay.expanded .mac-frame {
  width: 100vw;
  height: calc(100vh - 84px);
  max-width: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  border: none;
}

..stage-overlay.expanded .mac-screen {
  background: transparent;
}

.stage-overlay.expanded .mac-frame::before {
  display: none;
}

.stage-overlay.expanded .mac-top-bar {
  opacity: 0;
}

.stage-overlay.expanded .mac-screen::after {
  display: none;
}

.stage-overlay.expanded .flow-explanation {
  opacity: 0;
  transform: translateY(18px);
  pointer-events: none;
}

/* Playground Styles */
canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.ui-panel {
  position: fixed;
  left: 24px;
  top: 84px; /* Below nav: 60px nav + 24px margin */
  width: min(360px, calc(100vw - 48px));
  max-height: calc(100vh - 120px); /* Leave space for footer */
  padding: 20px;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  backdrop-filter: blur(18px);
  background: var(--panel-bg);
  box-shadow: 0 30px 80px rgba(1, 11, 32, 0.45);
  z-index: 20;
  overflow-y: auto; /* Allow scrolling if content is too tall */
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.panel-header h1 {
  font-size: 1.35rem;
  margin: 0 0 6px;
}

.panel-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.controls {
  margin-top: 20px;
  display: grid;
  gap: 18px;
}

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

.control-row label {
  display: block;
  font-weight: 600;
  color: var(--text);
}

.control-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

input[type='range'] {
  width: 100%;
  accent-color: #7cdaff;
}

input[type='checkbox'] {
  accent-color: #7cdaff;
  margin-right: 10px;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
}

button.ghost {
  width: min-content;
}

#clear-gravity {
  width:fit-content;
}

.instructions {
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.65;
}

.learning {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.learning h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.learning p {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.65;
}

.footer {
  position: fixed;
  left: 24px;
  bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.95rem;
  color: var(--muted);
  z-index: 10;
}

.footer strong {
  color: var(--text);
}

.hidden {
  display: none !important;
}

.show-ui-button {
  position: fixed;
  top: 50%;
  right: 24px;
  transform: translateY(-50%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(8, 18, 45, 0.92);
  color: var(--text);
  padding: 12px 18px;
  cursor: pointer;
  z-index: 12;
  box-shadow: 0 24px 48px rgba(1, 11, 32, 0.33);
}

@media (max-width: 560px) {
  .playground-container {
    padding-top: 76px; /* Smaller margin on mobile */
  }

  .ui-panel {
    top: 76px; /* Below nav on mobile */
    left: 16px;
    right: 16px;
    width: auto;
    max-height: calc(100vh - 100px);
    padding: 18px;
  }

  .footer {
    left: 16px;
    right: 16px;
    bottom: 16px;
    font-size: 0.88rem;
  }

  .nav-container {
    padding: 0 16px;
  }

  .hero h1 {
    font-size: 2.5rem;
  }

  .hero p {
    font-size: 1.1rem;
  }

  .hero-actions {
    flex-direction: column;
    align-items: center;
  }

  .references {
    padding: 80px 16px 20px;
  }

  .references h1 {
    font-size: 2rem;
  }
}

.footer strong {
  color: var(--text);
}

.hidden {
  display: none !important;
}

.show-ui-button {
  position: fixed;
  top: 50%;
  right: 24px;
  transform: translateY(-50%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(8, 18, 45, 0.92);
  color: var(--text);
  padding: 12px 18px;
  cursor: pointer;
  z-index: 12;
  box-shadow: 0 24px 48px rgba(1, 11, 32, 0.33);
}

