:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace;
  
  /* Light Theme Defaults */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-sidebar: #f1f5f9;
  --bg-header: rgba(255, 255, 255, 0.85);
  --bg-card: #ffffff;
  --bg-code: #0f172a;
  --bg-code-inline: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-sub: #64748b;
  --text-code-inline: #0f172a;
  
  --border-color: #e2e8f0;
  --border-light: #f1f5f9;
  
  --brand-primary: #1d4ed8;
  --brand-hover: #1e40af;
  --brand-light: #eff6ff;
  
  --accent-green: #059669;
  --accent-green-bg: #ecfdf5;
  --accent-yellow: #d97706;
  --accent-yellow-bg: #fffbeb;
  --accent-purple: #7c3aed;
  --accent-purple-bg: #f5f3ff;
  --accent-red: #dc2626;
  --accent-red-bg: #fef2f2;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  
  --header-height: 64px;
  --sidebar-width: 280px;
}

[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-surface: #0f172a;
  --bg-sidebar: #0b1120;
  --bg-header: rgba(15, 23, 42, 0.85);
  --bg-card: #131d33;
  --bg-code: #030712;
  --bg-code-inline: #1e293b;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sub: #64748b;
  --text-code-inline: #38bdf8;
  
  --border-color: #1e293b;
  --border-light: #172033;
  
  --brand-primary: #38bdf8;
  --brand-hover: #0284c7;
  --brand-light: rgba(56, 189, 248, 0.1);
  
  --accent-green: #10b981;
  --accent-green-bg: rgba(16, 185, 129, 0.1);
  --accent-yellow: #f59e0b;
  --accent-yellow-bg: rgba(245, 158, 11, 0.1);
  --accent-purple: #a855f7;
  --accent-purple-bg: rgba(168, 85, 247, 0.1);
  --accent-red: #f43f5e;
  --accent-red-bg: rgba(244, 63, 94, 0.1);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.75;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: var(--brand-primary);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  text-decoration: underline;
}

/* Header */
.doc-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text-main);
}

.header-brand:hover {
  text-decoration: none;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1d4ed8, #0284c7);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 2px 4px rgba(29, 78, 216, 0.3);
}

.brand-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  background: var(--brand-light);
  color: var(--brand-primary);
  border: 1px solid var(--border-color);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-link {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.nav-link:hover {
  color: var(--text-main);
  background: var(--brand-light);
  text-decoration: none;
}

.nav-link.active {
  color: var(--brand-primary);
  background: var(--brand-light);
  font-weight: 600;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle-btn:hover {
  border-color: var(--brand-primary);
}

.btn-terminal {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--brand-primary);
  color: #ffffff !important;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.15s ease;
}

.btn-terminal:hover {
  opacity: 0.9;
  text-decoration: none;
}

/* Layout */
.doc-container {
  display: flex;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-height));
}

/* Sidebar */
.doc-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  padding: 24px 16px;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-sub);
  margin-bottom: 8px;
  padding: 0 8px;
}

.sidebar-menu {
  list-style: none;
}

.sidebar-item a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.sidebar-item a:hover {
  color: var(--text-main);
  background: var(--bg-surface);
  text-decoration: none;
}

.sidebar-item.active a {
  color: var(--brand-primary);
  background: var(--bg-surface);
  font-weight: 600;
  border-left: 3px solid var(--brand-primary);
}

.sidebar-toc {
  margin-top: 16px;
  padding-left: 12px;
  border-left: 1px dashed var(--border-color);
}

.sidebar-toc a {
  display: block;
  padding: 4px 8px;
  font-size: 12.5px;
  color: var(--text-sub);
}

.sidebar-toc a:hover {
  color: var(--brand-primary);
  text-decoration: none;
}

/* Main Content Area */
.doc-main {
  flex: 1;
  min-width: 0;
  padding: 40px 48px 80px 48px;
  max-width: 960px;
}

/* Typography & Elements */
.doc-article h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-bottom: 16px;
  color: var(--text-main);
}

.doc-article h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.doc-article h3 {
  font-size: 18px;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--text-main);
}

.doc-article h4 {
  font-size: 15px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

.doc-article p {
  margin-bottom: 18px;
  color: var(--text-muted);
}

.doc-article ul, .doc-article ol {
  margin-bottom: 20px;
  padding-left: 24px;
  color: var(--text-muted);
}

.doc-article li {
  margin-bottom: 8px;
}

.doc-article hr {
  border: 0;
  height: 1px;
  background: var(--border-color);
  margin: 40px 0;
}

/* Callout Boxes */
.callout {
  padding: 16px 20px;
  border-radius: 10px;
  margin: 24px 0;
  border-left: 4px solid;
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.callout-info {
  border-color: var(--brand-primary);
  background: var(--brand-light);
}

.callout-success {
  border-color: var(--accent-green);
  background: var(--accent-green-bg);
}

.callout-warning {
  border-color: var(--accent-yellow);
  background: var(--accent-yellow-bg);
}

.callout-danger {
  border-color: var(--accent-red);
  background: var(--accent-red-bg);
}

.callout-title {
  font-weight: 700;
  font-size: 14.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.callout p:last-child {
  margin-bottom: 0;
}

/* Tables */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin: 24px 0;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  background: var(--bg-surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  text-align: left;
}

th {
  background: var(--bg-sidebar);
  color: var(--text-main);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-muted);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--brand-light);
}

/* Code Blocks */
pre {
  position: relative;
  background: var(--bg-code);
  color: #f8fafc;
  padding: 18px 20px;
  border-radius: 10px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  margin: 20px 0;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

pre code {
  color: inherit;
  background: transparent;
  padding: 0;
  font-size: inherit;
}

code {
  font-family: var(--font-mono);
  background: var(--bg-code-inline);
  color: var(--text-code-inline);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e293b;
  padding: 6px 14px;
  border-radius: 8px 8px 0 0;
  font-size: 12px;
  color: #94a3b8;
  font-family: var(--font-mono);
  border-bottom: 1px solid #334155;
}

.copy-btn {
  background: transparent;
  border: 1px solid #475569;
  color: #cbd5e1;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.copy-btn:hover {
  background: #334155;
  color: #ffffff;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}

.badge-blue { background: var(--brand-light); color: var(--brand-primary); }
.badge-green { background: var(--accent-green-bg); color: var(--accent-green); }
.badge-yellow { background: var(--accent-yellow-bg); color: var(--accent-yellow); }
.badge-purple { background: var(--accent-purple-bg); color: var(--accent-purple); }

/* Portal Cards (for index.html) */
.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 24px;
  margin: 32px 0;
}

.portal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 28px;
  transition: all 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  text-decoration: none !important;
}

.portal-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--brand-primary);
}

.card-icon {
  font-size: 32px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 10px;
}

.card-desc {
  font-size: 14px;
  color: var(--text-muted);
  flex-grow: 1;
  margin-bottom: 20px;
  line-height: 1.6;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  font-size: 12.5px;
  color: var(--text-sub);
}

/* Kids Story Stylings */
.story-character {
  display: flex;
  gap: 16px;
  margin: 24px 0;
  align-items: flex-start;
}

.avatar-bubble {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.avatar-owl {
  background: linear-gradient(135deg, #fbbf24, #d97706);
  border: 2px solid #f59e0b;
}

.avatar-boy {
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  border: 2px solid #3b82f6;
}

.avatar-chief {
  background: linear-gradient(135deg, #f87171, #dc2626);
  border: 2px solid #ef4444;
}

.speech-bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px 20px;
  position: relative;
  flex: 1;
  box-shadow: var(--shadow-sm);
}

.speaker-name {
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Mermaid Container */
.mermaid-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 24px;
  margin: 24px 0;
  overflow-x: auto;
  text-align: center;
}

/* Responsive */
@media (max-width: 900px) {
  .doc-container {
    flex-direction: column;
  }
  .doc-sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
  .doc-main {
    padding: 24px 20px 60px 20px;
  }
  .header-nav {
    display: none;
  }
}
