/* ===================================
   統計学ノート - 共通スタイル
   =================================== */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --primary-bg: #eff6ff;
    --secondary: #0891b2;
    --accent: #06b6d4;
    --success: #10b981;
    --success-bg: #ecfdf5;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.3s ease;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: 'Noto Sans JP', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 16px;
    line-height: 1.8;
    color: var(--gray-800);
    background: var(--gray-50);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ===================================
   Navigation (共通ナビバー)
   =================================== */

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--gray-200);
    z-index: 100;
}

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

.nav-logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.3px;
    flex-shrink: 0;
}

.nav-logo:hover { opacity: 0.8; }

/* ナビメニュー */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 24px;
    list-style: none;
}

.nav-menu > li > a {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--gray-600);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
    position: relative;
    transition: color 0.2s;
}

.nav-menu > li > a::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    width: 0; height: 2px;
    background: var(--primary);
    transition: width 0.2s;
}

.nav-menu > li > a:hover,
.nav-menu > li > a.active {
    color: var(--primary);
}

.nav-menu > li > a:hover::after,
.nav-menu > li > a.active::after {
    width: 100%;
}

/* ドロップダウン */
.nav-dropdown { position: relative; }

.nav-dropdown-toggle .fa-chevron-down {
    font-size: 0.58rem;
    transition: transform 0.2s;
}

.nav-dropdown:hover .nav-dropdown-toggle .fa-chevron-down {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 14px);
    left: 50%;
    transform: translateX(-50%) translateY(-6px);
    min-width: 200px;
    background: #ffffff;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 500;
    list-style: none;
}

.nav-dropdown:hover .nav-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.nav-dropdown-menu li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 0.87rem;
    font-weight: 500;
    color: var(--gray-700);
    border-radius: 8px;
    transition: all 0.15s;
    white-space: nowrap;
}

.nav-dropdown-menu li a::after { display: none !important; }

.nav-dropdown-menu li a:hover {
    background: var(--gray-50);
    color: var(--primary);
}

.nav-dropdown-menu li a.active {
    color: var(--primary);
    background: #eff6ff;
    font-weight: 600;
}

/* ハンバーガーボタン */
.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.nav-toggle span {
    width: 22px;
    height: 2px;
    background: var(--gray-700);
    transition: all 0.3s;
}

@media (max-width: 768px) {
    .nav-toggle { display: flex; }

    .nav-menu {
        position: fixed;
        top: 60px; left: 0; right: 0;
        background: white;
        flex-direction: column;
        align-items: center;
        gap: 0;
        padding: 0;
        max-height: 0;
        overflow: hidden;
        transition: all 0.3s;
        border-bottom: 1px solid var(--gray-200);
        box-shadow: var(--shadow-lg);
    }

    .nav-menu.active {
        max-height: 500px;
        padding: 12px 0;
    }

    .nav-menu > li { width: 100%; text-align: center; }
    .nav-menu > li > a { justify-content: center; padding: 12px 24px; width: 100%; }

    .nav-dropdown-menu {
        position: static;
        opacity: 1; visibility: visible;
        transform: none;
        box-shadow: none; border: none;
        border-top: 1px solid var(--gray-100);
        border-radius: 0;
        background: var(--gray-50);
        padding: 4px 0;
        min-width: unset;
    }

    .nav-dropdown:hover .nav-dropdown-menu { transform: none; }
    .nav-dropdown-menu li a { justify-content: center; }

    .nav-toggle.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
    .nav-toggle.active span:nth-child(2) { opacity: 0; }
    .nav-toggle.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }
}

/* ===================================
   Hub - Hero
   =================================== */

.stat-hero {
    padding: 110px 0 56px;
    text-align: center;
    background: linear-gradient(135deg, #eff6ff 0%, #e0f2fe 50%, #f0f9ff 100%);
    border-bottom: 1px solid var(--gray-200);
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary);
    color: white;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 18px;
    border-radius: 20px;
    margin-bottom: 20px;
}

.stat-hero h1 {
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.4;
    margin-bottom: 12px;
}

.hero-sub {
    font-size: 15px;
    color: var(--gray-500);
}

/* ===================================
   Hub - Chapter Grid
   =================================== */

.stat-main {
    padding: 40px 0 80px;
}

.chapter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 16px;
}

.chapter-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all var(--transition);
    cursor: pointer;
    opacity: 0;
    transform: translateY(12px);
    animation: fadeInUp 0.4s ease forwards;
}

.chapter-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.chapter-card.hidden {
    display: none;
}

.chapter-card-header {
    display: flex;
    align-items: center;
}

.chapter-num {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-bg);
    padding: 3px 10px;
    border-radius: 6px;
}

.chapter-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-800);
    line-height: 1.5;
}

.chapter-card-arrow {
    color: var(--gray-300);
    font-size: 13px;
    transition: all var(--transition);
    margin-top: auto;
}

.chapter-card:hover .chapter-card-arrow {
    color: var(--primary);
    transform: translateX(4px);
}

@keyframes fadeInUp {
    to { opacity: 1; transform: translateY(0); }
}

/* ===================================
   Chapter Page - Hero
   =================================== */

.chapter-hero {
    padding: 100px 0 36px;
    background: linear-gradient(135deg, #eff6ff 0%, #e0f2fe 50%, #f0f9ff 100%);
    border-bottom: 1px solid var(--gray-200);
}

.chapter-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--gray-400);
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.chapter-breadcrumb a {
    color: var(--gray-500);
    transition: color var(--transition);
}

.chapter-breadcrumb a:hover {
    color: var(--primary);
}

.chapter-label {
    display: inline-block;
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.chapter-hero h1 {
    font-size: clamp(1.4rem, 3vw, 1.9rem);
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.4;
}

/* ===================================
   Chapter Page - Content
   =================================== */

.chapter-body {
    padding: 44px 0 80px;
}

.chapter-content {
    max-width: 820px;
    margin: 0 auto;
}

.content-section {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 28px 32px;
    margin-bottom: 20px;
    transition: border-color var(--transition);
}

.content-section:hover {
    border-color: var(--gray-300);
}

.content-section h2 {
    font-size: 17px;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary-bg);
    display: flex;
    align-items: center;
    gap: 8px;
}

.content-section h2 i {
    color: var(--primary);
    font-size: 15px;
}

.content-section h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-700);
    margin: 20px 0 10px;
}

.content-section p,
.content-section ul,
.content-section ol {
    color: var(--gray-600);
    line-height: 1.9;
    margin-bottom: 12px;
}

.content-section p:last-child,
.content-section ul:last-child {
    margin-bottom: 0;
}

.content-section ul,
.content-section ol {
    padding-left: 1.5em;
}

.content-section ul { list-style: disc; }
.content-section ol { list-style: decimal; }

.content-section code {
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--primary-dark);
}

.content-section pre {
    background: var(--gray-900);
    color: var(--gray-100);
    padding: 20px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 12px 0;
    font-size: 14px;
    line-height: 1.6;
}

.content-section pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.placeholder {
    color: var(--gray-400) !important;
    font-style: italic;
}

/* Problem / Question block */
.example-block {
    border-left: 4px solid var(--gray-500);
    padding: 14px 18px;
    margin: 16px 0;
    background: var(--gray-50);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Answer / Solution block */
.answer-block {
    border-left: 4px dashed var(--gray-300);
    padding: 14px 18px;
    margin: 16px 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* KaTeX formula blocks */
.formula-block {
    background: var(--primary-bg);
    border: 1px solid #dbeafe;
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    margin: 12px 0;
    overflow-x: auto;
    text-align: left;
}



/* ===================================
   Chapter Page - Pager Navigation
   =================================== */

.chapter-pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-top: 44px;
    padding-top: 28px;
    border-top: 1px solid var(--gray-200);
}

.pager-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    transition: all var(--transition);
}

.pager-link:hover {
    border-color: var(--primary-light);
    color: var(--primary);
}

.pager-link.disabled {
    opacity: 0.35;
    pointer-events: none;
}

.pager-home {
    font-size: 13px;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color var(--transition);
}

.pager-home:hover {
    color: var(--primary);
}

/* ===================================
   Footer
   =================================== */

.stat-footer {
    text-align: center;
    padding: 28px 0;
    border-top: 1px solid var(--gray-200);
    font-size: 13px;
    color: var(--gray-400);
}

/* ===================================
   Responsive
   =================================== */

@media (max-width: 768px) {
    .chapter-grid {
        grid-template-columns: 1fr;
    }

    .stat-hero {
        padding: 100px 0 44px;
    }

    .stat-hero h1 {
        font-size: 1.5rem;
    }

    .content-section {
        padding: 20px;
    }

    .chapter-pager {
        flex-direction: column;
        gap: 12px;
    }

    .pager-link {
        width: 100%;
        justify-content: center;
    }

    .filter-bar {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 16px;
    }
}

/* ===================================
   Sidebar TOC Layout (detail pages)
   =================================== */

.chapter-layout {
    display: flex;
    gap: 28px;
    align-items: flex-start;
}

.chapter-toc-sidebar {
    width: 196px;
    flex-shrink: 0;
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 84px);
    overflow-y: auto;
}

.chapter-layout .chapter-content {
    flex: 1;
    min-width: 0;
    max-width: none;
    margin: 0;
}

.toc-box {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.toc-box h2 {
    font-size: 13px;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary-bg);
    display: flex;
    align-items: center;
    gap: 6px;
}

.toc-box h2 i {
    color: var(--primary);
}

.toc-box ol {
    list-style: decimal;
    padding-left: 16px;
    color: var(--gray-500);
    font-size: 12px;
    line-height: 2;
}

.toc-box ol a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}

.toc-box ol a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* ===================================
   Chapter Navigation Panel
   =================================== */

.chapter-nav-box {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-top: 12px;
}

.chapter-nav-box h2 {
    font-size: 13px;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary-bg);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chapter-nav-box h2 i {
    color: var(--primary);
}

.chapter-nav-box ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chapter-nav-box ul li a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 5px;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    color: var(--gray-600);
    font-size: 11.5px;
    line-height: 1.4;
}

.chapter-nav-box ul li a:hover {
    background: var(--primary-bg);
    color: var(--primary-dark);
}

.chapter-nav-box ul li.cnav-current a {
    background: var(--primary);
    color: white;
    font-weight: 700;
}

.cnav-num {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: var(--gray-100);
    color: var(--gray-500);
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.cnav-current a .cnav-num {
    background: rgba(255,255,255,0.25);
    color: white;
}

.cnav-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Section anchor offset for fixed nav */
.section-anchor {
    scroll-margin-top: 76px;
}

/* Concept box */
.concept-box {
    margin: 14px 0;
}

.concept-box .box-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-700);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Memo box */
.memo-box {
    margin: 12px 0;
}

.memo-box .box-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-700);
    margin-bottom: 6px;
}

/* Warn box */
.warn-box {
    margin: 12px 0;
}

.warn-box .box-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-700);
    margin-bottom: 6px;
}

/* Step list with numbered circles */
.step-list {
    counter-reset: step-counter;
    list-style: none !important;
    padding-left: 0 !important;
}

.step-list li {
    counter-increment: step-counter;
    position: relative;
    padding-left: 38px;
    margin-bottom: 10px;
}

.step-list li::before {
    content: counter(step-counter);
    position: absolute;
    left: 0;
    top: 2px;
    width: 26px;
    height: 26px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Distribution summary table */
.dist-table,
.chapter-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin: 14px 0;
}

.dist-table th,
.chapter-content table th {
    background: var(--primary-bg);
    color: #1e40af;
    border: 1px solid #bfdbfe;
    padding: 8px 12px;
    text-align: center;
    font-weight: 700;
}

.dist-table td,
.chapter-content table td {
    border: 1px solid var(--gray-200);
    padding: 8px 12px;
    text-align: center;
    background: white;
    vertical-align: middle;
}

.dist-table tr:hover td,
.chapter-content table tr:hover td {
    background: var(--gray-50);
}

/* Problem / answer badge */
.prob-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    margin-left: 6px;
}

.badge-q {
    background: var(--gray-700);
    color: white;
    padding: 2px 10px;
    border-radius: 4px;
}
.badge-a {
    background: white;
    color: var(--gray-600);
    border: 1.5px solid var(--gray-300);
    padding: 2px 10px;
    border-radius: 4px;
}

@media (max-width: 900px) {
    .chapter-layout {
        flex-direction: column;
    }

    .chapter-toc-sidebar {
        width: 100%;
        position: static;
        max-height: none;
    }
}
