/* ═══════════════════════════════════════════════════════════════
   PICO 教育DX用語辞典 ― メインスタイルシート
   v2.0 (2026-05) 読みやすさ改善 / バリアフリー / ダークモード対応
   ═══════════════════════════════════════════════════════════════ */

/* ─── CSS変数(テーマ + 文字サイズ) ─────────────────────────── */
:root {
    /* タイポグラフィ ─ ユーザーが a11y ボタンで切替 */
    --font-base: 17px;          /* 本文(切替対象) */
    --font-scale: 1.0;           /* 全体倍率(切替対象) */

    /* レイアウト */
    --container-max: 1200px;
    --reading-max: 42em;         /* 本文の最適行長 */

    /* カラー(ライトテーマ) */
    --c-bg:        #f4f6f8;
    --c-card-bg:  #ffffff;
    --c-card-soft:#f8fbff;
    --c-text:     #2c3e50;
    --c-text-soft:#5a6c7d;
    --c-text-muted:#6c757d;
    --c-line:     #e1e8ed;

    --c-primary:    #0075c1;
    --c-primary-dk: #005a87;
    --c-primary-soft:#e3f2fd;
    --c-accent:     #0d47a1;

    --c-success:    #2e7d32;
    --c-success-soft:#e8f5e9;
    --c-warning-bg: #fff8e1;
    --c-warning-bd: #f0b400;
    --c-danger:     #c62828;
    --c-danger-soft:#ffebee;

    --c-shadow:    0 2px 12px rgba(0, 0, 0, 0.08);
    --c-shadow-sm: 0 1px 6px rgba(0, 0, 0, 0.06);

    /* 行間・字間 ─ 日本語最適 */
    --lh-body: 1.85;
    --lh-tight: 1.5;
    --ls-body: 0.04em;
}

/* ─── ダークモード(自動 + 手動切替の両対応) ─────────────── */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --c-bg:        #121821;
        --c-card-bg:  #1c2632;
        --c-card-soft:#19232f;
        --c-text:     #e8eef4;
        --c-text-soft:#b0bec5;
        --c-text-muted:#90a4ae;
        --c-line:     #2c3845;

        --c-primary:    #4fc3f7;
        --c-primary-dk: #29b6f6;
        --c-primary-soft:#0d3a52;
        --c-accent:     #82b1ff;

        --c-success:    #81c784;
        --c-success-soft:#1b3a1f;
        --c-warning-bg: #3a2e10;
        --c-danger:     #ef9a9a;
        --c-danger-soft:#3a1818;

        --c-shadow:    0 2px 12px rgba(0, 0, 0, 0.5);
        --c-shadow-sm: 0 1px 6px rgba(0, 0, 0, 0.4);
    }
}

:root[data-theme="dark"] {
    --c-bg:        #121821;
    --c-card-bg:  #1c2632;
    --c-card-soft:#19232f;
    --c-text:     #e8eef4;
    --c-text-soft:#b0bec5;
    --c-text-muted:#90a4ae;
    --c-line:     #2c3845;
    --c-primary:    #4fc3f7;
    --c-primary-dk: #29b6f6;
    --c-primary-soft:#0d3a52;
    --c-accent:     #82b1ff;
    --c-success:    #81c784;
    --c-success-soft:#1b3a1f;
    --c-warning-bg: #3a2e10;
    --c-danger:     #ef9a9a;
    --c-danger-soft:#3a1818;
    --c-shadow:    0 2px 12px rgba(0, 0, 0, 0.5);
    --c-shadow-sm: 0 1px 6px rgba(0, 0, 0, 0.4);
}

/* ─── リセット ──────────────────────────────────────────────── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: calc(var(--font-base) * var(--font-scale));
}

body {
    font-family: "Hiragino Kaku Gothic ProN", "ヒラギノ角ゴシック ProN",
                 "Yu Gothic Medium", "游ゴシック Medium",
                 "Noto Sans JP", "Meiryo", sans-serif;
    line-height: var(--lh-body);
    letter-spacing: var(--ls-body);
    color: var(--c-text);
    background-color: var(--c-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ═══ サイトヘッダー ══════════════════════════════════════════ */
/* `.site-header` クラスを使用 ─ 用語カード内の <header class="term-header"> と衝突しないように */
.site-header {
    background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-dk) 100%);
    color: #ffffff;
    padding: 1rem 0;
    box-shadow: var(--c-shadow);
}

.header-container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.logo {
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.subtitle {
    font-size: 0.875rem;
    opacity: 0.92;
    margin-top: 0.2rem;
    font-weight: 500;
}

.data-info {
    text-align: right;
    font-size: 0.85rem;
    opacity: 0.92;
    line-height: 1.6;
}

/* ═══ a11y(バリアフリー)ツールバー ══════════════════════════ */
.a11y-bar {
    background: var(--c-card-bg);
    border-bottom: 1px solid var(--c-line);
    padding: 0.5rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--c-shadow-sm);
    transition: background-color 0.3s ease;
}

.a11y-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--c-text-soft);
    flex-wrap: wrap;
}

.a11y-label {
    font-weight: 600;
    margin-right: 0.25rem;
}

.a11y-group {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0 0.5rem;
    border-right: 1px solid var(--c-line);
}
.a11y-group:last-child { border-right: none; }

.a11y-btn {
    background: transparent;
    border: 1px solid var(--c-line);
    color: var(--c-text);
    padding: 0.3rem 0.7rem;
    border-radius: 5px;
    font-size: 0.85rem;
    cursor: pointer;
    line-height: 1;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}
.a11y-btn:hover { background: var(--c-primary-soft); color: var(--c-accent); }
.a11y-btn:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }
.a11y-btn.active {
    background: var(--c-primary);
    color: #fff;
    border-color: var(--c-primary);
}

.a11y-btn[aria-pressed="true"] {
    background: var(--c-primary);
    color: #fff;
    border-color: var(--c-primary);
}

/* モバイル用トグルボタン(デフォルト非表示) */
.a11y-toggle {
    display: none;
    background: var(--c-primary);
    color: #fff;
    border: none;
    padding: 0.55rem 1.1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    align-items: center;
    gap: 0.4rem;
    box-shadow: var(--c-shadow-sm);
    font-family: inherit;
}
.a11y-toggle:hover { background: var(--c-primary-dk); }
.a11y-toggle .a11y-arrow {
    display: inline-block;
    transition: transform 0.25s ease;
}
.a11y-toggle[aria-expanded="true"] .a11y-arrow {
    transform: rotate(180deg);
}

/* ═══ コンテナ ════════════════════════════════════════════════ */
.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 20px;
}

/* ═══ デバッグ情報 ════════════════════════════════════════════ */
.debug-info {
    background: var(--c-card-bg);
    color: var(--c-text);
    border-radius: 10px;
    padding: 1.5rem;
    margin: 1rem 0;
    box-shadow: var(--c-shadow);
}

.status-success { border-left: 4px solid var(--c-success); background: var(--c-success-soft); }
.status-error   { border-left: 4px solid var(--c-danger);  background: var(--c-danger-soft); }

/* ═══ 検索セクション ═════════════════════════════════════════ */
.search-section {
    background: var(--c-card-bg);
    padding: 2rem;
    border-radius: 12px;
    margin: 2rem 0;
    box-shadow: var(--c-shadow);
    text-align: center;
}

.search-section h2 {
    font-size: 1.35rem;
    color: var(--c-accent);
    margin-bottom: 0.8rem;
    font-weight: 700;
}

.search-box {
    display: flex;
    max-width: 600px;
    margin: 1rem auto;
    gap: 10px;
}

.search-input {
    flex: 1;
    padding: 0.85rem 1.2rem;
    border: 2px solid var(--c-line);
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
    background: var(--c-card-bg);
    color: var(--c-text);
    transition: border-color 0.3s ease;
    font-family: inherit;
}
.search-input:focus { border-color: var(--c-primary); }
.search-input::placeholder { color: var(--c-text-muted); }

.search-btn {
    background: var(--c-primary);
    color: #ffffff;
    border: none;
    padding: 0.85rem 2rem;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.3s ease;
    font-family: inherit;
}
.search-btn:hover { background: var(--c-primary-dk); }

/* ═══ カテゴリフィルター ═════════════════════════════════════ */
.category-filter { margin-top: 1rem; }

.category-btn {
    background: var(--c-bg);
    border: 1px solid var(--c-line);
    color: var(--c-text);
    padding: 0.55rem 1.1rem;
    border-radius: 20px;
    cursor: pointer;
    margin: 0.25rem;
    font-size: 0.92rem;
    font-weight: 500;
    transition: all 0.3s ease;
    font-family: inherit;
}
.category-btn.active,
.category-btn:hover {
    background: var(--c-primary);
    color: #ffffff;
    border-color: var(--c-primary);
}
.category-btn .count {
    font-size: 0.82em;
    opacity: 0.85;
    font-weight: normal;
    margin-left: 0.3rem;
}
.category-btn.active .count { opacity: 1; font-weight: 500; }

/* ═══ パンくず(個別用語ページ用) ══════════════════════════════ */
.breadcrumb {
    margin: 1.5rem 0 0.5rem;
    font-size: 0.9rem;
    color: var(--c-text-soft);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.breadcrumb a {
    color: var(--c-accent);
    text-decoration: none;
    font-weight: 500;
}
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb [aria-current="page"] {
    color: var(--c-text);
    font-weight: 600;
}

/* ═══ 個別用語ページ仕様 ══════════════════════════════════════ */
.term-single {
    background: var(--c-card-bg);
    margin: 1.5rem 0 2rem;
}
.term-single .term-header { padding: 2rem 2rem 1.5rem; }
.term-single .term-details { max-height: none !important; }
.term-single .term-details-content { padding: 0 2rem 2rem; }
.term-single .btn-back {
    display: inline-block;
    padding: 0.7rem 1.5rem;
    background: var(--c-primary-soft);
    border-radius: 25px;
    text-decoration: none;
    transition: all 0.2s ease;
}
.term-single .btn-back:hover {
    background: var(--c-accent);
    color: #fff !important;
}

@media (max-width: 768px) {
    .term-single .term-header { padding: 1.2rem; }
    .term-single .term-details-content { padding: 0 1.2rem 1.2rem; }
}

/* ═══ 用語コンテナ ════════════════════════════════════════════ */
.terms-container {
    border-radius: 12px;
    margin: 2rem 0;
    min-height: 400px;
}

@media (min-width: 769px) {
    .terms-container {
        background: var(--c-card-bg);
        padding: 2rem;
        box-shadow: var(--c-shadow);
    }
}

/* ═══ 用語カード ══════════════════════════════════════════════ */
.term-card {
    background: var(--c-card-soft);
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
    box-shadow: var(--c-shadow-sm);
    border: 1px solid var(--c-line);
}

.term-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    cursor: pointer;
    transition: background 0.3s ease;
}
.term-header:hover { background: var(--c-primary-soft); }

.term-info { flex: 1; }

.term-word {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--c-accent);
    margin-bottom: 0.35rem;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

.term-reading {
    font-size: 0.95rem;
    color: var(--c-text-soft);
    margin-bottom: 0.6rem;
    font-weight: 500;
}

/* ふりがな強調モード */
body.furigana-on .term-reading {
    color: var(--c-accent);
    font-weight: 600;
    font-size: 1.05rem;
    background: var(--c-primary-soft);
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
}

.term-short-desc {
    color: var(--c-text);
    font-size: 1rem;
    line-height: 1.75;
    margin-bottom: 0.9rem;
    max-width: var(--reading-max);
}

.term-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge {
    padding: 0.35rem 0.95rem;
    border-radius: 14px;
    font-size: 0.85rem;
    font-weight: 600;
}
.badge.category { background: var(--c-primary-soft); color: var(--c-accent); }
.badge.level    { background: var(--c-success-soft); color: var(--c-success); }

.expand-btn {
    background: transparent;
    border: 2px solid var(--c-primary);
    color: var(--c-primary);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 700;
    transition: all 0.3s ease;
    flex-shrink: 0;
    font-family: inherit;
}
.expand-btn:hover,
.expand-btn.active {
    background: var(--c-primary);
    color: #ffffff;
}

/* ═══ 詳細展開部 ══════════════════════════════════════════════ */
.term-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
    background: var(--c-card-bg);
}
.term-details.expanded { max-height: 5000px; }

.term-details-content {
    padding: 2rem;
    border-top: 1px solid var(--c-line);
}

.detail-section { margin-bottom: 1.75rem; }

.detail-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--c-accent);
    margin-bottom: 0.9rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--c-primary-soft);
}

/* 詳細説明本文 ― 読みやすさ最優先 */
.detail-description {
    background: var(--c-card-soft);
    padding: 1.4rem 1.6rem;
    border-radius: 0 8px 8px 0;
    border-left: 4px solid var(--c-accent);
    font-size: 1.0625rem;        /* 17px */
    line-height: 1.85;
    letter-spacing: 0.04em;
    color: var(--c-text);
    max-width: var(--reading-max);
}
.detail-description strong {
    color: var(--c-accent);
    font-weight: 600;
}

/* 例(Examplesは index.php 内のJSでインライン styleが効くため、補強として) */
.detail-section .example,
.detail-section [data-example] {
    background: var(--c-card-soft);
    color: var(--c-text);
    padding: 0.95rem 1.2rem;
    margin-bottom: 0.55rem;
    border-radius: 0 6px 6px 0;
    border-left: 3px solid var(--c-success);
    font-size: 1rem;
    line-height: 1.75;
}

/* タグ(.detail-tag)― WCAG AAA合格(コントラスト 7.56:1) */
.detail-tags,
.detail-relateds {
    background: var(--c-card-soft);
    padding: 0.9rem 1rem;
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.detail-tag,
.detail-related {
    display: inline-block;
    background: var(--c-primary-soft);
    color: var(--c-accent);                /* #0d47a1 ← AAA */
    border: 1px solid var(--c-accent);
    padding: 0.4rem 0.95rem;
    border-radius: 15px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    font-family: inherit;
    line-height: 1.4;
    text-decoration: none;       /* aタグ用 */
}
.detail-related:visited { color: var(--c-accent); }
.detail-tag:hover,
.detail-tag:focus-visible,
.detail-related:hover,
.detail-related:focus-visible {
    background: var(--c-accent);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(13, 71, 161, 0.25);
    outline: none;
}

/* 関連用語は🔗マークを擬似要素で前置 */
.detail-related::before {
    content: "🔗 ";
    margin-right: 0.15em;
}

/* ═══ フッター ════════════════════════════════════════════════ */
footer {
    background: var(--c-primary);
    color: #ffffff;
    text-align: center;
    padding: 2rem 0;
    margin-top: 3rem;
}

.footer-logo-link {
    display: inline-block;
    line-height: 0;
    border-radius: 4px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.footer-logo-link:hover,
.footer-logo-link:focus-visible {
    opacity: 1;
    transform: translateY(-1px);
}

.footer-logo-link:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 3px;
}

.footer-logo {
    max-width: 200px;
    height: auto;
    margin-bottom: 1rem;
    opacity: 0.92;
}

.footer-logo-link:hover .footer-logo,
.footer-logo-link:focus-visible .footer-logo {
    opacity: 1;
}

footer p {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

footer .version-info {
    font-size: 0.78rem;
    opacity: 0.85;
    margin-top: 0.3rem;
}

/* ═══ レスポンシブ(タブレット・スマートフォン) ══════════════ */
@media (max-width: 768px) {
    :root { --font-base: 16px; }

    .header-container {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    .search-box  { flex-direction: column; }
    .container   { padding: 0 12px; }
    .search-section { padding: 1.2rem; margin: 1rem 0; }

    .terms-container {
        background: transparent;
        padding: 0;
        margin: 1rem 0;
        box-shadow: none;
    }

    .term-card { margin-bottom: 0.8rem; }

    .term-header {
        padding: 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.8rem;
        position: relative;
        padding-right: 4rem;
    }

    .term-info { width: 100%; }

    .term-word {
        font-size: 1.25rem;
        line-height: 1.4;
    }
    .term-reading {
        font-size: 0.9rem;
        margin-bottom: 0.4rem;
    }
    .term-short-desc {
        font-size: 0.95rem;
        line-height: 1.7;
        margin-bottom: 0.6rem;
    }
    .term-badges { gap: 0.3rem; }
    .badge { padding: 0.25rem 0.7rem; font-size: 0.8rem; }

    .expand-btn {
        position: absolute;
        right: 1rem;
        top: 1rem;
        width: 2rem;
        height: 2rem;
        font-size: 1rem;
    }

    .term-details-content { padding: 1.2rem; }
    .detail-title { font-size: 1.05rem; margin-bottom: 0.7rem; }
    .detail-description {
        padding: 1rem 1.1rem;
        font-size: 1rem;
        line-height: 1.8;
    }

    .category-btn {
        padding: 0.45rem 0.9rem;
        margin: 0.2rem;
        font-size: 0.88rem;
    }
    .search-input,
    .search-btn { padding: 0.75rem 1.2rem; font-size: 0.95rem; }

    /* ═══ a11yバーのモバイル ─ 折りたたみ式 ═══ */
    .a11y-bar {
        padding: 0.4rem 0;
    }
    .a11y-toggle {
        display: inline-flex;       /* モバイルで表示 */
    }

    /* バー本体は initial で隠す */
    .a11y-inner {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0.8rem 16px 0.4rem;
        margin-top: 0.5rem;
        border-top: 1px solid var(--c-line);
        font-size: 0.85rem;
    }
    /* 開いた状態 */
    .a11y-bar.is-open .a11y-inner {
        display: flex;
    }

    .a11y-label {
        display: none;       /* モバイルでは「表示:」ラベルは省略 */
    }

    .a11y-group {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.35rem;
        padding: 0.35rem 0;
        border-right: none;
        border-bottom: 1px dashed var(--c-line);
        justify-content: flex-start;
    }
    .a11y-group:last-child {
        border-bottom: none;
    }
    .a11y-group::before {
        content: attr(aria-label);
        display: inline-block;
        width: 100%;
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--c-text-muted);
        margin-bottom: 0.25rem;
    }

    .a11y-btn {
        padding: 0.45rem 0.9rem;
        font-size: 0.88rem;
        flex-grow: 1;
        flex-basis: 0;
        text-align: center;
        min-width: 60px;
    }

    /* 折りたたみトグル列 */
    .a11y-bar > .a11y-bar-mobile-row {
        display: flex;
        justify-content: center;
        padding: 0 16px;
    }
}

/* ═══ 画像表示(JSで生成される動的スタイル補助) ══════════════ */
@media (min-width: 769px) {
    .detail-section div[style*="display: flex"] {
        justify-content: flex-start !important;
    }
    .detail-section div[style*="display: flex"] > div {
        flex: 0 0 auto !important;
        width: 300px !important;
        max-width: 300px !important;
    }
}
@media (max-width: 768px) {
    .detail-section div[style*="display: flex"] {
        flex-direction: column !important;
        align-items: center !important;
    }
    .detail-section div[style*="display: flex"] > div {
        width: 100% !important;
        max-width: calc(100vw - 4rem) !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

/* ═══ ダークモード時の特殊調整 ═══════════════════════════════ */
:root[data-theme="dark"] .badge.category,
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .badge.category {
        background: var(--c-primary-soft);
        color: var(--c-accent);
    }
}

:root[data-theme="dark"] .site-header,
:root[data-theme="dark"] footer {
    background: linear-gradient(135deg, #0a3a5c 0%, #062c47 100%);
}

/* 詳細説明内でJSが生成するインライン白背景に対する補正 */
:root[data-theme="dark"] .detail-section div[style*="background: #f8f9fa"],
:root[data-theme="dark"] .detail-section div[style*="background:#f8f9fa"] {
    background: var(--c-card-soft) !important;
    color: var(--c-text) !important;
}

/* ═══ 印刷向け最適化(おまけ) ══════════════════════════════════ */
@media print {
    .a11y-bar, .search-section, .category-filter, .expand-btn { display: none; }
    .term-details { max-height: none !important; }
    body { background: #fff; color: #000; }
    .term-card { break-inside: avoid; }
}

/* ═══ 動きを抑えたい設定への配慮 ══════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001s !important;
        transition-duration: 0.001s !important;
    }
}
