/*
   見た目の土台。本番を想定した落ち着いた配色にしている。
   色はすべてここの変数から引く。画面ごとに直接色を書くと、あとで揃えられなくなる。
*/
:root {
    --bg: #ffffff;
    --surface: #f6f7fb;
    --surface-2: #eef1f8;
    --fg: #1f2937;
    --fg-strong: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --accent: #2f5bea;
    --accent-strong: #1e40af;
    --accent-soft: #eaf0ff;
    --ok: #15803d;
    --critical: #c02626;
    --major: #c2410c;
    --minor: #0369a1;
    --highlight: #fef08a;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
    --content: 1100px;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
    color: var(--fg);
    background: var(--surface);
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { color: var(--fg-strong); line-height: 1.4; letter-spacing: 0.01em; }
h1 { font-size: 1.75rem; margin: 1.75rem 0 1.25rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 1.05rem; }

a { color: var(--accent); }
a:hover { color: var(--accent-strong); }

:focus-visible { outline: 3px solid rgba(47, 91, 234, 0.35); outline-offset: 2px; }

.boot { padding: 4rem 1rem; text-align: center; color: var(--muted); }

.page { max-width: var(--content); margin: 0 auto; padding: 0 1rem 4rem; min-height: calc(100dvh - 12rem); }

/* --- ヘッダー・ナビ --- */

/*
   固定 (sticky) にはしない。執筆画面の問題文パネルが sticky で top: 1rem に貼り付くので、
   ヘッダーまで貼り付くと重なる。
*/
.site-header { background: var(--bg); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-sm); }

.nav {
    max-width: var(--content);
    margin: 0 auto;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: nowrap;
}

.nav .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 800;
    font-size: 1.1rem;
    text-decoration: none;
    color: var(--fg-strong);
    letter-spacing: 0.02em;
}

.brand-mark {
    width: 1.9rem;
    height: 1.9rem;
    display: block;
}

.nav .links { display: flex; flex: 0 0 auto; gap: 0.25rem; flex-wrap: nowrap; }
.nav .links a {
    color: var(--muted);
    text-decoration: none;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
}
.nav .links a:hover { color: var(--fg-strong); background: var(--surface); }
.nav .links a.active { color: var(--accent); background: var(--accent-soft); }

.nav .auth { margin-left: auto; display: flex; flex: 0 0 auto; align-items: center; gap: 0.75rem; }
.nav .user { color: var(--muted); font-size: 0.9rem; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-checking { display: inline-flex; align-items: center; gap: 0.45rem; min-height: 2.4rem; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.spinner { width: 0.9rem; height: 0.9rem; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .spinner { animation: none; }
}

/*
   画面が中途半端に狭いときに、認証領域だけを次の行へ落とさない。
   上段はロゴと認証、メニューは下段へ明示的に分ける。
   ブラウザの拡大表示時にも同じレイアウトになるよう、通常のスマホ幅より
   少し広い地点で切り替える。
*/
@media (max-width: 1500px) {
    .nav { gap: 0.5rem 0.75rem; flex-wrap: wrap; }
    .nav .links { order: 3; width: 100%; margin: 0 -0.5rem; flex-wrap: wrap; }
}

@media (max-width: 640px) {
    /*
       ブランド名・ログアウトは最上段、ユーザー名はその下に残す。
       表示を消すより、誰でログイン中か分かるほうを優先する。
    */
    .nav {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.35rem 0.75rem;
    }
    .nav .brand { grid-column: 1; grid-row: 1; min-width: 0; font-size: 0.95rem; }
    .brand-mark { width: 1.65rem; height: 1.65rem; flex: 0 0 auto; }
    .nav .auth { display: contents; }
    .nav .user {
        display: block;
        grid-column: 1 / -1;
        grid-row: 2;
        max-width: none;
        font-size: 0.82rem;
    }
    .nav .auth .btn { grid-column: 2; grid-row: 1; padding: 0.42rem 0.8rem; }
    .nav .links {
        grid-column: 1 / -1;
        grid-row: 3;
        width: auto;
        margin: 0 -0.25rem;
    }
}

/* --- 部品 --- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1.1rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    line-height: 1.4;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-plain { background: var(--bg); color: var(--accent); border-color: var(--line-strong); }
.btn-plain:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.btn-danger { background: var(--critical); border-color: var(--critical); }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }

.card {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.muted { color: var(--muted); font-size: 0.9rem; }

/* Google のログインボタンの置き場所。描画まで高さが 0 だと、描かれた瞬間に下の文がずれる。 */
.google-signin { margin: 1rem 0; min-height: 44px; }
.error { color: var(--critical); }

/* --- 午前II 年度別演習 --- */
.am2-hero { padding: 2rem 0 1rem; }
.am2-hero h1 { margin: 0.25rem 0 0.6rem; }
.am2-hero p:last-child { max-width: 42rem; color: var(--muted); }
.am2-years { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; }
.am2-year-card { margin: 0; display: flex; flex-direction: column; align-items: flex-start; }
.am2-year-card h2 { margin: 0; }
.am2-year-card .btn { margin-top: auto; }
.am2-topline { display: flex; gap: 0.75rem; align-items: baseline; flex-wrap: wrap; margin: 1.5rem 0 0.5rem; color: var(--muted); font-size: 0.9rem; }
.am2-topline span:last-child { margin-left: auto; }
.am2-progress { height: 0.45rem; overflow: hidden; border-radius: 999px; background: var(--line); margin-bottom: 1rem; }
.am2-progress span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.15s ease-out; }
.am2-question { max-width: 52rem; margin-left: auto; margin-right: auto; }
.am2-question h1 { margin-top: 0; }
.am2-question-text { white-space: pre-wrap; font-size: 1.05rem; }
.am2-choices { display: grid; gap: 0.75rem; margin: 1.5rem 0; }
.am2-choice { width: 100%; display: grid; grid-template-columns: 2rem 1fr; gap: 0.7rem; align-items: start; text-align: left; padding: 0.8rem 1rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); cursor: pointer; font: inherit; line-height: 1.65; }
.am2-choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.am2-choice > span:first-child { display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--surface-2); color: var(--fg-strong); font-weight: 800; }
.am2-choice:disabled { cursor: default; }
.am2-choice.selected-correct { border-color: var(--ok); background: #f0fdf4; }
.am2-choice.selected-wrong { border-color: var(--critical); background: #fef2f2; }
.am2-choice-key { display: inline-grid; grid-template-columns: 1fr; place-items: center; width: 4.4rem; min-height: 3.25rem; margin-right: 0.5rem; }
.am2-question-image { margin: 1rem 0 1.5rem; }
.am2-question-image a { display: block; }
.am2-question-image img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.am2-question-image figcaption { margin-top: 0.4rem; color: var(--muted); font-size: 0.85rem; }
.am2-result { display: flex; align-items: baseline; gap: 0.75rem; margin: 1rem 0; padding: 0.75rem 1rem; border-radius: var(--radius-sm); }
.am2-result.is-correct { color: #166534; background: #f0fdf4; border: 1px solid #86efac; }
  .am2-result.is-wrong { color: #991b1b; background: #fef2f2; border: 1px solid #fca5a5; }
  .am2-explanation { margin: 1rem 0 1.25rem; padding: 1rem; border-left: 4px solid var(--accent); background: var(--surface-2); }
  .am2-explanation h2 { margin: 0 0 0.45rem; font-size: 1rem; }
  .am2-explanation p { margin: 0; line-height: 1.75; white-space: pre-line; }
  .am2-finish { max-width: 32rem; margin: 3rem auto; text-align: center; }
  .am2-score { font-size: 1.25rem; margin-bottom: 0.35rem; }
  .am2-pass { display: inline-block; margin: 0.25rem 0 0.4rem; padding: 0.35rem 0.9rem; border-radius: 999px; font-size: 1.1rem; }
  .am2-pass.is-passed { color: #166534; background: #dcfce7; }
  .am2-pass.is-not-passed { color: #991b1b; background: #fee2e2; }
  .am2-finish .btn { margin: 0.3rem; }

@media (max-width: 640px) {
    .am2-topline span:last-child { margin-left: 0; }
    .am2-question { padding: 1rem; }
}

p.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.9rem;
}

footer.site-footer { border-top: 1px solid var(--line); background: var(--bg); }
footer.site-footer .inner { max-width: var(--content); margin: 0 auto; padding: 1.25rem 1rem 2rem; }
footer.site-footer p { color: var(--muted); font-size: 0.8rem; margin: 0.25rem 0; }
.footer-links { display: flex; gap: 1rem; flex-wrap: wrap; }

/* 表。狭い画面では表ごと横スクロールさせ、ページ全体を横に揺らさない。 */
.table-wrap {
    overflow-x: auto;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.table-wrap table { width: 100%; border-collapse: collapse; min-width: 36rem; }
.table-wrap th {
    text-align: left;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--surface);
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table-wrap td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-wrap tr:last-child td { border-bottom: none; }
.table-wrap tbody tr:hover { background: #fafbff; }
.table-wrap td.actions { white-space: nowrap; text-align: right; }
.table-wrap td.actions .btn { padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.history-delete-confirm { display: inline-flex; align-items: center; gap: 0.4rem; margin-left: 0.75rem; }

/* 履歴はPCでは表、スマホでは答案ごとのカードにする。操作を省かずに横スクロールをなくす。 */
@media (max-width: 640px) {
    .history-table-wrap { overflow: visible; border: 0; background: transparent; box-shadow: none; }
    .history-table-wrap .history-table { min-width: 0; display: block; }
    .history-table thead { display: none; }
    .history-table tbody { display: block; }
    .history-table tr {
        display: grid;
        grid-template-columns: max-content 1fr;
        gap: 0.45rem 1rem;
        margin-bottom: 0.75rem;
        padding: 1rem;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: var(--bg);
        box-shadow: var(--shadow-sm);
    }
    .history-table td { padding: 0; border: 0; }
    .history-table td.history-title { grid-column: 1 / -1; font-weight: 700; overflow-wrap: anywhere; }
    .history-table td.history-meta {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: max-content 1fr;
        align-items: center;
        gap: 1rem;
    }
    .history-table td.history-meta::before { content: attr(data-label); color: var(--muted); font-size: 0.85rem; }
    .history-table td.history-meta > * { justify-self: start; }
    .history-table td.history-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.5rem; text-align: left; white-space: normal; padding-top: 0.25rem; }
    .history-table td.history-actions .btn { min-height: 2.5rem; }
    .history-table .history-delete-confirm { width: 100%; flex-wrap: wrap; margin-left: 0; padding-top: 0.25rem; }
}

/* 判定のバッジ (履歴など小さい場所用)。 */
.rank-badge {
    display: inline-grid;
    place-items: center;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 50%;
    font-weight: 800;
    font-size: 0.95rem;
    margin-right: 0.35rem;
}
.rank-badge.rank-A { background: var(--ok); color: #fff; }
.rank-badge.rank-B { background: var(--minor); color: #fff; }
.rank-badge.rank-C { background: var(--major); color: #fff; }
.rank-badge.rank-D { background: var(--critical); color: #fff; }

/* --- 執筆画面 --- */

/*
   レイアウトは画面幅で自動的に切り替える。
   **Razor 側は1つの木しか出さない。** 案ごとにマークアップを分岐させると、
   字数表示やテスト答案のような付随物を片方にだけ足してしまい、
   比べたい差以外の差が混ざる。

     900px 未満 … 問題文を畳み、答案を全幅にする。
     900px 以上 … 問題文を左に開いたまま、答案と左右に並べる。

   モバイルで踏みやすい点:
     - 100vh は使わない。iOS Safari がアドレスバーぶん大きい値を返す。100dvh を使う。
     - 下端固定の要素を置かない。ソフトキーボードに押し上げられて答案欄と喧嘩する。
     - textarea のフォントを 16px 未満にしない。iOS がフォーカス時に自動ズームする
       (font: inherit のまま触らないこと)。
*/

.write { position: relative; }


/* --- 参照パネル (問題文 / 別の設問で書いた答案) --- */

/*
   パネルの高さの連鎖。

   height: 100% は親に**確定した高さ**が無いと解決されない。
   左右レイアウトの親は max-height しか持たないため、以前ここが 100% だったときは
   中身がそのまま伸び、枠 768px に対し 2,834px になってページ下部へ突き抜けていた
   (上部だけ見ると正常に見えるので、画面写真では気づけない)。

   フレックスで縮ませれば、親が height でも max-height でも同じように収まる。
   min-height: 0 が無いとフレックス項目は既定で内容より縮まない。
*/
.reference-inner { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }

.reference-head {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--line);
}

.reference-tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; flex: 1; }

.reference-tabs button {
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
}

.reference-tabs button.active { border-color: var(--accent); color: var(--accent); font-weight: 700; }

.reference-close {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0 0.25rem;
    cursor: pointer;
}

.reference-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-top: 0.75rem; }
.reference-body .problem-text,
.reference-body .section-prompt,
.prev-answer { white-space: pre-wrap; }
.reference-body h3 { margin: 1.25rem 0 0; }
.reference-body h3.current { color: var(--accent); }
.prev-answer { line-height: 1.9; }

/*
   既定はオーバーレイ。

   スライドイン (transform + transition) は捨てた。**遷移が完了しないと
   パネルが画面外に留まる**ためで、実際に踏んだ: タブが背面にあると
   requestAnimationFrame が止まり、開いたのに何も出ない状態になる。
   利用者から見ると原因が分からず、直しようもない。

   visibility で切り替えれば、途中の状態が存在しない。
   閉じているパネルは読み上げやタブ移動からも外れる。
*/
.reference {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 0 0 auto;
    width: min(34rem, 100%);
    padding: 1rem;
    background: var(--bg);
    border-left: 1px solid var(--line);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
    z-index: 20;
    visibility: hidden;
}

.reference.open { visibility: visible; }

/* スマホでは横に寄せるより全面に出すほうが読みやすい。 */
@media (max-width: 640px) {
    .reference {
        inset: 0;
        width: 100%;
        border-left: none;
    }
}

/* --- 執筆側 --- */

/*
   執筆側は**ビューポート1枚に収める縦フレックス**。
   帯・答案・採点ボタンが常に同時に見え、スクロールは答案の中だけで起きる。

   帯を position: sticky にする案は捨てた。答案が帯の下へ潜り込み、
   いま書いている行が隠れる (実測: 帯 114px に対し答案の上端が 14px)。
   親の高さを決めてしまえば、そもそも潜り込む余地がない。

   height ではなく min-height なのは、採点中の案内やエラーが出たときに
   下が切れないようにするため。そのときだけページが少し伸びる。
*/
.compose {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 2rem);
}

.compose-bar {
    flex: none;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    padding: 0.5rem 0;
    margin-bottom: 0.75rem;
}

.compose > :not(textarea.answer) { flex: none; }

.compose-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.compose-row .reference-toggle { margin-left: auto; }

/* 設問文は省略しない。左右表示では左の問題文と見比べられ、
   集中表示では押すと問題文パネルを開ける。 */
.prompt-line {
    margin: 0.4rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    cursor: pointer;
}

.compose-actions { margin-top: 1rem; }

/* クラウド保存は自動では行わない。模範解答の操作の横で、保存状態と
   競合時の選択肢をひとまとまりに表示する。 */
.cloud-draft {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
}

.cloud-draft .error,
.cloud-draft .notice {
    width: 100%;
    margin: 0.25rem 0 0;
}

/*
   模範解答の口。答案欄の下に置いている。
   上部の帯に足すとスマホで帯が高くなり、書く場所がそのぶん狭くなる。
*/
.model-draft { margin-top: 1rem; }
.model-draft-controls { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 0.5rem; }
.model-draft-content { margin-top: 1rem; }
.draft-setup { margin-top: 0; }
.draft-setup label { display: block; font-size: 0.9rem; margin-bottom: 0.25rem; }

textarea.draft-context {
    width: 100%;
    min-height: 7rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 4px;
    /* 答案欄と同じ理由で 16px を下回らせない (iOS の自動ズーム)。 */
    font: inherit;
    line-height: 1.6;
    resize: vertical;
}

.draft-context-help { display: flex; gap: 0.75rem; flex-wrap: wrap; margin: 0.25rem 0 0; }

.draft-tools { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }

/* 警告ではないが、読み飛ばされると困るもの。 */
.notice {
    border-left: 3px solid var(--major);
    background: #fff7ed;
    padding: 0.5rem 0.75rem;
    margin: 0.75rem 0 0;
    font-size: 0.9rem;
}

.section-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.section-tabs button { padding: 0.3rem 0.8rem; border: 1px solid var(--line); background: #fff; cursor: pointer; font: inherit; }
.section-tabs button.active { border-color: var(--accent); color: var(--accent); font-weight: 700; }

textarea.answer {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 4px;
    /* font: inherit のまま。16px を下回ると iOS がフォーカス時に自動ズームする。 */
    font: inherit;
    line-height: 1.9;
    /* 親が高さを決めるので、残りを埋める。つまんで伸ばす操作は不要になる。 */
    flex: 1 1 auto;
    min-height: 12rem;
    resize: none;
}

@media (max-width: 640px) {
    /*
       答案欄は執筆画面の主役なので、通常は画面高の約45%を使う。
       clamp にすると、小さい端末でも最低限の高さを保ちつつ、縦に長い端末で
       不必要に大きくなりすぎない。ソフトキーボード表示時は 100dvh が縮むため、
       答案欄も可視領域に合わせて縮む。
    */
    textarea.answer { min-height: clamp(14rem, 45dvh, 22rem); }

    /*
       答案欄に届くまでのスクロールを削る。実測 (375x812) では
       答案欄の上に 582px あり、その内訳の最大が見出し 163px だった。
       2rem の見出しは 375px の画面で1/5を占める。
    */
    .write-title { font-size: 1.35rem; line-height: 1.4; }

}

/*
   オーバーレイの外側。閉じる口を「×」だけにすると、
   開閉ボタン自体がパネルの下に隠れて押せなくなる (実測で踏んだ)。
*/
.reference-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 15;
    border: none;
    padding: 0;
    cursor: pointer;
}

/* --- 広い画面では問題文を横に開いたままにする --- */

@media (min-width: 900px) {
    .write {
        display: grid;
        grid-template-columns: minmax(18rem, 32%) 1fr;
        gap: 1.5rem;
        align-items: start;
    }

    .write .reference {
        position: sticky;
        top: 1rem;
        inset: auto;
        width: auto;
        visibility: visible;
        transform: none;
        box-shadow: none;
        border: 1px solid var(--line);
        border-radius: 6px;
        z-index: 1;
        max-height: calc(100dvh - 2rem);
    }

    /* 常に見えているので、開閉の口も背景も要らない。 */
    .write .reference-close,
    .write .reference-backdrop,
    .write .reference-toggle { display: none; }
}

/*
   左右に並べると1列が 550px 程度まで細くなり、1行の文字数が足りない。
   収まる幅があるときだけ、中央 1100px の外へはみ出させる。
*/
@media (min-width: 1460px) {
    .write { width: 1380px; margin-left: -140px; }
}

.count { font-variant-numeric: tabular-nums; }
.count.short { color: var(--critical); font-weight: 700; }
.count.over { color: var(--major); font-weight: 700; }
.count.ok { color: #15803d; }

.sample-loader {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
    padding: 0.5rem;
    border: 1px dashed var(--line);
    border-radius: 4px;
}

.sample-loader .btn { padding: 0.2rem 0.6rem; font-size: 0.85rem; }

/* --- 結果 --- */

.rank { font-size: 2.5rem; font-weight: 700; line-height: 1; }
.rank-A { color: #15803d; }
.rank-B { color: #0369a1; }
.rank-C { color: var(--major); }
.rank-D { color: var(--critical); }

.criteria { list-style: none; padding: 0; }
.criteria li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.criteria li:last-child { border-bottom: 0; }
.criteria-comment { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 0.9rem; }
.criteria-legend { margin: 1rem 0; }
.criteria-legend summary { cursor: pointer; color: var(--accent); font-weight: 700; }
.criteria-legend dl { margin: 0.75rem 0; }
.criteria-legend dl > div { display: grid; grid-template-columns: 9rem 1fr; gap: 0.5rem; margin-top: 0.5rem; }
.criteria-legend dt, .criteria-legend dd { margin: 0; }
.criteria-level { align-self: start; border-radius: 999px; padding: 0.15rem 0.55rem; font-size: 0.85rem; font-weight: 700; white-space: nowrap; }
.criteria-level-priority { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical); }
.criteria-level-improve { background: color-mix(in srgb, var(--major) 16%, transparent); color: var(--major); }
.criteria-level-good { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.bar { background: var(--line); height: 0.6rem; border-radius: 3px; align-self: center; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.coverage-section + .coverage-section { border-top: 1px solid var(--line); margin-top: 1rem; padding-top: 1rem; }
.coverage-section h3 { margin-bottom: 0.5rem; }
.coverage-list { list-style: none; padding: 0 !important; }
.coverage-list li { border-left: 4px solid var(--line); padding: 0.5rem 0 0.5rem 0.75rem; }
.coverage-list li + li { margin-top: 0.5rem; }
.coverage-list p { margin: 0.3rem 0 0; }
.coverage-list blockquote { margin: 0.4rem 0 0; }
.coverage-fulfilled { border-color: var(--accent) !important; }
.coverage-partial { border-color: var(--major) !important; }
.coverage-missing { border-color: var(--critical) !important; }
.coverage-status { display: inline-block; margin-left: 0.5rem; font-size: 0.85rem; font-weight: 700; }
.coverage-fulfilled .coverage-status { color: var(--accent); }
.coverage-partial .coverage-status { color: var(--major); }
.coverage-missing .coverage-status { color: var(--critical); }
.improvement-link { display: inline-block; margin-top: 0.25rem; padding: 0; border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 0.9rem; text-decoration: underline; }

.finding { border-left: 4px solid var(--line); padding-left: 0.75rem; margin-bottom: 1rem; }
.finding.Critical { border-color: var(--critical); }
.finding.Major { border-color: var(--major); }
.finding.Minor { border-color: var(--minor); }
.finding .sev { font-weight: 700; font-size: 0.85rem; }
.finding.Critical .sev { color: var(--critical); }
.finding.Major .sev { color: var(--major); }
.finding.Minor .sev { color: var(--minor); }

.body-view { white-space: pre-wrap; border: 1px solid var(--line); padding: 1rem; border-radius: 4px; }
.body-view mark { background: var(--highlight); }

table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--line); padding: 0.4rem 0.6rem; text-align: left; }
th { background: #f9fafb; }

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.6rem 1.25rem;
    background: #fde047;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; float: right; }

/* ---- 問題一覧: 出題年ごと ---- */
.year-index { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.5rem; }
.year-index a { padding: 0.25rem 0.7rem; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: 0.9rem; }
.year-group { margin-bottom: 2rem; scroll-margin-top: 1rem; }
.year-heading { border-bottom: 2px solid var(--line); padding-bottom: 0.3rem; }
.year-group .card h3 { margin: 0.25rem 0 0.5rem; }

/* ---- 執筆: 本日の残り回数 ---- */
.quota-left { font-size: 0.85rem; color: var(--muted); white-space: nowrap; margin-left: 0.5rem; }
.quota-left.empty { color: var(--critical); font-weight: 700; }

/* ---- トップ (ランディング) ---- */
.hero { padding: 2rem 0 1.5rem; }
.hero-kicker { color: var(--accent); font-weight: 700; margin: 0 0 0.5rem; }
.hero-title { font-size: clamp(1.6rem, 5vw, 2.4rem); line-height: 1.35; margin: 0 0 1rem; }
.hero-lead { max-width: 42rem; line-height: 1.8; }
.hero-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1.5rem; }
.btn-large { padding: 0.7rem 1.4rem; font-size: 1.05rem; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; margin: 1rem 0 1.5rem; }
.feature { border: 1px solid var(--line); border-radius: 6px; padding: 1rem; }
.feature h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
.feature p { margin: 0; line-height: 1.7; }

/* =====================================================================
   見た目の仕上げ (本番想定)。上の各画面の規則を、色と余白だけ上書きする。
   レイアウト（高さの連鎖・左右の格子）には触れない。
   ===================================================================== */

/* 執筆 */
.write-title { margin-bottom: 0.25rem; }
.compose-bar { background: var(--surface); }
.section-tabs button {
    border-radius: 999px;
    padding: 0.3rem 0.9rem;
    background: var(--bg);
    border-color: var(--line-strong);
    font-weight: 600;
    color: var(--muted);
}
.section-tabs button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.section-tabs button .count { margin-left: 0.25rem; font-size: 0.8rem; opacity: 0.8; }

textarea.answer, textarea.draft-context {
    background: var(--bg);
    border-color: var(--line-strong);
    border-radius: var(--radius-sm);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: border-color 0.15s, box-shadow 0.15s;
}
textarea.answer:focus, textarea.draft-context:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 91, 234, 0.15);
}

.model-draft-content, .compose-actions {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
}
.compose-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.compose-actions .btn { padding: 0.65rem 1.5rem; font-size: 1.02rem; }
.notice { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.quota-left {
    background: var(--surface-2);
    border-radius: 999px;
    padding: 0.15rem 0.65rem;
    font-weight: 600;
}
.quota-left.empty { background: #fef2f2; }
.quota-summary {
    display: grid;
    gap: 0.1rem;
    padding: 0.35rem 0.65rem;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}
.quota-summary span { color: var(--muted); }
.quota-summary.empty { background: #fef2f2; }

.reference { background: var(--bg); }
.reference-tabs button { border-radius: 999px; }
.reference-tabs button.active { background: var(--accent-soft); }
@media (min-width: 900px) {
    .write .reference { border-radius: var(--radius); box-shadow: var(--shadow-sm); }
}

/* 問題一覧 */
.year-index a { background: var(--bg); color: var(--fg); font-weight: 600; }
.year-index a:hover { border-color: var(--accent); color: var(--accent); }
.year-heading { display: flex; align-items: baseline; gap: 0.6rem; border-bottom-color: var(--line-strong); }
.year-group .card { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1.5rem; align-items: center; transition: box-shadow 0.15s, border-color 0.15s; }
.year-group .card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.year-group .card > * { grid-column: 1; margin: 0; }
.year-group .card > .btn { grid-column: 2; grid-row: 1 / span 3; }
@media (max-width: 640px) {
    .year-group .card { grid-template-columns: 1fr; }
    .year-group .card > .btn { grid-column: 1; grid-row: auto; margin-top: 0.5rem; justify-self: start; }
}

/* 結果 */
.score-head { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.score-head .rank {
    display: inline-grid;
    place-items: center;
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 50%;
    background: var(--surface);
    border: 3px solid currentColor;
    font-size: 2.2rem;
}
.score-head .score { font-size: 2rem; font-weight: 800; color: var(--fg-strong); line-height: 1; }
.score-head .score small { font-size: 1rem; font-weight: 600; color: var(--muted); margin-left: 0.15rem; }
.bar { background: var(--surface-2); height: 0.55rem; border-radius: 999px; }
.bar > span { background: linear-gradient(90deg, var(--accent), #6d4aff); border-radius: 999px; }
.finding { background: var(--bg); border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius-sm); padding: 0.75rem 1rem; }
.body-view { background: var(--bg); border-radius: var(--radius); line-height: 1.9; margin-top: 0.75rem; }
.markdown-view {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}
/* AI の書き換え例は Markdown のコードブロックになることがある。
   pre の既定 white-space: pre は横へはみ出すため、改行を保ったまま折り返す。 */
.markdown-view pre {
    max-width: 100%;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.result-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 2rem; }
@media (max-width: 640px) {
    .criteria-legend dl > div { grid-template-columns: 1fr; gap: 0.25rem; }
}

/* トップ (ランディング) */
.hero {
    margin: 1.5rem 0;
    padding: clamp(1.75rem, 5vw, 3.5rem);
    border-radius: 16px;
    color: #fff;
    background:
        radial-gradient(circle at 85% 15%, rgba(255, 255, 255, 0.18), transparent 40%),
        linear-gradient(135deg, #1e3a8a 0%, #2f5bea 55%, #6d4aff 100%);
    box-shadow: var(--shadow);
}
.hero .hero-kicker {
    display: inline-block;
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 999px;
    padding: 0.15rem 0.8rem;
    font-size: 0.85rem;
}
.hero-title { color: #fff; margin-top: 0.75rem; }
.hero-lead { color: rgba(255, 255, 255, 0.9); }
.hero .muted { color: rgba(255, 255, 255, 0.85); }
.hero .btn { background: #fff; color: var(--accent-strong); border-color: #fff; }
.hero .btn:hover { background: var(--accent-soft); }
.hero .hero-secondary { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.65); }
.hero .hero-secondary:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }
.pricing-hero { text-align: center; padding: 1.5rem 0 0.5rem; }
.pricing-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; max-width: 52rem; margin: 1.5rem auto; }
.pricing-card { position: relative; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow-sm); }
.pricing-card-featured { border: 2px solid var(--accent); box-shadow: var(--shadow); }
.pricing-card h2 { margin-top: 0; }
.pricing-card ul { padding-left: 1.2rem; min-height: 8rem; }
.pricing-card li + li { margin-top: 0.4rem; }
.price { color: var(--fg-strong); font-size: 2rem; font-weight: 800; margin: 0.25rem 0; }
.price span { color: var(--muted); font-size: 0.9rem; font-weight: 500; }
.plan-badge { position: absolute; top: -0.8rem; right: 1rem; margin: 0; padding: 0.1rem 0.7rem; border-radius: 999px; background: var(--accent); color: #fff; font-size: 0.8rem; font-weight: 700; }
.pricing-notes { max-width: 52rem; margin-left: auto; margin-right: auto; }
.guide-hero { margin: 1.5rem 0; padding: clamp(1.5rem, 4vw, 2.5rem); border-radius: var(--radius); background: var(--accent-soft); }
.guide-hero h1 { margin-top: 0.5rem; }
.guide-hero p:last-child { margin-bottom: 0; max-width: 44rem; }
.guide-official-links { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-top: 1.25rem; font-size: .9rem; }
.guide-official-links span { color: var(--muted); font-weight: 700; }
.guide-official-links a { color: var(--accent-strong); font-weight: 700; }
.guide-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.guide-card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.guide-card h2 { margin: 0.25rem 0 0.5rem; font-size: 1.1rem; }
.guide-card p { color: var(--muted); font-size: 0.9rem; }
.guide-number { color: var(--accent) !important; font-weight: 800; letter-spacing: .08em; }
.guide-article { max-width: 48rem; margin: 1.5rem auto; }
.guide-article section { margin: 2rem 0; }
.guide-article h2 { border-bottom: 2px solid var(--accent-soft); padding-bottom: .35rem; }
.guide-article li + li { margin-top: .4rem; }
.guide-lead { font-size: 1.08rem; color: var(--muted); }
.static-guide-page .guide-article > h2 { margin-top: 2rem; }
.static-guide-page .guide-article > h2 { border-bottom: 2px solid var(--accent-soft); padding-bottom: .35rem; }
.static-guide-page .guide-article > li + li { margin-top: .4rem; }
.breadcrumb { color: var(--muted); font-size: .85rem; }
.breadcrumb span { margin: 0 .4rem; }
.guide-flow { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }
.guide-flow span { background: var(--accent-soft); color: var(--accent-strong); border-radius: 999px; padding: .25rem .7rem; font-size: .9rem; font-weight: 700; }
.guide-flow span:not(:last-child)::after { content: "→"; margin-left: 1rem; color: var(--muted); }
.guide-cta { margin: 2.5rem 0; background: var(--surface-2); border-radius: var(--radius); padding: 1.25rem; }
.guide-cta h2 { margin-top: 0; border: none; }
.static-guide-footer { max-width: var(--content); margin: 0 auto; padding: 1.5rem 1rem 2.5rem; color: var(--muted); font-size: .9rem; border-top: 1px solid var(--line); }
.static-guide-footer a { color: inherit; }
.checklist { padding-left: 2rem; }
.checklist li::marker { color: var(--accent); font-weight: 800; }
@media (max-width: 760px) { .guide-grid { grid-template-columns: 1fr; } .guide-flow span:not(:last-child)::after { display: none; } }
.legal-list { display: grid; grid-template-columns: 11rem 1fr; border-top: 1px solid var(--line); }
.legal-list dt, .legal-list dd { margin: 0; padding: 0.75rem; border-bottom: 1px solid var(--line); }
.legal-list dt { font-weight: 700; background: var(--surface); }
.legal-copy h2 { margin-top: 1.5rem; }
.legal-copy h2:first-child { margin-top: 0; }
@media (max-width: 640px) { .legal-list { grid-template-columns: 1fr; } .legal-list dt { padding-bottom: 0.25rem; border-bottom: none; } .legal-list dd { padding-top: 0.25rem; } }
@media (max-width: 640px) { .pricing-grid { grid-template-columns: 1fr; } .pricing-card ul { min-height: 0; } }
.feature { background: var(--bg); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.feature-num {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 800;
    margin-bottom: 0.5rem;
}
.card ul { padding-left: 1.2rem; margin: 0; }
.card li + li { margin-top: 0.35rem; }
