/* 
 * MML DESIGN SYSTEM 4.0 - "Thinking Grid"
 * Inspiration: Otl Aicher (Grid), John Maeda (Computational Flow)
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800;900&family=Playfair+Display:ital,wght@0,700;1,700&family=JetBrains+Mono:wght@400;700&family=Patrick+Hand&display=swap');

:root {
  /* --- TOKENS --- */
  --bg-canvas: #f4f3ef; /* Warm Paper */
  --bg-surface: #ffffff;
  --bg-surface-hover: #ffffff;
  --text-primary: #111111; /* Sharp Black */
  --text-secondary: #555555;
  --text-tertiary: #888888;
  --accent-primary: #ea580c; /* International Orange (Saul Bass) */
  --border-color: #e5e5e5;
  
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --card-shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
  
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-serif: 'Playfair Display', serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-hand: 'Patrick Hand', cursive;
  
  --current-font: var(--font-sans);
  --ease: cubic-bezier(0.16, 1, 0.3, 1); /* iOS Spring */
  --transition-speed: 0.5s;
}

/* --- THEMES --- */
/* 1. Beige Paper (Classic) - Warm, Intellectual */
[data-theme="beige"] {
  --bg-canvas: #f4f3ef; 
  --bg-surface: #ffffff; 
  --bg-surface-hover: #ffffff;
  --text-primary: #111111; 
  --text-secondary: #555555; 
  --accent-primary: #ea580c; 
  --border-color: #e5e5e5;
}

/* 2. Deep Space (Dark Mode) - Void, Infinite */
[data-theme="dark"] {
  --bg-canvas: #09090b; 
  --bg-surface: #18181b; 
  --bg-surface-hover: #27272a;
  --text-primary: #f8fafc; 
  --text-secondary: #94a3b8; 
  --accent-primary: #38bdf8; /* Sky Blue */
  --border-color: #27272a;
}

/* 3. Electric Violet (Vibrant) - Digital, Creative */
[data-theme="violet"] {
  --bg-canvas: #1e1b4b; /* Indigo 950 */
  --bg-surface: #312e81; /* Indigo 900 */
  --bg-surface-hover: #3730a3;
  --text-primary: #e0e7ff; 
  --text-secondary: #a5b4fc; 
  --accent-primary: #c084fc; /* Violet */
  --border-color: #4338ca;
}

/* 4. Matcha Latte (Fresh) - Calm, Natural */
[data-theme="matcha"] {
  --bg-canvas: #f0fdf4; /* Green 50 */
  --bg-surface: #ffffff; 
  --bg-surface-hover: #dcfce7;
  --text-primary: #14532d; /* Green 900 */
  --text-secondary: #15803d; /* Green 700 */
  --accent-primary: #16a34a; /* Green 600 */
  --border-color: #bbf7d0;
}

/* 5. Cherry Blossom (Soft) - Elegant, Pink */
[data-theme="sakura"] {
  --bg-canvas: #fff1f2; /* Rose 50 */
  --bg-surface: #ffffff;
  --bg-surface-hover: #ffe4e6;
  --text-primary: #881337; /* Rose 900 */
  --text-secondary: #be123c; /* Rose 700 */
  --accent-primary: #fb7185; /* Rose 400 */
  --border-color: #fecdd3;
}

/* 6. High Contrast (Accessibility/Cyber) - Stark, Bold */
[data-theme="contrast"] {
  --bg-canvas: #000000;
  --bg-surface: #000000;
  --bg-surface-hover: #1a1a1a;
  --text-primary: #ffff00; /* Yellow */
  --text-secondary: #00ff00; /* Green */
  --accent-primary: #ff00ff; /* Magenta */
  --border-color: #ffffff;
}

[data-font="serif"] { --current-font: var(--font-serif); }
[data-font="mono"] { --current-font: var(--font-mono); }
[data-font="hand"] { 
  --current-font: var(--font-hand); 
  letter-spacing: 0.08em; /* Add breathing room for handwriting */
  font-size: 110%; /* Compensate for smaller visual size */
}

/* --- GLOBAL RESET & BASE --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--current-font);
  transition: background-color var(--transition-speed) var(--ease), color var(--transition-speed) var(--ease);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none !important; transition: all 0.3s var(--ease); }

/* --- APP STRUCTURE --- */
.app-container {
  width: 100%;
  max-width: 1200px; /* Wider for Grid */
  margin: 0 auto;
  padding: 0 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2; /* Above canvas */
}

/* --- HEADER --- */
.navbar {
  width: 100%;
  height: 90px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

.nav-links { display: flex; gap: 48px; }
.nav-link {
  font-size: 0.85rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.15em; opacity: 0.6;
}
.nav-link:hover, .nav-link.active { opacity: 1; color: var(--accent-primary); }

/* --- HERO SECTION --- */
.hero {
  min-height: 40vh; /* Give it space */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center; /* Explicit Center */
  width: 100%;
  margin-bottom: 60px;
  padding-top: 40px;
}

.main-title {
  font-size: clamp(2.5rem, 5vw, 4.5rem);
  font-weight: 900;
  line-height: 1.1;
  /* Removed negative letter-spacing for hand font compatibility */
  margin-bottom: 24px;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

/* Specific adjustment for sans-serif to keep it tight */
[data-font="sans"] .main-title {
  letter-spacing: -0.04em;
}

[data-font="hand"] .main-title {
  letter-spacing: 0.02em; /* Breathe more for hand font */
}

.tagline {
  font-size: 1.25rem;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
  font-weight: 400;
}

/* --- FEATURE GRID --- */
.features-container {
  width: 100%;
  margin-bottom: 100px;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 32px;
  width: 100%;
}

/* --- STACKED LIST (For Subpages: Blog, Learn, Game) --- */
.stacked-list {
  width: 100%;
  max-width: 800px;
  margin: 0 auto 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.list-item {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.4s var(--ease);
  position: relative;
  text-align: left;
}

.list-item:hover {
  transform: translateX(8px); /* Slide right instead of up for lists */
  border-color: var(--accent-primary);
  box-shadow: var(--card-shadow-hover);
  z-index: 10;
  background: var(--bg-surface-hover);
}

.item-content {
  display: flex;
  align-items: center;
  gap: 24px;
  flex: 1;
}

.item-icon-box {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-primary);
  flex-shrink: 0;
}

.item-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  display: block;
}

.item-desc {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.feature-card {
  background: var(--bg-surface);
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  transition: all 0.5s var(--ease);
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.feature-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--card-shadow-hover);
  border-color: var(--accent-primary);
}

.card-content {
  padding: 40px; /* Increased padding */
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-icon {
  margin-bottom: 24px;
  color: var(--accent-primary);
  width: 48px; height: 48px;
  background: var(--bg-canvas); /* Icon background */
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
}
.card-icon i { width: 24px; height: 24px; }

.card-content h3 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
}

[data-font="sans"] .card-content h3 {
  letter-spacing: -0.02em;
}

[data-font="hand"] .card-content h3 {
  letter-spacing: 0.04em;
}

.card-content p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.6;
  flex: 1; /* Pushes arrow down */
}

.link-arrow {
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}
.link-arrow i { width: 16px; height: 16px; transition: transform 0.3s ease; }
.feature-card:hover .link-arrow i { transform: translateX(4px); }

/* --- PHILOSOPHY --- */
.philosophy-section {
  text-align: center;
  margin-bottom: 80px;
  padding: 0 20px;
}
.content-wrapper {
  max-width: 700px;
  margin: 0 auto;
}
.philosophy-section h2 {
  font-size: 2rem;
  margin-bottom: 20px;
  font-weight: 800;
}
.philosophy-section p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

/* --- FOOTER (Sticky) --- */
footer {
  width: 100%;
  padding: 40px 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-color);
  background: var(--bg-canvas);
  position: relative;
  z-index: 2;
}

/* --- FLOATING CONTROLS --- */
.controls-floating {
  position: fixed; bottom: 32px; right: 32px;
  display: flex; flex-direction: column-reverse; gap: 16px;
  z-index: 10000;
}
.fab {
  width: 50px; height: 50px; border-radius: 50%;
  background: var(--bg-surface); border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: all 0.3s var(--ease);
}
.fab:hover { transform: scale(1.1); border-color: var(--accent-primary); }
.dropdown-menu {
  position: absolute; bottom: 70px; right: 0;
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: 16px; padding: 6px; min-width: 220px; /* Increased width */
  display: none; flex-direction: column; gap: 2px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.dropdown-menu.show { display: flex; animation: fadeUp 0.2s var(--ease); }
.menu-item {
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  font-size: 0.85rem; font-weight: 500;
  white-space: nowrap; /* Prevent wrapping */
}
.menu-item:hover { background: var(--bg-canvas); color: var(--accent-primary); }

.color-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* --- CONTENT PAGES --- */
.content-layout {
  text-align: left;
  width: 100%;
  padding-bottom: 60px;
}

.markdown-body {
  width: 100%;
  text-align: left;
  line-height: 1.8;
}
.markdown-body h1 { margin: 2rem 0 1.5rem; font-size: 2.2rem; }
.markdown-body h2 { margin: 2rem 0 1rem; font-size: 1.8rem; }
.markdown-body p { margin-bottom: 1.5rem; font-size: 1.1rem; }
.markdown-body a { 
  border-bottom: 1px solid var(--border-color); 
  padding-bottom: 2px;
}
.markdown-body a:hover { 
  border-bottom-color: var(--accent-primary); 
  background: var(--bg-surface-hover); 
}

/* --- LEARN & SIDEBAR LAYOUT --- */
.learn-container {
  padding-top: 20px;
  padding-bottom: 80px;
}

.breadcrumb-bar {
  display: flex;
  align-items: center;
  justify-content: center; /* Center breadcrumb */
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-tertiary);
  margin-bottom: 40px;
  position: relative; /* For absolute positioning if needed, but flex is better */
}
.breadcrumb-bar a:hover { color: var(--accent-primary); }
.breadcrumb-bar i { width: 14px; height: 14px; opacity: 0.5; }
.current-cat { font-weight: 600; color: var(--text-primary); }

.sidebar-toggle-btn {
  background: none;
  border: 1px solid var(--border-color);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  position: absolute; /* Float to left */
  left: 0;
}
.sidebar-toggle-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}
.sidebar-toggle-btn i { width: 18px; height: 18px; opacity: 1; }

.sidebar-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 40px;
  position: relative;
  width: 100%;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-layout.collapsed {
  grid-template-columns: 0px 1fr;
  gap: 0;
}

/* Sidebar Styles */
.sidebar {
  position: sticky;
  top: 40px;
  height: calc(100vh - 80px); /* Fit in viewport */
  overflow-y: hidden; /* Use inner scroll */
  border-right: 1px solid var(--border-color);
  padding-right: 20px;
  display: flex;
  flex-direction: column;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  opacity: 1;
  white-space: nowrap; /* Prevent text wrapping during collapse */
}

.sidebar-layout.collapsed .sidebar {
  padding-right: 0;
  border-right: none;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-20px);
}

/* Ensure images and content resize properly */
.reading-content {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  transition: max-width 0.4s ease;
}

.sidebar-layout.collapsed .reading-content {
  max-width: 900px; /* Give it a bit more room when focused */
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  box-shadow: var(--card-shadow);
}

.sidebar-header {
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Hide close button on desktop */
@media (min-width: 1025px) {
  .close-sidebar { display: none; }
}

.sidebar-header h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
  color: var(--text-tertiary);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 40px;
}

/* Sidebar Groups & Links */
.sidebar-group { margin-bottom: 16px; }

.group-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.group-title:hover { opacity: 1; color: var(--accent-primary); }

.group-arrow { 
  width: 14px; height: 14px; 
  transition: transform 0.3s ease; 
  opacity: 0.4;
}

.sidebar-group.collapsed .group-children { display: none; }
.sidebar-group.collapsed .group-arrow { transform: rotate(-90deg); }

.group-children {
  padding-left: 12px;
  border-left: 1px solid var(--border-color);
  margin-left: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-link {
  font-size: 0.9rem;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.4;
  transition: all 0.2s ease;
}

.link-icon { width: 14px; height: 14px; opacity: 0.5; flex-shrink: 0; }

.sidebar-link:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.sidebar-link.active {
  background: var(--bg-surface);
  color: var(--accent-primary);
  font-weight: 600;
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}

.sidebar-link.active .link-icon { opacity: 1; color: var(--accent-primary); }

/* Article Styles */
.reading-content {
  width: 100%;
  max-width: 800px; /* Optimal reading width */
  margin: 0 auto; /* Center the article itself */
}

.article-header {
  text-align: center; /* Centered Title */
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border-color);
}

.article-title {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.article-meta {
  display: flex;
  justify-content: center;
  gap: 24px;
  color: var(--text-tertiary);
  font-size: 0.9rem;
}

.meta-item { display: flex; align-items: center; gap: 6px; }
.meta-item i { width: 14px; height: 14px; }

/* Mobile Toggle */
.mobile-toc-toggle {
  display: none;
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 12px 24px;
  border-radius: 99px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  z-index: 1000;
  align-items: center; gap: 8px;
  font-weight: 600;
  cursor: pointer;
}
.mobile-toc-toggle i { width: 18px; }

/* Responsive Sidebar */
@media (max-width: 1024px) {
  .sidebar-layout { grid-template-columns: 1fr; }
  .sidebar-layout.collapsed { grid-template-columns: 1fr; } /* No change on mobile */
  .sidebar-toggle-btn { display: none; } /* Hide desktop toggle on mobile */
  
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    background: var(--bg-surface);
    z-index: 2000;
    padding: 24px;
    box-shadow: 20px 0 40px rgba(0,0,0,0.1);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    height: 100vh;
    border-right: none;
  }
  
  .sidebar.show { transform: translateX(0); }
  .mobile-toc-toggle { display: flex; }
}

/* Page Footer */
.page-footer {
  margin-top: 80px;
  padding-top: 32px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
}
.footer-link {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-secondary);
  font-weight: 500;
  opacity: 0.7;
}
.footer-link:hover { opacity: 1; color: var(--accent-primary); }

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar { width: 4px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
