/* =========================================================================
   カラートークン（モノトーン基調）
   - 全体はグレースケール。クイズの正誤（緑/赤）だけ視認性のため色を残す。
   - ダークテーマは OS 設定（prefers-color-scheme: dark）に自動追従する。
   ========================================================================= */
:root {
    color-scheme: light dark;

    /* 面・文字・境界 */
    --bg: #eef2f5;
    --surface: #ffffff;
    --surface-2: #f7f9fb;
    --surface-3: #e7edf2;
    --text: #102a43;
    --text-muted: #526777;
    --text-subtle: #718292;
    --text-strong: #102a43;
    --border: #d7e0e7;
    --border-strong: #b8c6d1;
    --border-hover: #7890a2;

    /* ヘッダー / フッター */
    --header-bg: #102a43;
    --header-text: #f5f5f5;
    --footer-bg: #102a43;
    --footer-text: #f5f5f5;

    /* アクセント（モノトーン） */
    --accent: #1d4ed8;
    --accent-hover: #173fae;
    --accent-text: #ffffff;
    --accent-soft: #e8efff;
    --link: #174ea6;
    --focus-ring: #2563eb;

    --code-bg: #ededee;

    /* 注記（黄色をやめてグレーに） */
    --note-bg: #f6f2e9;
    --note-border: #dccba8;
    --note-text: #674c20;

    /* 影 */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.08);

    /* 正誤（両テーマで維持する唯一の有彩色） */
    --correct-bg: #dcfce7;
    --correct-border: #22c55e;
    --correct-text: #15803d;
    --incorrect-bg: #fee2e2;
    --incorrect-border: #ef4444;
    --incorrect-text: #991b1b;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0c1117;
        --surface: #151c24;
        --surface-2: #1a232d;
        --surface-3: #24303c;
        --text: #edf4fa;
        --text-muted: #a9b8c5;
        --text-subtle: #8193a2;
        --text-strong: #edf4fa;
        --border: #2c3946;
        --border-strong: #465767;
        --border-hover: #71879a;

        --header-bg: #091725;
        --header-text: #f0f0f0;
        --footer-bg: #091725;
        --footer-text: #f0f0f0;

        --accent: #7aa2ff;
        --accent-hover: #9bb9ff;
        --accent-text: #07111f;
        --accent-soft: #172a4c;
        --link: #9bbcff;
        --focus-ring: #8db0ff;

        --code-bg: #2d2d2d;

        --note-bg: #2b251b;
        --note-border: #5e4b2d;
        --note-text: #ead3a4;

        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);

        --correct-bg: #14351f;
        --correct-border: #22c55e;
        --correct-text: #86efac;
        --incorrect-bg: #3b1717;
        --incorrect-border: #ef4444;
        --incorrect-text: #fca5a5;
    }
}

/* ========================================================================= */

html, body {
    height: auto;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Yu Gothic", "Hiragino Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
}

.site-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--header-bg);
    color: var(--header-text);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.site-header .site-logo {
    margin: 0;
    font-size: 1.2rem;
}

.site-header a {
    color: var(--header-text);
    text-decoration: none;
}

.menu-toggle {
    border: 0;
    background: rgba(255, 255, 255, 0.15);
    color: var(--header-text);
    border-radius: 999px;
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
    cursor: pointer;
}

.container {
    display: flex;
    align-items: stretch;
    /* 閉じたサイドバーを絶対配置で流し込みから外すためのアンカー。 */
    position: relative;
    /* Clip the off-canvas sidebar horizontally only; the page itself scrolls
       vertically so short pages don't leave trailing white space on PC and the
       footer always sits at the true bottom of the content. */
    overflow-x: hidden;
    flex: 1 0 auto;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.04);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    position: relative;
    /* min-height:100% は高さ連鎖でフッター下に余白を生む原因になっていたため撤去。
       開いたときの高さは container の align-items:stretch が確保する。 */
    margin-right: 0;
    overflow-y: auto;
    box-sizing: border-box;
    z-index: 100;
}

.sidebar:not(.is-open) {
    /* 閉じている間は流し込みから完全に外す。これをしないと、内容が短いページで
       サイドバー（overflow-y:auto のスクロール領域）の高さが container の高さ連鎖に
       影響し、フッター下に余白が残る（項目5の再発）。絶対配置なら container の
       高さは main の内容だけで決まる。 */
    position: absolute;
    top: 0;
    left: 0;
    height: 0;
    width: 0;
    padding: 0;
    border-right: 0;
    box-shadow: none;
    overflow: hidden;
    transform: translateX(-100%);
}

.sidebar.is-open {
    width: 240px;
    padding: 20px;
    transform: translateX(0);
}

.site-note {
    background: var(--note-bg);
    border: 1px solid var(--note-border);
    color: var(--note-text);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.8rem;
    line-height: 1.5;
    margin-bottom: 16px;
}

.sidebar h3 {
    margin-top: 0;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0 0 20px;
}

.sidebar li + li {
    margin-top: 10px;
}

.sidebar a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 1rem;
}

.sidebar a:hover {
    color: var(--text);
    text-decoration: underline;
}

main {
    flex: 1;
    padding: 24px;
    margin-left: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

footer {
    margin-top: auto;
    padding: 16px 24px;
    background: var(--footer-bg);
    color: var(--footer-text);
    text-align: center;
    font-weight: 600;
    flex-shrink: 0;
}

.breadcrumb {
    margin-bottom: 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

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

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

.choices-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
}

/* .choice は <button>（question.js が生成）。ブラウザ既定のボタン体裁を
   打ち消して、従来の行ブロック表示に戻すためのリセットを含む。
   transition を background-color / border-color に限定しているのは、
   `all` だと不要なプロパティまで対象になるため。採点結果の着色は
   .choice.correct / .incorrect 側で transition を切って即座に出す。 */
.choice {
    display: flex;
    align-items: center;
    width: 100%;
    margin: 0;
    border: 1px solid var(--border-strong);
    padding: 15px;
    cursor: pointer;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    text-align: left;
    transition: background-color 120ms ease, border-color 120ms ease;
}

/* 押した瞬間に反応させる（click を待たない）。transform ではなく面の変化に
   しているのは、長い選択肢テキストを動かさず読みやすさを損なわないため。 */
.choice:active {
    background: var(--surface-3);
    border-color: var(--border-hover);
    transition: none;
}

/* 採点済み。disabled にはしない（フォーカス不能になり読み返せなくなる）ので、
   ポインタと反応だけ止める。押しても何も起きない要素が hover/押下に反応すると、
   まだ選べるという誤った手掛かりになる（フィードバックは原因と結びついている
   ことが要件）。フォーカスリングは読み返しの手掛かりなので残す。 */
.choice[aria-disabled="true"] {
    cursor: default;
}

.choice[aria-disabled="true"]:hover,
.choice[aria-disabled="true"]:active {
    background: var(--surface);
    border-color: var(--border-strong);
}

/* 採点結果が付いた肢は、その配色を hover/押下でも保つ。 */
.choice.correct:hover,
.choice.correct:active {
    background: var(--correct-bg);
    border-color: var(--correct-border);
}

.choice.incorrect:hover,
.choice.incorrect:active {
    background: var(--incorrect-bg);
    border-color: var(--incorrect-border);
}

/* Preserve newlines in the source choice text (renders each "品名―物質" pair on
   its own line) while still wrapping long lines. Single-line choices, which have
   no newlines, render identically to before. */
.choice-text,
.choice-explanation-text {
    white-space: pre-line;
}

.choice:hover {
    background: var(--surface-3);
    border-color: var(--border-hover);
}

.choice:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
    background: var(--surface-3);
    border-color: var(--border-hover);
}

/* 採点結果は最重要情報なので、フェードを挟まず即座に確定させる。 */
.choice.correct {
    background: var(--correct-bg);
    border-color: var(--correct-border);
    color: var(--correct-text);
    transition: none;
}

.choice.incorrect {
    background: var(--incorrect-bg);
    border-color: var(--incorrect-border);
    color: var(--incorrect-text);
    transition: none;
}

.mark {
    display: inline-block;
    width: 30px;
    font-weight: bold;
    text-align: center;
    margin-right: 10px;
}

.explanation-box {
    margin-top: 20px;
    padding: 20px;
    border-radius: 8px;
    background: var(--surface-3);
    border-left: 4px solid var(--border-hover);
    color: var(--text);
}

.explanation-box h2 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.explanation-box p {
    margin: 0;
    line-height: 1.6;
}

.explanation-content {
    line-height: 1.6;
}

.explanation-content p {
    margin: 0 0 0.75em;
}

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

.explanation-content h3 {
    margin: 0.75em 0 0.4em;
    font-size: 1rem;
}

.explanation-content ul,
.explanation-content ol {
    margin: 0 0 0.75em;
    padding-left: 1.5em;
}

.explanation-content li {
    margin: 0.2em 0;
}

.explanation-content code {
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: var(--code-bg);
    font-size: 0.95em;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.explanation-content a {
    color: var(--link);
    text-decoration: underline;
    word-break: break-all;
}

/* 解説内のパイプ表（markdown.go の renderTable が出力）。表本体は
   .exp-table-wrap で横スクロールさせ、ページ全体は横に溢れさせない。 */
.exp-table-wrap {
    overflow-x: auto;
    margin: 0 0 0.75em;
}
.exp-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.9rem;
}
.exp-table th,
.exp-table td {
    border: 1px solid var(--border-strong);
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}
.exp-table td {
    white-space: normal;
    min-width: 6em;
}
.exp-table th {
    background: var(--surface-3);
    font-weight: 600;
}
.exp-table tbody tr:nth-child(even) {
    background: var(--surface-2);
}

/* 政令別表第三など、見出しに「第N類」を持つ解説表。類ごとに表自体を
   分割したうえで、トップの試験区分カードと同じ6色順のレールを付ける。
   色が見えなくても見出しと表の分割で境界を判別できる。 */
.exp-table-wrap--hazard-class {
    margin-top: 0.35em;
    margin-bottom: 1.35em;
    border-left: 5px solid var(--exp-table-accent);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.exp-table--hazard-class th {
    border-top-color: var(--exp-table-accent);
    border-bottom: 2px solid var(--exp-table-accent);
    background: var(--surface-2);
    color: var(--exp-table-accent);
    font-weight: 700;
}

.exp-table-wrap--class-1 { --exp-table-accent: var(--accent-cycle-1); }
.exp-table-wrap--class-2 { --exp-table-accent: var(--accent-cycle-2); }
.exp-table-wrap--class-3 { --exp-table-accent: var(--accent-cycle-3); }
.exp-table-wrap--class-4 { --exp-table-accent: var(--accent-cycle-4); }
.exp-table-wrap--class-5 { --exp-table-accent: var(--accent-cycle-5); }
.exp-table-wrap--class-6 { --exp-table-accent: var(--accent-cycle-6); }

/* Chemical structure figures embedded via {{struct:<id>}} in explanations. */
.explanation-content .chem-structure {
    margin: 1em auto;
    padding: 12px;
    max-width: 340px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
}

.explanation-content .chem-structure__svg svg {
    display: block;
    width: 100%;
    max-width: 260px;
    height: auto;
    margin: 0 auto;
}

.explanation-content .chem-structure figcaption {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-subtle);
}

/* Explanation items: {{#<id>}} definition anchors (tag articles) and
   {{quote:<tag>#<id>}} inline quotes with a source link (question pages). */
.explanation-content .exp-item-no {
    display: inline-block;
    margin-right: 0.35em;
    padding: 0 0.15em;
    color: var(--text-subtle);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-decoration: none;
    scroll-margin-top: 80px;
}

.explanation-content .exp-item-no:target {
    color: var(--link);
    background: var(--code-bg);
    border-radius: 4px;
}

/* Quoted tag-item body ({{quote:<tag>#<id>}}): an inline "card" that stands out
   from the surrounding sentence with a tinted background and a left accent. */
.explanation-content .exp-quote {
    display: inline;
    background: var(--surface-3);
    box-shadow: 0.35em 0 0 var(--surface-3), -0.35em 0 0 var(--surface-3);
    border-radius: 4px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

/* Source link appended after a quoted item body. */
.explanation-content .exp-src {
    white-space: nowrap;
    word-break: keep-all;
    margin-left: 0.15em;
    color: var(--text-subtle);
    font-size: 0.85em;
    font-variant-numeric: tabular-nums;
    text-decoration: none;
}

.explanation-content .exp-src:hover {
    text-decoration: underline;
}

/* 用語自動リンク: a tag keyword the generator turned into a link to that tag's
   hub page (autolink.go). Every occurrence is linked, headings included, so the
   styling has to stay quiet at any density: color: inherit plus a dotted
   underline reads as "there is more on this term" without competing with the
   deliberate links in the prose, and inherits heading size/color when it lands
   in an h3. Distinct from .exp-src (quote attribution) and from external links,
   which open a new tab. */
.explanation-content .exp-autolink {
    color: inherit;
    text-decoration: underline dotted var(--link);
    text-underline-offset: 0.2em;
    text-decoration-thickness: 1px;
}

.explanation-content .exp-autolink:hover,
.explanation-content .exp-autolink:focus-visible {
    color: var(--link);
    text-decoration-style: solid;
}

/* Per-choice explanations rendered by question.js after answering, one card per
   displayed choice (in on-screen order), tinted by correctness. */
#choice-explanations {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

.choice-explanation {
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 8px;
    padding: 12px 14px;
    background: var(--surface-2);
}

.choice-explanation-correct {
    border-left-color: var(--correct-border);
    background: var(--correct-bg);
}

.choice-explanation-incorrect {
    border-left-color: var(--incorrect-border);
    background: var(--incorrect-bg);
}

.choice-explanation-head {
    display: flex;
    align-items: baseline;
    gap: 0.5em;
    font-weight: 700;
    margin-bottom: 6px;
}

.choice-explanation-head .mark {
    flex: none;
    font-size: 1.1em;
    line-height: 1;
}

.choice-explanation-correct .choice-explanation-head { color: var(--correct-text); }
.choice-explanation-incorrect .choice-explanation-head { color: var(--incorrect-text); }

/* 自分が選んだ選択肢。解説は全選択肢ぶん同じ体裁で並ぶため、これが無いと
   解説側から自分の選択を辿れない。正誤色は据え置き、境界の強調だけで示す。 */
.choice-explanation-picked {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

.choice-explanation-picked-badge {
    flex: none;
    margin-left: auto;
    padding: 2px 8px;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

.choice-explanation .explanation-content {
    color: var(--text);
}

.choice-explanation .explanation-content p:first-child { margin-top: 0; }
.choice-explanation .explanation-content p:last-child { margin-bottom: 0; }

.hidden,
[hidden] {
    display: none !important;
}

main h1 {
    margin-top: 0;
    font-size: 1.8rem;
    color: var(--text);
}

main ul {
    list-style: none;
    padding: 0;
    margin: 20px 0;
}

main li {
    margin: 10px 0;
}

main a {
    color: var(--link);
    text-decoration: none;
}

main a:hover {
    text-decoration: underline;
}

/* Mobile responsive */
@media (max-width: 768px) {
    body {
        margin: 0;
        padding: 0;
    }

    .container {
        display: flex;
        flex-direction: column;
        flex: 1 0 auto;
    }

    .site-header {
        padding: 14px 16px;
    }

    .site-header .site-logo {
        font-size: 1.05rem;
        flex: 1;
    }

    .menu-toggle {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }

    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-width: 240px;
        border-right: 1px solid var(--border);
        border-bottom: none;
        padding: 60px 16px 16px;
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
        z-index: 100;
    }

    .sidebar:not(.is-open) {
        display: none;
    }

    .sidebar h3 {
        font-size: 1.1rem;
    }

    .sidebar a {
        font-size: 0.95rem;
    }

    main {
        padding: 16px;
        margin: 0;
        flex: 1;
    }

    main h1 {
        font-size: 1.5rem;
        margin: 0 0 16px 0;
    }

    .breadcrumb {
        font-size: 0.85rem;
        margin-bottom: 16px;
    }

    .choices-area {
        gap: 12px;
        margin: 16px 0;
    }

    .choice {
        padding: 16px;
        font-size: 1.05rem;
        line-height: 1.6;
        min-height: 60px;
    }

    .mark {
        margin-right: 12px;
    }

    .explanation-box {
        margin-top: 16px;
        padding: 16px;
    }

    .explanation-box h2 {
        font-size: 1.05rem;
    }

    .explanation-box p {
        font-size: 1rem;
    }

    footer {
        padding: 12px 16px;
        font-size: 0.9rem;
    }
}

/* Custom Added Styles for Antigravity Enhancement */
.welcome-banner {
    background: var(--surface-3);
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.welcome-banner h1 {
    margin-bottom: 8px;
    color: var(--text);
    font-size: 1.8rem;
}

.welcome-banner p {
    margin: 0;
    color: var(--text-muted);
    font-size: 1.05rem;
    line-height: 1.6;
}

.section {
    margin: 24px 0;
}

.section-title {
    font-size: 1.3rem;
    color: var(--text);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    color: var(--text);
}

.accent-card {
    background: var(--surface);
    border-left: 5px solid var(--accent);
}

.action-area {
    margin-top: 16px;
}

/* Buttons */
[hidden] {
    display: none !important;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    border: none;
    outline: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-text) !important;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-3);
    color: var(--text) !important;
    border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
    background: var(--surface-2);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.btn-large {
    padding: 14px 28px;
    font-size: 1.1rem;
}

/* Update History */
.update-history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.history-item {
    display: flex;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.history-item:last-child {
    border-bottom: none;
}

.history-date {
    font-weight: bold;
    color: var(--text-subtle);
    font-family: monospace;
    font-size: 0.95rem;
    min-width: 90px;
}

.history-note {
    color: var(--text-muted);
}

.history-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.history-details summary {
    cursor: pointer;
    color: var(--text-subtle);
    font-size: 0.9rem;
}

.history-details ul {
    margin: 6px 0 0;
    padding-left: 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Question List & Grid */
.questions-container, .categories-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.filter-area {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.filter-area label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.random-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin: 12px 0;
}

.random-options label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.random-options input[type="number"] {
    width: 100px;
}

.select-input {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-strong);
    font-size: 0.95rem;
    background: var(--surface);
    color: var(--text);
}

/* Quiz Launch Panel
   範囲を絞って「ランダムに解く／上から順に解く」を起動する共通パネル。
   分野別問題一覧・共通科目・タグ解説などで共有し、起動導線の見た目を揃える。 */
.quiz-launch {
    border-left: 5px solid var(--accent);
}

.quiz-launch__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 12px;
    margin-bottom: 12px;
}

.quiz-launch__title {
    margin: 0;
    font-size: 1.1rem;
}

.quiz-launch__scope {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.quiz-launch__options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin: 12px 0;
}

.quiz-launch__options label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.quiz-launch__options input[type="number"] {
    width: 100px;
}

.quiz-launch__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.quiz-launch__note {
    margin: 12px 0 0;
    color: var(--text-subtle);
    font-size: 0.85rem;
}

/* 初回ランダム出題でだけ表示する短い使い方案内。問題文より先に読めるが、
   主役になりすぎないよう通常カードより小さく、左の学習レールだけを強調する。 */
.random-intro {
    margin: 0 0 20px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-left: 5px solid var(--accent);
    border-radius: 12px;
    background: var(--surface-2);
    box-shadow: var(--shadow-sm);
}

.random-intro__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.random-intro h2 {
    margin: 0;
    font-size: 1.05rem;
}

.random-intro ul {
    margin: 10px 0 8px;
    padding-left: 1.4em;
}

.random-intro li + li {
    margin-top: 4px;
}

.random-intro__dismiss {
    display: inline-grid;
    flex: none;
    place-items: center;
    width: 44px;
    height: 44px;
    margin: -8px -10px 0 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.random-intro__dismiss:hover {
    background: var(--surface-3);
    color: var(--text);
}

.random-intro__dismiss:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

.question-grid-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.question-item {
    margin: 0 !important;
}

/* --- 問題カード：タグ（分類/試験）を上段、問題名を下段に縦積み ---
   タグ文字数が長くても横並びで潰れないよう、縦方向にスタックする。
       ┌─────────────┐
       │ タグ         │
       │ 問題名       │
       └─────────────┘ */
.question-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 16px 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    transition: all 0.2s ease;
    color: var(--text) !important;
}

.question-card:hover {
    background: var(--surface);
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
    text-decoration: none !important;
}

/* タグ行（分類・試験バッジ等をまとめる帯）。テンプレ側の先頭 div に付与。 */
.question-card__tags {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.question-cat-badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--surface-3);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* 試験体系バッジ（旧インラインstyleの置き換え） */
.badge-exam {
    text-transform: none;
    background: var(--surface-3);
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
}

/* Tag chips (question.html) and tag-type sections (tags.html) */
.tag-chip-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-chip {
    display: inline-block;
    background: var(--surface-3);
    color: var(--text-muted) !important;
    border: 1px solid var(--border-strong);
    text-transform: none;
    text-decoration: none !important;
}

.tag-chip:hover {
    background: var(--surface-2);
    border-color: var(--border-hover);
}

/* 用語解説（タグ解説）セクションのグループ見出し（物質名/法令名/…）。 */
.tag-group-title {
    margin: 20px 0 0;
    font-size: 0.95rem;
    color: var(--text-muted);
}
.tag-group-title:first-of-type {
    margin-top: 8px;
}

/* 物質名の分類ツリー（類 → 品名分類 → 物質）。tag-tree.html が描画する。
   類ごとにカードを縦に積み、品名分類は左ボーダーの入れ子ブロックで示す。 */
.tag-tree {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}
.tag-tree-group {
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 12px 14px;
}
.tag-tree-group__title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-strong);
}
.tag-tree-group__title a,
.tag-tree-sub__title a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--border-hover);
    text-underline-offset: 3px;
}
.tag-tree-group__title a:hover,
.tag-tree-sub__title a:hover {
    color: var(--accent);
}
.tag-tree-sub {
    margin-top: 10px;
    padding-left: 12px;
    border-left: 3px solid var(--border-strong);
}
.tag-tree-sub__title {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}
.tag-tree .tag-chip-list {
    margin-top: 8px;
}

/* 危険物ポータル・法令ページ・甲種トップ専用の高密度表示。
   適用判断は generator の CompactTagExplanations に閉じ、通常のタグ索引や
   他試験・他資格のタグツリーには波及させない。 */
.tag-explanations-section--compact .tag-tree--compact {
    display: block;
    column-count: 2;
    column-gap: 12px;
}

.tag-explanations-section--compact .tag-tree-group--disclosure {
    break-inside: avoid;
    margin: 0 0 12px;
}

.tag-tree-group--disclosure > summary {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 24px;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    list-style: none;
    pointer-events: none;
}

.tag-tree-group--disclosure > summary::-webkit-details-marker {
    display: none;
}

.tag-tree-group__summary-title {
    flex: 1;
}

.tag-tree-group__count {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
}

.tag-tree-group__body {
    margin-top: 8px;
}

.tag-tree-group__root-link {
    margin: 0 0 8px;
    font-size: 0.82rem;
}

.tag-tree-group__root-link a {
    color: var(--text-muted);
    text-decoration: underline;
    text-decoration-color: var(--border-hover);
    text-underline-offset: 3px;
}

.tag-flat-grid--compact {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.tag-flat-grid--compact .tag-tree-group--disclosure {
    margin: 0;
}

.tag-flat-grid--compact .tag-chip-list {
    margin-top: 8px;
}

@media (max-width: 768px) {
    .tag-explanations-section--compact .tag-tree--compact {
        column-count: 1;
    }

    .tag-explanations-section--compact .tag-tree-group--disclosure {
        padding: 0;
    }

    .tag-explanations-section--compact .tag-tree-group--disclosure > summary {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        min-height: 48px;
        padding: 0 14px;
        cursor: pointer;
        pointer-events: auto;
    }

    .tag-explanations-section--compact .tag-tree-group--disclosure > summary::before {
        content: "▸";
        color: var(--text-muted);
        font-size: 0.85rem;
    }

    .tag-explanations-section--compact .tag-tree-group--disclosure[open] > summary::before {
        content: "▾";
    }

    .tag-explanations-section--compact .tag-tree-group__body {
        margin: 0;
        padding: 0 14px 14px;
        border-top: 1px solid var(--border);
    }

    .tag-explanations-section--compact .tag-tree-group__root-link {
        padding-top: 10px;
    }

    .tag-flat-grid--compact {
        grid-template-columns: 1fr;
    }
}
.tag-type-section__note {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.tag-type-section {
    margin-top: 24px;
}

.tag-type-section h2 {
    margin-bottom: 8px;
}

/* 科目領域と横断トピックを、見出し込みで独立した分類として示す。 */
.tag-domain-panel {
    margin-top: 24px;
    padding: 16px 18px 18px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
}

.tag-domain-panel > .tag-group-title,
.tag-domain-panel > h2 {
    margin-top: 0;
}

.tag-domain-panel > .tag-tree,
.tag-domain-panel > .tag-flat-grid--compact,
.tag-domain-panel > .category-grid {
    margin-top: 12px;
}

.tag-domain-panel .tag-tree-group {
    background: var(--surface);
}

@media (max-width: 768px) {
    .tag-domain-panel {
        padding: 14px;
    }
}

/* タグ種別バッジ（旧・法令/化学/火災の色分け → モノトーンの濃淡に統一） */
.badge-law {
    background: var(--surface-3);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.badge-chem {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.badge-fire {
    background: var(--accent);
    color: var(--accent-text);
    border: 1px solid var(--accent);
}

.question-text {
    flex: 1;
    margin: 0;
    font-weight: 500;
    color: var(--text);
}

.related-reason-badge {
    align-self: flex-start;
    background: var(--surface-3);
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
    text-transform: none;
    white-space: nowrap;
}

/* 縦積みカードでは矢印は不要（クリック領域全体がリンク）。ホバーで反応する。 */
.question-arrow, .category-arrow {
    display: none;
}

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.category-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    transition: all 0.2s ease;
    color: var(--text) !important;
}

/* タグの学習進捗バッジは category-card 内の唯一の入れ物（リンク自体）へ
   追加されるため、flex子として本文を圧迫しないよう常に単独の行へ回す。 */
.category-card > .tag-progress--compact {
    flex: 1 1 100%;
    margin-top: 8px;
}

.category-card:hover {
    background: var(--surface);
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    text-decoration: none !important;
}

/* 試験体系カード（ポータル）: タイトル＋説明＋問題数を縦に積む */
.category-card:has(.category-card__title) {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.category-card__title {
    font-weight: 700;
    font-size: 1.05rem;
}

.category-card__desc {
    font-size: 0.82rem;
    color: var(--text-muted, #6b7280);
    line-height: 1.5;
}

.category-card__count {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent, #1e3a8a);
}

/* 試験体系トップの科目セクション見出しの問題数 */
.subject-count {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted, #6b7280);
}

/* 共通科目ページのリード文 */
.subject-lead {
    color: var(--text-muted, #6b7280);
    margin: 4px 0 20px;
}

/* 問題ページ: 難易度バッジ・最終更新日 */
.question-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 0 0 16px;
    font-size: 0.85rem;
}

.difficulty-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-weight: 600;
    border: 1px solid transparent;
}

/* 難易度もモノトーン：薄→濃で基礎→応用を直感的に表現 */
.difficulty-basic {
    background: var(--surface-3);
    color: var(--text-muted);
    border-color: var(--border);
}

.difficulty-standard {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border-strong);
}

.difficulty-advanced {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

.updated-date {
    color: var(--text-subtle);
}

.related-note {
    margin: 0 0 12px;
    padding: 8px 12px;
    background: var(--note-bg);
    border: 1px solid var(--note-border);
    border-radius: 8px;
    color: var(--note-text);
    font-size: 0.85rem;
}

/* 試験体系別トップ / タグ解説記事 */
.exam-hero {
    margin-bottom: 20px;
}

.exam-hero p {
    margin: 0;
    line-height: 1.7;
}

.exam-categories {
    margin-bottom: 24px;
}

.exam-categories h2 {
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.tag-explanation {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    line-height: 1.8;
}

.tag-explanation h3 {
    margin-top: 20px;
    margin-bottom: 8px;
    font-size: 1.15rem;
    color: var(--text);
}

.tag-explanation h3:first-child {
    margin-top: 0;
}

/* --- 解説ありタグの明示（項目10） --- */
.tag-chip-hint {
    font-size: 0.85rem;
    color: var(--text-subtle);
    margin: 4px 0 8px;
    line-height: 1.6;
}

.tag-chip-explained {
    background: var(--surface-2) !important;
    border-color: var(--border-hover);
}

.tag-chip-explained:hover {
    background: var(--surface-3);
    border-color: var(--border-hover);
}

.tag-explained-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 0.7rem;
    font-weight: 700;
    vertical-align: middle;
}

/* =========================================================================
   リザルト振り返り
   - quiz-navigation.js の showFinishScreen が組み立てる「回答の振り返り」一覧。
   - 正誤の配色は #choice-explanations と同じトークン(--correct-*/--incorrect-*)を
     再利用し、クイズ画面と見た目のトーンを揃える。
   ========================================================================= */
/* =========================================================================
   学習終了カード（quiz-navigation.js の showFinishScreen）
   - 以前は結果ボックスに #f3f4f6 / #1e3a8a を直書きしており、ダークテーマで
     明るい箱が1つだけ浮いていた。配色はテーマトークンに従わせる。
   - 見出し(h1)の直後に差し込まれ、問題側は hidden で残る（戻ると復帰する）。
   ========================================================================= */
.quiz-finish {
    margin-top: 20px;
}

.quiz-finish:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

.quiz-finish__score {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5em;
    flex-wrap: wrap;
    margin: 20px 0;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-3);
    text-align: center;
}

.quiz-finish__score-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-strong);
}

.quiz-finish__score-rate {
    font-size: 1rem;
    color: var(--text-muted);
}

.quiz-finish__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 20px;
}

.result-review {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.result-review-heading {
    margin: 0 0 12px;
    font-size: 1.05rem;
    color: var(--text);
}

.result-review-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-review-item {
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 8px;
    padding: 12px 14px;
    background: var(--surface-2);
}

.result-review-item.is-correct {
    border-left-color: var(--correct-border);
    background: var(--correct-bg);
}

.result-review-item.is-incorrect {
    border-left-color: var(--incorrect-border);
    background: var(--incorrect-bg);
}

.result-review-question {
    display: block;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    line-height: 1.6;
}

.result-review-question:hover {
    text-decoration: underline;
}

.result-review-item.is-correct .result-review-question {
    color: var(--correct-text);
}

.result-review-item.is-incorrect .result-review-question {
    color: var(--incorrect-text);
}

.result-review-picked,
.result-review-correct {
    margin: 6px 0 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.result-review-correct {
    color: var(--incorrect-text);
    font-weight: 600;
}

@media (max-width: 768px) {
    .result-review-heading {
        font-size: 1rem;
    }

    .result-review-item {
        padding: 10px 12px;
    }

    .result-review-question,
    .result-review-picked,
    .result-review-correct {
        font-size: 0.9rem;
    }
}
.tag-progress { display:block; margin-top:.3rem; font-size:.8rem; font-weight:600; color:#374151; }
.tag-progress--mastered { color:#166534; }
.tag-progress--review_recommended { color:#9a6700; }
.tag-progress--needs_relearning { color:#b42318; }
.tag-progress--completed { color:#854d0e; }
.tag-progress--in_progress { color:#1d4ed8; }
.tag-progress--no_questions { color:#6b7280; }
.tag-progress--detail { padding:.5rem .75rem; border:1px solid currentColor; border-radius:.4rem; width:fit-content; max-width:100%; }
/* リンクの子ではなく兄弟として常に配置するため、幅に関わらず必ず単独の行になる
   （横方向に間延びしたピルへ引き伸ばされるのを防ぐ）。長文でも折り返す。 */
.tag-progress--compact { display:block; width:fit-content; max-width:100%; margin:.3rem 0 0; padding:.15rem .5rem; border:1px solid currentColor; border-radius:.4rem; font-size:.72rem; line-height:1.4; white-space:normal; overflow-wrap:anywhere; }
.learning-progress-controls { margin:1rem 0 1.5rem; padding:1rem; border:1px solid var(--border); border-radius:.75rem; background:var(--surface); color:var(--text); }
.learning-progress-controls h2 { margin-top:0; }
.progress-storage-notice { color:var(--note-text); font-weight:600; }

@media (prefers-color-scheme: dark) {
    .tag-progress { color:var(--text-muted); }
    .tag-progress--mastered { color:#86efac; }
    .tag-progress--review_recommended,
    .tag-progress--completed { color:#fcd34d; }
    .tag-progress--needs_relearning { color:#fca5a5; }
    .tag-progress--in_progress { color:#93c5fd; }
    .tag-progress--no_questions { color:var(--text-subtle); }
}

/* 試験体系トップの用語解説。大分類・タグ・進捗の視覚階層を統一する。 */
.tag-explanation-hub__intro { display:grid; grid-template-columns:minmax(0,1fr) minmax(230px,.45fr); gap:20px; align-items:start; }
.tag-explanation-hub__intro > p { margin-top:0; }
.tag-overall-progress { padding:12px 14px; background:var(--surface-2); border:1px solid var(--border); border-radius:8px; }
.tag-overall-progress__labels { display:flex; justify-content:space-between; gap:12px; margin-bottom:8px; color:var(--text-muted); font-size:.82rem; }
.tag-overall-progress__labels strong { color:var(--text); }
.tag-overall-progress__track { height:7px; overflow:hidden; background:var(--surface-3); border-radius:999px; }
.tag-overall-progress__track span { display:block; width:0; height:100%; background:var(--correct-border); border-radius:inherit; transition:width 180ms ease; }
.tag-domain-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; margin-top:18px; }
.tag-domain-card { min-width:0; margin:0; padding:0; background:var(--surface-2); border:1px solid var(--border-strong); border-radius:10px; }
.tag-explanations-section--compact .tag-domain-card--disclosure[open] { grid-column:1 / -1; }
.tag-domain-card > h3,
.tag-domain-card > summary { margin:0; padding:14px 16px; color:var(--text); font-size:.98rem; font-weight:700; }
.tag-domain-card > summary { display:flex; align-items:center; gap:10px; min-height:24px; cursor:pointer; list-style:none; }
.tag-domain-card > summary::-webkit-details-marker { display:none; }
.tag-domain-card > summary::before { content:"▸"; color:var(--text-muted); }
.tag-domain-card[open] > summary::before { content:"▾"; }
.tag-domain-card > summary:focus-visible { outline:3px solid var(--focus-ring); outline-offset:2px; }
.tag-domain-card__count { margin-left:auto; color:var(--text-muted); font-size:.8rem; font-weight:500; }
.tag-domain-card__body { padding:0 14px 14px; border-top:1px solid var(--border); }
.tag-domain-card .tag-tree { gap:10px; margin-top:12px; }
.tag-domain-card .tag-tree-group { padding:0; background:transparent; border:0; }
.tag-progress-surface--compact .tag-chip-list { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); align-items:stretch; }
.tag-progress-surface--compact .tag-chip-list > li { display:flex; flex-wrap:wrap; align-items:center; gap:5px 8px; min-width:0; padding:9px 10px; background:var(--surface); border:1px solid var(--border); border-radius:7px; }
.tag-progress-surface--compact .tag-chip-list > li:hover { border-color:var(--border-hover); }
.tag-progress-surface--compact .tag-chip { flex:1 1 100%; min-width:0; padding:0; background:transparent; border:0; color:var(--text) !important; font-weight:600; }
.tag-progress-surface--compact .tag-chip:hover { background:transparent; color:var(--accent) !important; }
.tag-progress-surface--compact .tag-progress--compact { margin:0; }

@media (max-width:768px) {
    .tag-explanation-hub__intro,
    .tag-domain-grid { grid-template-columns:1fr; }
    .tag-progress-surface--compact .tag-chip-list { grid-template-columns:1fr; }
    .tag-domain-card > h3,
    .tag-domain-card > summary { padding:13px 14px; }
}

/* =========================================================================
   2026-07-19 UI / mobile optimization
   資格試験の技術手帳をモチーフに、読みやすい行長、確実なタップ領域、
   横方向に欠けないレイアウトを全ページで共有する。
   ========================================================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: "Yu Gothic UI", "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    font-size: 1rem;
    line-height: 1.65;
}

button,
input,
select,
textarea {
    font: inherit;
}

img,
svg,
video {
    max-width: 100%;
}

.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;
}

.skip-link {
    position: fixed;
    top: 8px;
    left: 50%;
    z-index: 2000;
    padding: 10px 16px;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-md);
    transform: translate(-50%, -160%);
    transition: transform 160ms ease;
}

.skip-link:focus {
    transform: translate(-50%, 0);
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 1200;
    min-height: 64px;
    padding: 10px clamp(14px, 3vw, 28px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 4px 18px rgba(7, 17, 31, 0.2);
}

.site-header .site-logo {
    min-width: 0;
    overflow: hidden;
    font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
    font-size: clamp(1rem, 2.4vw, 1.25rem);
    font-weight: 700;
    letter-spacing: 0.025em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-toggle {
    display: inline-grid;
    flex: 0 0 44px;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    line-height: 1;
    transition: background 160ms ease, transform 160ms ease;
}

.menu-toggle:hover {
    background: rgba(255, 255, 255, 0.19);
}

.menu-toggle:active {
    transform: scale(0.96);
}

.container {
    width: 100%;
    min-width: 0;
}

main {
    width: 100%;
    max-width: 1160px;
    margin-inline: auto;
    padding: clamp(20px, 3.5vw, 40px);
}

main > :first-child {
    margin-top: 0;
}

main h1,
main h2,
main h3 {
    overflow-wrap: anywhere;
}

/* 文字間はサイズごとに変える（1つの固定値はどこかで必ず不適切になる）。
   和文、とくに明朝の見出しは字面が詰まって見えるため**正の字間**を保つ。
   ラテン組版の「大きい文字ほど負の字間」はそのまま当てはまらないので負値には
   しない。関係だけを守る = 大きい見出しほど詰め、小さい文字ほど開ける。 */
main h1 {
    max-width: 32em;
    font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
    font-size: clamp(1.55rem, 3.2vw, 2.2rem);
    line-height: 1.38;
    letter-spacing: 0.01em;
}

main h2 {
    line-height: 1.45;
    letter-spacing: 0.015em;
}

main h3 {
    letter-spacing: 0.02em;
}

.breadcrumb {
    max-width: 100%;
    margin-bottom: clamp(14px, 2.5vw, 24px);
    padding-bottom: 4px;
    overflow-x: auto;
    color: var(--text-subtle);
    scrollbar-width: thin;
    white-space: nowrap;
}

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

.welcome-banner {
    position: relative;
    overflow: hidden;
    padding: clamp(20px, 4vw, 34px);
    border: 1px solid var(--border);
    border-left: 5px solid var(--accent);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.welcome-banner h1 {
    margin-bottom: 8px;
    font-size: clamp(1.65rem, 3.5vw, 2.35rem);
}

.welcome-banner p {
    max-width: 70ch;
    overflow-wrap: anywhere;
}

.section {
    margin: clamp(28px, 5vw, 48px) 0;
}

.section-title {
    gap: 10px;
    margin: 0 0 14px;
    font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
    font-size: clamp(1.2rem, 2.4vw, 1.5rem);
    line-height: 1.4;
}

.section-title::before {
    content: "";
    align-self: stretch;
    width: 4px;
    min-height: 1.4em;
    border-radius: 999px;
    background: var(--accent);
}

.card,
.questions-container,
.categories-container,
.tag-explanation {
    min-width: 0;
    padding: clamp(16px, 3vw, 26px);
    overflow-wrap: anywhere;
    border-color: var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
}

.card > :first-child,
.questions-container > :first-child,
.tag-explanation > :first-child {
    margin-top: 0;
}

.card > :last-child,
.questions-container > :last-child,
.tag-explanation > :last-child {
    margin-bottom: 0;
}

.quiz-launch {
    position: relative;
    overflow: hidden;
    border-left: 5px solid var(--accent);
}

.quiz-launch__head {
    margin-bottom: 16px;
}

.quiz-launch__title {
    font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
    font-size: clamp(1.15rem, 2vw, 1.35rem);
}

.quiz-launch__scope,
.quiz-launch__note,
.subject-lead {
    max-width: 72ch;
    line-height: 1.7;
}

.quiz-launch__options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    align-items: end;
    gap: 14px;
}

.quiz-launch__options label,
.random-options label {
    min-width: 0;
    font-weight: 600;
}

.select-input {
    width: 100%;
    min-height: 44px;
    padding: 9px 12px;
    border-radius: 9px;
    border-color: var(--border-strong);
}

.quiz-launch__options input[type="number"],
.random-options input[type="number"] {
    width: 100%;
}

.quiz-launch__actions {
    gap: 10px;
}

.btn {
    min-height: 46px;
    padding: 10px 20px;
    border-radius: 10px;
    line-height: 1.25;
    text-align: center;
    touch-action: manipulation;
}

.btn-primary {
    border: 1px solid transparent;
    box-shadow: 0 3px 10px rgba(29, 78, 216, 0.2);
}

.btn-primary:hover,
.btn-secondary:hover {
    transform: translateY(-1px);
}

.btn:focus-visible,
.select-input:focus-visible,
.menu-toggle:focus-visible,
.sidebar a:focus-visible,
.question-card:focus-visible,
.category-card:focus-visible,
.tag-chip:focus-visible,
.history-details summary:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 3px;
}

.category-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
    gap: 14px;
}

.category-card,
.question-card {
    min-width: 0;
    min-height: 54px;
    border-radius: 11px;
}

.category-card {
    padding: 18px;
}

.category-card__title,
.question-text,
.category-card__desc {
    overflow-wrap: anywhere;
}

.category-card__count,
.history-date,
.updated-date,
.difficulty-badge,
.question-cat-badge {
    font-variant-numeric: tabular-nums;
}

.question-card {
    padding: 15px 18px;
    border-color: var(--border);
}

/* 小さいラベル類は本文より字間を開ける（main h1/h2/h3 の指定と対の関係）。
   0.75rem 前後まで落ちると字面が潰れて判読が落ちるため。 */
.question-cat-badge,
.difficulty-badge,
.updated-date,
.tag-explained-badge {
    letter-spacing: 0.03em;
}

.question-cat-badge,
.tag-chip {
    line-height: 1.4;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 7px 11px;
}

.choices-area {
    max-width: 100%;
    gap: 12px;
    margin: clamp(18px, 3vw, 28px) 0;
}

.choice {
    min-width: 0;
    min-height: 60px;
    padding: 15px 18px;
    border-radius: 11px;
    overflow-wrap: anywhere;
    touch-action: manipulation;
}

.choice:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.mark {
    flex: 0 0 30px;
}

.explanation-box {
    max-width: 100%;
    padding: clamp(16px, 3vw, 24px);
    overflow-wrap: anywhere;
    border-left-color: var(--accent);
    border-radius: 12px;
}

.explanation-content {
    max-width: 76ch;
}

.exp-table-wrap {
    max-width: 100%;
    overscroll-behavior-inline: contain;
}

.question-tags,
.related-questions {
    margin-top: clamp(30px, 5vw, 48px);
}

.question-tags h2,
.related-questions h2 {
    font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
    font-size: clamp(1.2rem, 2.4vw, 1.5rem);
}

.sidebar-scrim {
    display: none;
}

.sidebar a {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 7px 8px;
    border-radius: 8px;
}

.sidebar a:hover {
    background: var(--surface-3);
    text-decoration: none;
}

.history-item {
    min-width: 0;
}

.history-note,
.history-body {
    overflow-wrap: anywhere;
}

footer {
    padding: 18px 24px;
    font-size: 0.88rem;
    font-weight: 500;
}

@media (min-width: 769px) {
    .sidebar.is-open {
        width: 280px;
        padding: 24px 20px;
    }

    .quiz-launch__actions .btn-primary {
        min-width: 190px;
    }
}

@media (max-width: 768px) {
    body.sidebar-open {
        overflow: hidden;
    }

    .site-header {
        min-height: 60px;
        padding: 8px 14px;
    }

    .site-header .site-logo {
        font-size: 1rem;
    }

    .container {
        display: block;
        overflow-x: clip;
    }

    main {
        max-width: 100%;
        padding: 18px 14px 34px;
    }

    main h1 {
        margin-bottom: 14px;
        font-size: clamp(1.45rem, 7vw, 1.85rem);
    }

    .breadcrumb {
        margin-bottom: 14px;
        font-size: 0.78rem;
    }

    .welcome-banner {
        padding: 20px 18px;
    }

    .welcome-banner h1 {
        font-size: clamp(1.55rem, 7.4vw, 1.9rem);
    }

    .welcome-banner p,
    .subject-lead {
        font-size: 0.94rem;
    }

    .section {
        margin: 30px 0;
    }

    .card,
    .questions-container,
    .categories-container,
    .tag-explanation {
        padding: 16px;
        border-radius: 12px;
    }

    .sidebar,
    .sidebar:not(.is-open) {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1150;
        display: block;
        width: min(86vw, 320px);
        max-width: none;
        height: 100dvh;
        padding: 76px 18px 28px;
        overflow-y: auto;
        visibility: hidden;
        border: 0;
        border-right: 1px solid var(--border);
        box-shadow: 12px 0 30px rgba(7, 17, 31, 0.3);
        transform: translateX(-105%);
        transition: transform 220ms ease, visibility 220ms ease;
    }

    .sidebar.is-open {
        width: min(86vw, 320px);
        height: 100dvh;
        padding: 76px 18px 28px;
        visibility: visible;
        transform: translateX(0);
    }

    .sidebar-scrim {
        position: fixed;
        inset: 0;
        z-index: 1100;
        display: block;
        width: 100%;
        height: 100%;
        padding: 0;
        visibility: hidden;
        border: 0;
        opacity: 0;
        background: rgba(4, 12, 22, 0.58);
        transition: opacity 180ms ease, visibility 180ms ease;
    }

    body.sidebar-open .sidebar-scrim {
        visibility: visible;
        opacity: 1;
    }

    .sidebar a {
        min-height: 44px;
    }

    .filter-area,
    .random-options {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .filter-area > label,
    .filter-area > .select-input,
    .random-options > label {
        width: 100%;
    }

    .filter-area .quiz-launch__actions {
        width: 100%;
        margin-left: 0 !important;
    }

    .quiz-launch__head {
        display: block;
    }

    .quiz-launch__scope {
        margin-top: 5px;
    }

    .quiz-launch__options {
        grid-template-columns: 1fr;
        gap: 11px;
    }

    .quiz-launch__actions {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .quiz-launch__actions .btn,
    .action-area .btn {
        width: 100%;
        min-height: 48px;
    }

    .random-intro {
        margin-bottom: 18px;
        padding: 14px 14px 15px;
    }

    .category-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .category-card,
    .question-card {
        padding: 15px;
    }

    .tag-chip {
        min-height: 44px;
        padding: 8px 12px;
    }

    .choice {
        min-height: 64px;
        padding: 15px 14px;
        font-size: 1rem;
        line-height: 1.7;
    }

    .question-meta {
        gap: 8px;
        margin-bottom: 18px;
    }

    .history-item {
        display: grid;
        gap: 5px;
    }

    .history-date {
        min-width: 0;
    }

    .exp-table {
        font-size: 0.82rem;
    }

    footer {
        padding: 16px 14px;
    }
}

@media (max-width: 380px) {
    main {
        padding-inline: 12px;
    }

    .card,
    .questions-container,
    .categories-container,
    .tag-explanation {
        padding: 14px;
    }

    .question-cat-badge {
        font-size: 0.75rem;
    }
}

/* =========================================================================
   動きの抑制（prefers-reduced-motion）
   - 「動きを消す」のではなく「前庭感覚を刺激しない等価物に置き換える」。
     位置の移動・拡大縮小は止めるが、状態が変わったことの手掛かりになる
     不透明度の変化は残す（全部消すと、サイドバーが一瞬で現れて開閉の
     因果が読めなくなる）。
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }

    /* 移動は止める。押下フィードバックは面の変化で伝わるので影響はない。 */
    .menu-toggle:active,
    .btn-primary:hover,
    .btn-secondary:hover,
    .question-card:hover,
    .category-card:hover {
        transform: none !important;
    }
}

/* サイドバーだけはクロスフェードを残す。ドロワーになるのは 768px 以下だけで、
   デスクトップの常設サイドバーに opacity を当てると消えてしまうため、
   断点の内側に限定する。 */
@media (prefers-reduced-motion: reduce) and (max-width: 768px) {
    .sidebar,
    .sidebar:not(.is-open) {
        transform: none !important;
        opacity: 0;
        transition-property: opacity, visibility !important;
        transition-duration: 180ms !important;
    }

    .sidebar.is-open {
        transform: none !important;
        opacity: 1;
    }

    .sidebar-scrim {
        transition-property: opacity, visibility !important;
        transition-duration: 180ms !important;
    }
}

/* =========================================================================
   高コントラスト（prefers-contrast: more）
   - 面の色は変えず、境界と補助文字だけを強める。半透明素材は使っていないため
     prefers-reduced-transparency の対応は不要。
   ========================================================================= */
@media (prefers-contrast: more) {
    :root {
        --border: var(--border-hover);
        --border-strong: var(--text);
        --text-muted: var(--text);
        --text-subtle: var(--text);
    }

    /* border-width は「左だけ太いアクセント境界」を持つ要素（.accent-card,
       .choice-explanation, .result-review-item）には当てない。一括指定が
       border-left-width を打ち消してアクセントが消えるため。それらは上の
       トークン差し替えによる境界色の強化だけで足りる。 */
    .choice,
    .quiz-finish__score {
        border-width: 2px;
    }

    .choice:focus-visible,
    .btn:focus-visible,
    .select-input:focus-visible,
    .menu-toggle:focus-visible,
    .sidebar a:focus-visible,
    .question-card:focus-visible,
    .category-card:focus-visible,
    .tag-chip:focus-visible {
        outline-width: 3px;
    }

    .explanation-content a,
    .breadcrumb a {
        text-decoration-thickness: 2px;
    }
}

/* =========================================================================
   デザイン改善 2026-07-23 (設計書/デザイン改善提案_2026-07-23.md)
   - デスクトップ用の常設ナビ、フッター拡充、選択肢の記号化、試験区分カードの
     位置ベースアクセント色など、既存レイヤーを上書きしない追加分。
   ========================================================================= */

:root {
    /* カード等の位置に応じて巡回させる、控えめな彩度のアクセント帯。
       特定の試験区分名には結び付けない(何番目のカードか、だけで決まる)ので
       サイト共通で汎用的に使える。 */
    --accent-cycle-1: #1d4ed8;
    --accent-cycle-2: #0f766e;
    --accent-cycle-3: #7c3aed;
    --accent-cycle-4: #b45309;
    --accent-cycle-5: #be123c;
    --accent-cycle-6: #15803d;
    --accent-cycle-7: #4338ca;
    --accent-cycle-8: #0e7490;
}

@media (prefers-color-scheme: dark) {
    :root {
        --accent-cycle-1: #7aa2ff;
        --accent-cycle-2: #2dd4bf;
        --accent-cycle-3: #c4b5fd;
        --accent-cycle-4: #fbbf24;
        --accent-cycle-5: #fb7185;
        --accent-cycle-6: #4ade80;
        --accent-cycle-7: #a5b4fc;
        --accent-cycle-8: #22d3ee;
    }
}

/* ---- デスクトップ用の常設ナビ (H1) ---------------------------------------
   モバイル(768px以下)ではハンバーガー+オフキャンバスのみに委ね、非表示。 */
.primary-nav {
    display: none;
}

@media (min-width: 769px) {
    .menu-toggle {
        display: none;
    }

    /* デスクトップでは常設の .primary-nav が主要導線を担うため、オフキャンバス
       サイドバー(閉じた状態は幅0のまま画面には映らない)を支援技術からも隠す。
       隠さないと「サイトメニュー」ランドマークが .primary-nav と重複して2つ
       聞こえてしまう(視覚的には片方しか使えないのに)。 */
    .sidebar:not(.is-open) {
        visibility: hidden;
    }

    .site-header {
        gap: 20px;
    }

    .primary-nav {
        display: flex;
        align-items: center;
        gap: 4px;
        margin-left: auto;
    }

    .primary-nav__flat {
        display: flex;
        align-items: center;
        gap: 2px;
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .primary-nav a,
    .primary-nav summary {
        display: inline-flex;
        align-items: center;
        min-height: 40px;
        padding: 0 12px;
        border-radius: 8px;
        color: var(--header-text);
        font-size: 0.92rem;
        font-weight: 600;
        text-decoration: none;
        white-space: nowrap;
        cursor: pointer;
    }

    .primary-nav a:hover,
    .primary-nav summary:hover {
        background: rgba(255, 255, 255, 0.12);
    }

    .primary-nav a:focus-visible,
    .primary-nav summary:focus-visible {
        outline: 2px solid var(--focus-ring);
        outline-offset: 2px;
    }

    .primary-nav__dropdown {
        position: relative;
    }

    .primary-nav__dropdown summary {
        list-style: none;
        gap: 6px;
    }

    .primary-nav__dropdown summary::-webkit-details-marker {
        display: none;
    }

    .primary-nav__dropdown summary::after {
        content: "▾";
        font-size: 0.7em;
        opacity: 0.8;
    }

    .primary-nav__dropdown[open] summary::after {
        content: "▴";
    }

    .primary-nav__dropdown ul {
        position: absolute;
        top: calc(100% + 6px);
        right: 0;
        z-index: 1300;
        display: flex;
        flex-direction: column;
        min-width: 180px;
        margin: 0;
        padding: 8px;
        list-style: none;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 10px;
        box-shadow: var(--shadow-md);
    }

    .primary-nav__dropdown li + li {
        margin-top: 2px;
    }

    .primary-nav__dropdown a {
        width: 100%;
        min-height: 38px;
        padding: 0 10px;
        color: var(--text);
        font-weight: 500;
    }

    .primary-nav__dropdown a:hover {
        background: var(--surface-3);
    }
}

/* ---- 選択肢のアルファベット記号化 (M2) ------------------------------------
   紙の参考書・過去問集のような「A. / B. / C. / D.」表記を選択肢の先頭に添える。
   .mark(採点後の○×)とは別領域で、レイアウトはボタンの flex 行に素直に乗せる。 */
.choices-area {
    counter-reset: choice-index;
}

.choice::before {
    counter-increment: choice-index;
    content: counter(choice-index, upper-alpha);
    display: inline-grid;
    flex: none;
    place-items: center;
    width: 26px;
    height: 26px;
    margin-right: 10px;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
}

/* A/B/C/D バッジは採点後も色を変えない(意図的)。正誤は行全体の背景色/境界線と
   隣接する .mark の○×だけで示しており、バッジまで着色すると同じ結果を3箇所
   (行の背景・バッジ・○×)で重複して伝えることになり、かえって読み取りにくい。 */

/* ---- 試験区分カードの位置ベースアクセント (M3) ----------------------------
   特定のIDや名前を判定せず、DOM上の並び順(nth-child)だけで8色を巡回させる。
   taxonomy側の項目数に依存しないので、サイトごとの試験区分数が違っても崩れない。 */
.category-grid > .category-card:nth-child(8n+1) { border-left: 4px solid var(--accent-cycle-1); }
.category-grid > .category-card:nth-child(8n+2) { border-left: 4px solid var(--accent-cycle-2); }
.category-grid > .category-card:nth-child(8n+3) { border-left: 4px solid var(--accent-cycle-3); }
.category-grid > .category-card:nth-child(8n+4) { border-left: 4px solid var(--accent-cycle-4); }
.category-grid > .category-card:nth-child(8n+5) { border-left: 4px solid var(--accent-cycle-5); }
.category-grid > .category-card:nth-child(8n+6) { border-left: 4px solid var(--accent-cycle-6); }
.category-grid > .category-card:nth-child(8n+7) { border-left: 4px solid var(--accent-cycle-7); }
.category-grid > .category-card:nth-child(8n) { border-left: 4px solid var(--accent-cycle-8); }

/* カード説明文が長文だとスキャンしにくいため、視覚的には2行で折り返す
   (全文はDOM上に残るので読み上げ・検索は妨げない)。 */
.category-card__desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ---- トップページの用語解説ツリーの折りたたみ (H5) ------------------------ */
.tag-explanation-details {
    margin-top: 16px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

.tag-explanation-details > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
    list-style: none;
}

.tag-explanation-details > summary::-webkit-details-marker {
    display: none;
}

.tag-explanation-details > summary::before {
    content: "▸";
    color: var(--text-muted);
}

.tag-explanation-details[open] > summary::before {
    content: "▾";
}

.tag-explanation-details__hint {
    color: var(--text-subtle);
    font-size: 0.82rem;
    font-weight: 500;
}

.tag-explanation-details[open] .tag-explanation-details__hint {
    display: none;
}

.tag-explanation-details > summary:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

.tag-explanation-details__body {
    margin-top: 14px;
}

/* ---- プライバシー設定 ------------------------------------------------------ */
.privacy-preference {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 18px;
    margin-top: 20px;
    padding: 16px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface-2);
}

.privacy-preference p {
    flex: 1 1 320px;
    margin: 0;
}

.privacy-preference .btn {
    flex: 0 0 auto;
}

/* ---- フッター拡充 (H4) ----------------------------------------------------- */
.site-footer {
    margin-top: auto;
    padding: 28px 20px;
    background: var(--footer-bg);
    color: var(--footer-text);
    flex-shrink: 0;
}

.site-footer__inner {
    max-width: 1160px;
    margin-inline: auto;
}

.site-footer__nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
    margin: 0 0 14px;
    padding: 0;
    list-style: none;
}

.site-footer__nav a {
    color: var(--footer-text);
    font-weight: 600;
    text-decoration: none;
}

.site-footer__nav a:hover {
    text-decoration: underline;
}

.site-footer__note {
    max-width: 70ch;
    margin: 0 0 12px;
    color: rgba(245, 245, 245, 0.75);
    font-size: 0.82rem;
    line-height: 1.7;
}

.site-footer__copyright {
    margin: 0;
    color: rgba(245, 245, 245, 0.75);
    font-size: 0.82rem;
    font-weight: 600;
}

@media (max-width: 768px) {
    .site-footer {
        padding: 22px 16px;
        text-align: left;
    }
}

/* ---- 見出しの記憶に残る処理 (M1) -------------------------------------------
   .welcome-banner の中の h1 は banner 側の左アクセント境界で十分なので対象外にし、
   それ以外のページ見出し(問題文・分野名・タグ名など)にだけ下線アクセントを足す。 */
main > h1 {
    padding-bottom: 12px;
    border-bottom: 3px solid var(--accent-soft);
}

/* 件数表示は桁が変わってもガタつかないよう等幅数字にする。 */
.category-card__count,
.question-cat-badge,
.difficulty-badge {
    font-variant-numeric: tabular-nums;
}

/* ---- 学習開始・回答・振り返りを一続きにする UX レイヤー ------------------ */
.quiz-launch__modes {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(250px, 0.65fr);
    gap: 14px;
}

.quiz-mode-panel {
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}

.quiz-mode-panel--primary {
    border-left: 4px solid var(--accent);
    background: var(--surface);
}

.quiz-mode-panel__head h2,
.quiz-mode-panel__head h3 {
    margin: 0 0 6px;
    font-size: 1.08rem;
}

.quiz-mode-panel__head p,
.quiz-mode-panel__field {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.65;
}

.quiz-mode-panel__field {
    display: grid;
    gap: 5px;
    margin-top: 14px;
    font-size: 0.9rem;
    font-weight: 600;
}

.quiz-availability {
    min-height: 1.5em;
    margin: 10px 0 0;
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.5;
}

.quiz-availability[data-state="empty"],
.quiz-availability[data-state="error"] {
    color: var(--incorrect-text);
    font-weight: 600;
}

.question-filter-feedback {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: 8px;
}

.question-filter-feedback .quiz-availability {
    margin: 0;
}

.empty-state {
    margin: 16px 0;
    padding: 18px;
    border: 1px dashed var(--border-strong);
    border-radius: 10px;
    background: var(--surface-2);
    text-align: center;
}

.empty-state p {
    margin: 0 0 10px;
}

.btn-text {
    border: 0;
    background: transparent;
    color: var(--text-muted);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.btn-text:hover {
    color: var(--text);
    background: var(--surface-2);
}

.random-intro__summary {
    margin: 8px 0 0;
    color: var(--text-muted);
}

.random-intro__details {
    margin-top: 8px;
}

.random-intro__details > summary,
.choice-explanation-others > summary {
    min-height: 38px;
    color: var(--accent-text);
    font-weight: 700;
    cursor: pointer;
}

.choice-explanation-others {
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

.choice-explanation-others__body {
    display: grid;
    gap: 12px;
    margin-top: 8px;
}

.explanation-subheading {
    margin: 22px 0 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 1rem;
}

.quiz-answer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.learning-summary__card {
    border-left: 5px solid var(--accent);
}

.learning-summary__head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 20px;
}

.learning-summary__eyebrow {
    margin: 0 0 3px;
    color: var(--accent-text);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.learning-summary__head h2,
.learning-summary__note {
    margin: 0;
}

.learning-summary__note {
    color: var(--text-subtle);
    font-size: 0.82rem;
}

.learning-summary__stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1px;
    margin: 18px 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--border);
}

.learning-summary__metric {
    display: grid;
    gap: 2px;
    padding: 14px;
    background: var(--surface-2);
}

.learning-summary__metric strong {
    color: var(--text-strong);
    font-size: 1.45rem;
    font-variant-numeric: tabular-nums;
}

.learning-summary__metric span {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.learning-summary__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 768px) {
    .quiz-launch__modes,
    .learning-summary__stats {
        grid-template-columns: 1fr;
    }

    .quiz-mode-panel {
        padding: 15px;
    }

    .quiz-answer-actions,
    .quiz-finish__actions,
    .learning-summary__actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .quiz-answer-actions .btn,
    .quiz-finish__actions .btn,
    .learning-summary__actions .btn {
        width: 100%;
    }

    .learning-summary__head {
        display: block;
    }

    .learning-summary__note {
        margin-top: 8px;
    }
}
