/* ==========================================================================
   2D GAME PHYSICS - MODERN DARK UI STYLESHEET
   ========================================================================== */

:root {
  --bg-primary: #0a0d14;
  --bg-secondary: #111726;
  --bg-tertiary: #192238;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(25, 34, 56, 0.95);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(56, 189, 248, 0.5);

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-cyan: #38bdf8;
  --accent-cyan-glow: rgba(56, 189, 248, 0.25);
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.25);
  --accent-purple: #a855f7;
  --accent-purple-glow: rgba(168, 85, 247, 0.25);
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(56, 189, 248, 0.07) 0%, transparent 40%),
    radial-gradient(circle at 85% 65%, rgba(168, 85, 247, 0.06) 0%, transparent 40%),
    linear-gradient(to bottom, #090c13, #0d121d);
  background-attachment: fixed;
}

/* Header & Navigation */
header.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 13, 20, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 2rem;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.logo-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px var(--accent-cyan-glow);
  color: #fff;
  font-size: 1.1rem;
}

.nav-links {
  display: flex;
  gap: 0.5rem;
  list-style: none;
  flex-wrap: wrap;
}

.nav-links a {
  text-decoration: none;
  color: var(--text-muted);
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-links a:hover {
  color: var(--text-main);
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

.nav-links a.active {
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
  font-weight: 600;
}

/* Hero Section */
.hero {
  max-width: 1300px;
  margin: 2.5rem auto 1.5rem auto;
  padding: 0 1.5rem;
  text-align: center;
}

.badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.25);
  margin-bottom: 1rem;
}

.hero h1 {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #ffffff 30%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero p.lead {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 780px;
  margin: 0 auto;
  font-weight: 400;
}

/* Main Container */
main.container {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto 3rem auto;
  padding: 0 1.5rem;
  flex: 1;
}

/* Simulation Grid & Cards */
.demo-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  margin-bottom: 2.5rem;
  transition: border-color 0.25s ease;
  backdrop-filter: blur(8px);
}

.demo-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.demo-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(17, 24, 39, 0.6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.demo-title-group h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.demo-title-group p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.demo-body {
  display: grid;
  grid-template-columns: 1fr 340px;
  min-height: 480px;
}

@media (max-width: 1024px) {
  .demo-body {
    grid-template-columns: 1fr;
  }
}

/* Canvas Viewport */
.canvas-viewport {
  position: relative;
  background: #07090e;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  min-height: 420px;
}

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

.canvas-overlay-hint {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  backdrop-filter: blur(4px);
}

.canvas-stats {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-cyan);
  pointer-events: none;
}

/* Controls Panel */
.controls-sidebar {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
  max-height: 600px;
}

@media (max-width: 1024px) {
  .controls-sidebar {
    border-left: none;
    border-top: 1px solid var(--border-color);
    max-height: none;
  }
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.control-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.control-value {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-cyan);
  font-weight: 600;
}

/* Range Sliders */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
  cursor: pointer;
  transition: transform 0.1s, background-color 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: #fff;
}

/* Buttons */
.btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-main);
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border-color: #38bdf8;
  color: #fff;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0ea5e9, #3b82f6);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.5);
}

.btn-accent {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: var(--accent-emerald);
}

.btn-accent:hover {
  background: rgba(16, 185, 129, 0.25);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

/* Toggle Switches */
.toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-switch {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  transition: 0.3s;
  border-radius: var(--radius-full);
}

.slider-switch:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: #94a3b8;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .slider-switch {
  background-color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

input:checked + .slider-switch:before {
  transform: translateX(18px);
  background-color: #0b0f19;
}

/* Explanations & Theory Sections */
.theory-block {
  padding: 1.5rem;
  background: rgba(15, 23, 42, 0.6);
  border-top: 1px solid var(--border-color);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

@media (max-width: 900px) {
  .theory-block {
    grid-template-columns: 1fr;
  }
}

.theory-content h3 {
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theory-content p {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 0.75rem;
}

.formula-card {
  background: #080c14;
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-cyan);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  margin: 0.85rem 0;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.formula-card .math {
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 1.05rem;
}

.formula-card .comment {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.code-box {
  background: #080b12;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.code-box-header {
  background: rgba(255, 255, 255, 0.03);
  padding: 0.4rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.code-box pre {
  padding: 0.85rem;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #e2e8f0;
  overflow-x: auto;
  line-height: 1.5;
}

.code-box pre code .kw { color: #f43f5e; font-weight: 600; }
.code-box pre code .fn { color: #38bdf8; }
.code-box pre code .num { color: #f59e0b; }
.code-box pre code .str { color: #10b981; }
.code-box pre code .comment { color: #64748b; font-style: italic; }

/* Grid of Topic Cards (on Homepage) */
.topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.topic-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

.topic-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent-color, var(--accent-cyan)), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.topic-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

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

.topic-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 1.25rem;
}

.topic-card h3 {
  font-size: 1.25rem;
  color: #fff;
  margin-bottom: 0.5rem;
}

.topic-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
  flex: 1;
}

.topic-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--accent-cyan);
  font-size: 0.85rem;
  font-weight: 600;
}

/* Footer */
footer.site-footer {
  border-top: 1px solid var(--border-color);
  background: rgba(10, 13, 20, 0.95);
  padding: 2rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  margin-top: auto;
}

.footer-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

/* Callout Note */
.callout {
  background: rgba(56, 189, 248, 0.08);
  border-left: 3px solid var(--accent-cyan);
  padding: 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.88rem;
  color: #cbd5e1;
  margin: 1rem 0;
}

.callout strong {
  color: #fff;
}

/* Animations */
@keyframes pulseGlow {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.pulse {
  animation: pulseGlow 2s infinite ease-in-out;
}
