/* ============================================
   とものページ — 共通デザインシステム
   ============================================ */

/* ===== リセット・ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-bg: #f5f5f0;
    --color-surface: #ffffff;
    --color-primary: #2d2b7c;
    --color-primary-light: #4a47a3;
    --color-accent: #e8a317;
    --color-text: #1a1a2e;
    --color-text-muted: #555570;
    --color-border: #ddd8d0;
    --color-link: #1a4fc9;
    --color-link-visited: #5b21b6;
    --color-success: #166534;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,.12);
    --transition: .2s ease;
}

/* ===== スキップナビゲーション (WCAG 2.4.1) ===== */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--color-primary);
    color: #fff;
    padding: 10px 20px;
    z-index: 9999;
    font-size: 14px;
    text-decoration: underline;
    border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { top: 0; }

/* スクリーンリーダー専用 */
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ===== 全体 ===== */
body {
    font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.7;
    font-size: 15px;
    min-height: 100vh;
}

/* ===== リンク (WCAG 1.4.3) ===== */
a:link { color: var(--color-link); }
a:visited { color: var(--color-link-visited); }
a:active { color: #b91c1c; }
a { transition: color var(--transition), opacity var(--transition); text-underline-offset: 3px; }
a:hover { opacity: .8; }

/* フォーカス (WCAG 2.4.7, 2.4.11, 2.4.13) */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ターゲットサイズ (WCAG 2.5.8) */
a { display: inline-block; min-height: 24px; }

/* ===== ヘッダー ===== */
.site-header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    color: #fff;
    padding: 24px 32px;
    text-align: center;
    box-shadow: var(--shadow-md);
    position: relative;
}
.site-header h1 {
    font-size: clamp(1.5rem, 4vw, 2.2rem);
    font-weight: 700;
    letter-spacing: .05em;
    margin-bottom: 4px;
}
.site-header .meta {
    font-size: .8rem;
    opacity: .85;
}
.site-header .breadcrumb {
    font-size: .8rem;
    margin-top: 6px;
    opacity: .85;
}
.site-header .breadcrumb a {
    color: #bfdbfe;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.site-header .breadcrumb a:hover { opacity: 1; color: #fff; }

/* 訪問者バナー (index.html用) */
.visitor-banner {
    background: rgba(255,255,255,.12);
    backdrop-filter: blur(4px);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    margin-top: 12px;
    display: inline-block;
    font-size: .95rem;
}
.visitor-msg--first { color: #bfdbfe; }
.visitor-msg--return { color: #bbf7d0; }

/* ===== 3ペインレイアウト (CSS Grid) ===== */
.layout {
    display: grid;
    grid-template-columns: 240px 1fr 260px;
    gap: 24px;
    max-width: 1280px;
    margin: 24px auto;
    padding: 0 20px;
    align-items: start;
}

/* 2ペインレイアウト (サブページ用) */
.layout-2col {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 24px;
    max-width: 1100px;
    margin: 24px auto;
    padding: 0 20px;
    align-items: start;
}

/* レスポンシブ (3ペイン) */
@media (max-width: 960px) {
    .layout {
        grid-template-columns: 220px 1fr;
    }
    .pane-right { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
    .layout, .layout-2col {
        grid-template-columns: 1fr;
        padding: 0 12px;
        gap: 16px;
    }
}
/* レスポンシブ (2ペイン) */
@media (max-width: 768px) {
    .layout-2col {
        grid-template-columns: 1fr;
        padding: 0 12px;
        gap: 16px;
    }
}

/* ===== カード共通 ===== */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--color-accent);
    display: flex;
    align-items: center;
    gap: 6px;
}
.card-header .icon { font-size: 1.15em; }

/* ===== 左ペイン: ナビゲーション ===== */
.pane-left { position: sticky; top: 24px; }
.nav-list { list-style: none; }
.nav-list li { margin-bottom: 2px; }
.nav-list a {
    display: block;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    color: var(--color-text);
    transition: background var(--transition), color var(--transition);
    min-height: 40px;
    line-height: 1.4;
}
.nav-list a:hover,
.nav-list a:focus-visible {
    background: rgba(45,43,124,.06);
    color: var(--color-primary);
}
.nav-list a.current {
    background: rgba(45,43,124,.1);
    color: var(--color-primary);
    font-weight: 700;
}
.nav-desc {
    display: block;
    font-size: .75rem;
    font-weight: 400;
    color: var(--color-text-muted);
    margin-top: 2px;
    line-height: 1.4;
}

/* ===== 中央ペイン: メイン ===== */
.pane-center { min-width: 0; }
.notice-box {
    background: linear-gradient(135deg, #fef9c3 0%, #fef3c7 100%);
    border-left: 4px solid var(--color-accent);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    margin-bottom: 20px;
    font-size: .9rem;
}
.notice-box strong { color: #92400e; }

.kiriban-list { font-size: .85rem; }
.kiriban-list dt { font-weight: 600; color: var(--color-primary); display: inline; }
.kiriban-list dd { display: inline; margin-left: 4px; margin-right: 16px; }

/* ===== 右ペイン: サイドバー ===== */
.pane-right .card + .card { margin-top: 16px; }

.banner-img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}
.seti-link { display: block; text-align: center; }
.seti-link img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }

/* ===== フッター ===== */
.site-footer {
    background: var(--color-primary);
    color: rgba(255,255,255,.8);
    text-align: center;
    padding: 20px 32px;
    margin-top: 40px;
    font-size: .8rem;
}
.site-footer a { color: #93c5fd; }
.site-footer a:visited { color: #c4b5fd; }

/* 意図的に背景に溶け込む隠しリンク (index.html用) */
.subtle-link { color: var(--color-bg); text-decoration: none; font-size: .7rem; }
.subtle-link:visited { color: var(--color-bg); }
.subtle-link:hover, .subtle-link:focus-visible { color: var(--color-text-muted); }

/* カウンター画像 */
.counter-img { opacity: .5; margin-top: 8px; }

/* ===== サブページ: コンテンツ用スタイル ===== */
.content-body {
    line-height: 1.8;
    font-size: .95rem;
}
.content-body p {
    margin-bottom: 1em;
}
.content-body h2 {
    background: var(--color-primary);
    color: #fff;
    text-align: center;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 1.1rem;
    margin: 2em 0 1em;
}
.content-body h2:first-child {
    margin-top: 0;
}
.content-body h3 {
    color: var(--color-primary);
    font-size: 1rem;
    margin: 1.5em 0 .8em;
    padding-left: 12px;
    border-left: 3px solid var(--color-accent);
}
.content-body a:link { color: var(--color-link); }
.content-body a:visited { color: var(--color-link-visited); }

/* テーブル (サブページ用) */
.content-body table {
    border-collapse: collapse;
    margin: 1em auto;
    width: auto;
    max-width: 100%;
    font-size: .9rem;
    overflow-x: auto;
}
.content-body th,
.content-body td {
    border: 1px solid var(--color-border);
    padding: 8px 12px;
    text-align: left;
}
.content-body th {
    background: var(--color-primary);
    color: #fff;
    font-weight: 600;
}
.content-body tr:nth-child(even) {
    background: rgba(0,0,0,.02);
}
.content-body tr:hover {
    background: rgba(45,43,124,.04);
}
/* レガシーのテーブルclassとの互換 */
.content-body table.a { width: 90%; }
.content-body .head {
    background-color: var(--color-accent);
    font-weight: bold;
    font-size: 1em;
    padding: 10px 14px;
    color: var(--color-text);
}
.content-body .body {
    background-color: #fdf6e3;
    padding: 10px 14px;
}
.content-body .st {
    background-color: #e8e4a0;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
}

/* コードブロック風 (白背景のtablのボーダー付き) */
.content-body table[border] tr[bgcolor='white'] td {
    background: var(--color-surface);
    font-family: "Consolas", "Source Code Pro", monospace;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

/* リスト */
.content-body li {
    margin-bottom: .5em;
    margin-left: 1.2em;
}
.content-body ul { list-style-type: disc; margin: .5em 0 1em 1.5em; }

/* 取り消し線 */
.content-body s { color: var(--color-text-muted); }

/* リンクカード (link.htm用) */
.link-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 12px;
    transition: box-shadow var(--transition);
}
.link-item:hover { box-shadow: var(--shadow-sm); }
.link-item a { font-weight: 600; }
.link-item .link-desc {
    font-size: .85rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}
.link-item img {
    max-height: 40px;
    vertical-align: middle;
    margin-right: 8px;
    border-radius: 4px;
}

/* セクションの仕切り */
.section-divider {
    border: none;
    height: 1px;
    background: var(--color-border);
    margin: 2em 0;
}

/* ダウンロードリンク */
.download-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--color-primary);
    color: #fff !important;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    transition: background var(--transition);
    margin: 4px 2px;
}
.download-link:visited { color: #fff !important; }
.download-link:hover { background: var(--color-primary-light); opacity: 1; }

/* テーブルレスポンシブ */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1em 0;
}
.table-responsive table {
    min-width: 500px;
}

/* ===== 全画像レスポンシブ ===== */
img { max-width: 100%; height: auto; }

/* ===== モバイルナビゲーショントグル ===== */
.nav-toggle { display: none; }
.nav-toggle-label { display: none; }

/* ===== タッチデバイス最適化 ===== */
@media (hover: none) and (pointer: coarse) {
    /* ホバーエフェクト無効化 (タップ時のちらつき防止) */
    .card:hover { box-shadow: var(--shadow-sm); }
    .link-item:hover { box-shadow: none; }

    /* タップターゲット拡大 (WCAG 2.5.8 推奨 44x44px) */
    .nav-list a { min-height: 44px; display: flex; align-items: center; }
    .download-link { min-height: 44px; }
}

/* ===== 768px以下: タブレット縦・大型スマホ横 ===== */
@media (max-width: 768px) {
    .site-header { padding: 18px 16px; }
    .site-header h1 { letter-spacing: .02em; }

    /* sticky 解除 (1カラム時に不要) */
    .pane-left { position: static; }

    /* カード縮小 */
    .card { padding: 16px; }

    /* テーブルの横スクロール対応 */
    .content-body table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* フッター */
    .site-footer { padding: 16px; }
}

/* ===== 640px以下: モバイルナビトグル表示 ===== */
@media (max-width: 640px) {
    /* ハンバーガートグルボタン表示 */
    .nav-toggle-label {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 14px;
        cursor: pointer;
        font-size: .9rem;
        font-weight: 700;
        color: var(--color-primary);
        border-bottom: 2px solid var(--color-accent);
        margin-bottom: 0;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }
    .nav-toggle-label .hamburger {
        display: flex;
        flex-direction: column;
        gap: 4px;
        width: 22px;
    }
    .nav-toggle-label .hamburger span {
        display: block;
        height: 2px;
        background: var(--color-primary);
        border-radius: 1px;
        transition: transform var(--transition), opacity var(--transition);
    }

    /* ナビリストを非表示、トグルで表示 */
    .card-header.nav-header-desktop { display: none; }
    .nav-list {
        max-height: 0;
        overflow: hidden;
        transition: max-height .3s ease;
    }
    .nav-toggle:checked ~ .nav-list {
        max-height: 500px;
    }

    /* トグル開閉時のハンバーガーアニメーション */
    .nav-toggle:checked ~ .nav-toggle-label .hamburger span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }
    .nav-toggle:checked ~ .nav-toggle-label .hamburger span:nth-child(2) {
        opacity: 0;
    }
    .nav-toggle:checked ~ .nav-toggle-label .hamburger span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    /* ナビをコンパクト化 */
    .nav-desc { display: none; }
    .nav-list a {
        padding: 10px 14px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* ===== 480px以下: スマートフォン ===== */
@media (max-width: 480px) {
    body { font-size: 14px; }

    .site-header { padding: 14px 12px; }
    .site-header h1 { letter-spacing: 0; }
    .site-header .meta,
    .site-header .breadcrumb { font-size: .75rem; }

    .visitor-banner { padding: 6px 12px; font-size: .85rem; }

    .layout, .layout-2col {
        padding: 0 10px;
        gap: 12px;
        margin: 12px auto;
    }

    .card {
        padding: 12px;
        border-radius: var(--radius-sm);
    }
    .card-header { font-size: .9rem; margin-bottom: 8px; padding-bottom: 6px; }

    /* コンテンツ */
    .content-body { font-size: .88rem; }
    .content-body h2 { font-size: .95rem; padding: 8px 12px; margin: 1.5em 0 .8em; }
    .content-body h3 { font-size: .9rem; }
    .content-body th,
    .content-body td { padding: 6px 8px; font-size: .8rem; }

    /* お知らせ */
    .notice-box { padding: 10px 12px; font-size: .82rem; }

    /* キリ番リスト (インライン → ブロック) */
    .kiriban-list dt { display: block; }
    .kiriban-list dd { display: block; margin-left: 1em; margin-bottom: .5em; }

    /* リンクカード */
    .link-item { padding: 12px; }
    .link-item img { max-height: 32px; }

    /* ダウンロードリンク (幅いっぱい) */
    .download-link {
        width: 100%;
        justify-content: center;
        padding: 10px 14px;
    }

    /* フッター */
    .site-footer { padding: 14px 12px; font-size: .7rem; }
}

/* ===== セーフエリア対応 (ノッチ付きデバイス) ===== */
@supports (padding: env(safe-area-inset-left)) {
    .site-header {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    .site-footer {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    .layout, .layout-2col {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
}

/* ===== 印刷最適化 ===== */
@media print {
    .skip-link, .pane-left, .pane-right,
    .site-footer, .counter-img,
    .nav-toggle-label { display: none; }

    .layout, .layout-2col { display: block; }

    .card { box-shadow: none; border: 1px solid #ccc; }
    .site-header {
        background: #fff;
        color: #000;
        box-shadow: none;
        border-bottom: 2px solid #333;
    }
    .site-header h1 { color: #000; }
    .site-header .breadcrumb a { color: #333; }
}
