:root {
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --border: #e5e7eb;
  --accent-blue: #2563eb;
  --accent-green: #059669;
}

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

body {
  font-family: 'Noto Sans JP', sans-serif;
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.9;
  font-size: 16px;
}

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

strong {
  font-weight: bold;
  background: linear-gradient(transparent 50%, #fff9c4 50%);
}

a:hover {
  text-decoration: underline;
}

/* Header */
header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
}

nav ul {
  display: flex;
  gap: 1.5rem;
  list-style: none;
}

nav a {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Breadcrumb */
.breadcrumb {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--text-muted);
}

/* Main Layout */
.main-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 3rem;
}

/* Article */
article {
  max-width: 100%;
}

.article-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.category-tag {
  display: inline-block;
  background: var(--accent-green);
  color: white;
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 2px;
  margin-bottom: 0.75rem;
  text-decoration: none;
}

.category-tag:hover {
  background: #047857;
  text-decoration: none;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 0.75rem;
}

.article-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Content */
.article-content h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent-blue);
}

.article-content h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 2rem 0 0.75rem;
  padding-left: 0.75rem;
  border-left: 3px solid var(--accent-green);
}

.article-content p {
  margin-bottom: 1.25rem;
}

.article-content ul, .article-content ol {
  margin: 1rem 0 1.25rem 1.5rem;
}

.article-content li {
  margin-bottom: 0.5rem;
}

/* 図（グラフ用） */
.figure {
  margin: 2rem 0;
  text-align: center;
}

.figure-caption {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
}

.figure svg {
  max-width: 100%;
  height: auto;
}

/* 数式（KaTeX用） */
.math-block {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
}

.math-block .katex {
  font-size: 1.15rem;
}

/* ポイント */
.point {
  border: 1px solid var(--accent-green);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
}

.point-title {
  font-weight: 700;
  color: var(--accent-green);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.point p {
  margin: 0;
}

/* テーブル */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  text-align: left;
}

.data-table th {
  font-weight: 700;
}

/* コード */
.code-block {
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.code-header {
  background: #374151;
  color: #d1d5db;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-family: 'Source Code Pro', monospace;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.copy-btn {
  background: #4b5563;
  color: #e5e7eb;
  border: none;
  padding: 0.25rem 0.6rem;
  border-radius: 3px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: 'Noto Sans JP', sans-serif;
  transition: background 0.2s;
}

.copy-btn:hover {
  background: #6b7280;
}

.copy-btn.copied {
  background: #059669;
}

.code-content {
  background: #1f2937;
  overflow-x: auto;
}

.code-content pre {
  margin: 0;
  padding: 1rem;
  font-family: 'Source Code Pro', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}

.code-content pre code {
  font-family: 'Source Code Pro', monospace;
  font-size: 0.85rem;
  background: none;
}

.code-output {
  background: #111827;
  border-top: 1px solid #374151;
  padding: 0.75rem 1rem;
  font-family: 'Source Code Pro', monospace;
  font-size: 0.85rem;
  color: #9ca3af;
  white-space: pre-wrap;
}

/* 注意書き */
.note {
  border: 1px solid #f59e0b;
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.note-title {
  font-weight: 700;
  color: #f59e0b;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

/* 具体例ボックス */
.example {
  border: 1px solid #64b5f6;
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.example-title {
  font-weight: 700;
  color: #1565c0;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

/* 練習問題 */
.problem {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem;
  margin: 1.5rem 0;
}

.problem-text {
  margin-bottom: 1rem;
}

.answer-toggle {
  background: var(--accent-blue);
  color: white;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.answer-content {
  display: none;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.answer-content.show {
  display: block;
}

/* 練習問題（新スタイル） */
.exercise {
  border: 1px solid #666;
  border-radius: 4px;
  padding: 1.25rem;
  margin: 1.5rem 0;
}

.exercise-title {
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.toggle-answer {
  margin-top: 0.75rem;
  padding: 0.4rem 1rem;
  border: 1px solid var(--accent-blue);
  border-radius: 4px;
  background: white;
  color: var(--accent-blue);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}

.toggle-answer:hover {
  background: #e8f0fe;
}

.answer {
  display: none;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}

.answer.show {
  display: block;
}

/* ナビゲーション */
.article-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.95rem;
}

/* サイドバー */
.sidebar {
  position: sticky;
  top: 80px;
  align-self: start;
}

.sidebar-section {
  margin-bottom: 2rem;
}

.sidebar-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.toc-list {
  list-style: none;
}

.toc-list li {
  margin-bottom: 0.5rem;
}

.toc-list a {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.popular-list {
  list-style: none;
}

.popular-item {
  margin-bottom: 0.75rem;
}

.popular-link {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* フッター */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ==================== トップページ ==================== */

.top-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.hero {
  text-align: center;
  padding: 2rem 0 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

.hero h1 {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.hero-desc {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 1.5rem;
}

/* 検索フォーム */
.search-form {
  display: flex;
  max-width: 500px;
  margin: 0 auto;
  gap: 0.5rem;
}

.search-input {
  flex: 1;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.search-btn {
  padding: 0.6rem 1.25rem;
  background: var(--accent-blue);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
}

.search-btn:hover {
  background: #1d4ed8;
}

/* カテゴリセクション */
.category-section {
  margin-bottom: 2.5rem;
}

.category-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent-green);
}

.category-title a {
  color: var(--text-primary);
  text-decoration: none;
}

.category-title a:hover {
  color: var(--accent-green);
}

.category-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.article-list {
  list-style: none;
  margin: 0 0 1rem 0;
  padding: 0;
}

.article-list li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.article-list li a {
  flex: 1;
}

.article-list .no-article {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.article-date {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.more-link {
  font-size: 0.9rem;
  color: var(--accent-blue);
}

/* 検索ページ */
.search-section h1 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.search-section .search-form {
  margin-bottom: 1.5rem;
}

.search-message {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.search-results .article-category {
  display: inline-block;
  background: var(--accent-green);
  color: white;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 2px;
  margin-right: 0.5rem;
}

/* ==================== カテゴリ一覧ページ ==================== */

.category-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.category-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.category-header h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.category-header p {
  color: var(--text-secondary);
}

/* レスポンシブ */
@media (max-width: 768px) {
  .main-container {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  
  .search-form {
    flex-direction: column;
  }
  
  .article-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
}
