/* ============================================================
   E-計算！ Math — 按分（端数を合計に合わせる）（proportional-allocation.html）だけで使う見た目
   入力の行は css/math.css の .vp-rows / .vp-row をそのまま使う。色はすべて共通のトークン
   ============================================================ */

/* ---- 入力 ---- */
.ap-top { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 12px 14px; }
@media (max-width: 420px) { .ap-top { grid-template-columns: 1fr; } }
.ap-top .field { margin-bottom: 0; min-width: 0; }
.ap-top select { width: 100%; }
#total[aria-invalid="true"], .vp-row input[aria-invalid="true"] { border: 2px solid var(--s2); }
.ap-unitrow { margin-top: 14px; }
.ap-mainrow { margin-top: 14px; }

/* ---- 結果 ---- */
/* 結果の数字の欄の高さを先に確保する（読み込み直後や行を足したときに、下が動かないように） */
#result { min-height: 236px; display: flow-root; }
@media (max-width: 600px) { #result { min-height: 262px; } }
#result .res-mini .v, #result .res-mini .s { overflow-wrap: anywhere; }
#resultPanel [hidden] { display: none !important; }
.ap-h3 { margin: 22px 0 4px; font-size: 15px; }
.ap-h3 small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 4px; }

/* ひとこと：1項目ずつ行を分ける。「ほかの方法」は方法ごとに1行 */
#verdict .ap-vl { display: block; }
.ap-oth { display: block; margin: 2px 0 0 1em; }
.ap-oth > span { display: block; }
.ap-oth b { font-weight: 600; }
/* 表が枠より広いときだけ出す案内（JavaScript で hidden を外す） */
.ap-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

/* 方法ごとの取り分の表 */
table.ap-tbl td, table.ap-tbl th { vertical-align: top; }
/* 見出しは下にそろえ、短い説明は1行に（画面の外の列の折り返しで見出しの行が高くならないように） */
table.ap-tbl thead th { vertical-align: bottom; }
table.ap-tbl th .sub, table.ap-tbl th.n .sub { white-space: nowrap; }
table.ap-tbl td.n b { font-weight: 600; }
table.ap-tbl td.up b { color: var(--accent); font-weight: 700; }
table.ap-tbl td.up b::after { content: "↑"; font-size: 11px; margin-left: 1px; }
table.ap-tbl td.out { box-shadow: inset 0 -3px 0 var(--s2); }
table.ap-tbl th.main, table.ap-tbl td.main { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
table.ap-tbl tr.ap-total td { border-top: 2px solid var(--grid); font-weight: 700; }
table.ap-tbl td.nm { min-width: 4.5em; max-width: 9em; overflow-wrap: anywhere; }
/* 狭い画面：余白を詰めて、名前・正確な取り分・選んだ方法の3列が 320px でも枠に収まるように */
@media (max-width: 420px) {
  html[data-ui="v2"] table.ap-tbl th, html[data-ui="v2"] table.ap-tbl td { padding-left: 6px; padding-right: 6px; }
  table.ap-tbl td.nm { min-width: 3.5em; max-width: 7em; }
}
.ap-dis { display: inline-block; margin-top: 3px; padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 1.6; background: var(--tint-warn); color: var(--tint-warn-ink); white-space: nowrap; }
.ap-key { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--ink-2); }
.ap-key b { color: var(--accent); }
.ap-key .k-out { display: inline-block; width: 18px; height: 10px; box-shadow: inset 0 -3px 0 var(--s2); vertical-align: middle; margin-right: 4px; }
.ap-key .k-dis { margin-right: 4px; }
/* 方法ごとの比べ方：文の列は折り返し、方法の列は潰れないように幅を確保する（狭い画面では表の中で横に動かす） */
table.ap-sum th, table.ap-sum td { text-align: left; }
table.ap-sum th.n, table.ap-sum td.n { text-align: right; white-space: nowrap; }
table.ap-sum td { white-space: normal; min-width: 7.5em; }
table.ap-sum td:first-child { min-width: 8.5em; }
/* 見出しと方法の名前は <wbr> の位置だけで折り返す（「端数を最後の行」「に」のように切れないように） */
table.ap-sum th, table.ap-sum td.ap-mname { white-space: normal; word-break: keep-all; }
/* 狭い画面では、方法ごとの比べ方を方法ごとのカードに（横にスクロールしなくても全部読めるように）。
   見出しは読み上げ用に残して見た目だけ隠し、各欄の見出しは data-label から出す */
@media (max-width: 600px) {
  table.ap-stack, table.ap-stack tbody, table.ap-stack tr, table.ap-stack td { display: block; }
  table.ap-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  table.ap-stack tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--grid); }
  table.ap-stack tbody tr:last-child { border-bottom: 0; }
  table.ap-stack td, table.ap-stack td.n { min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  table.ap-stack td:first-child { grid-column: 1 / -1; font-size: 13.5px; white-space: normal; text-align: left; }
  table.ap-stack td:nth-child(4), table.ap-stack td:nth-child(5) { grid-column: 1 / -1; }
  /* 読み上げでは隠した見出しの行が欄の名前になるので、見た目の見出しは読み上げない（/ "" に未対応のブラウザは1つ目を使う） */
  table.ap-stack td[data-label]::before { content: attr(data-label); content: attr(data-label) / ""; display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
}
/* 合計を増やすと減る？の表（2列、.ap-para）：見出しと方法の名前は <wbr> の位置だけで折り返し（上の keep-all）、
   例の文は長い数字や名前でも折り返す。狭い画面では最小幅と余白を外して、320px でも枠に収める */
table.ap-para td:last-child { overflow-wrap: anywhere; }
@media (max-width: 420px) {
  table.ap-para td, table.ap-para td:first-child { min-width: 0; }
  html[data-ui="v2"] table.ap-para th, html[data-ui="v2"] table.ap-para td { padding-left: 6px; padding-right: 6px; }
}
/* 取り分の表：名前の列は横に動かしても見えるようにする */
table.ap-tbl th:first-child, table.ap-tbl td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; box-shadow: 1px 0 0 var(--grid); }
table.ap-tbl tbody tr:hover td:first-child { background: var(--page); }

/* ---- ずれの図（行ごとに5本のレーン。x は % で置き、印は入れ子の svg で描く） ---- */
.ap-fig { margin: 18px 0 0; padding: 14px 14px 10px; border: 1px solid var(--grid); border-radius: var(--r); background: var(--surface); min-width: 0; }
.ap-fig figcaption { font-size: 14px; font-weight: 700; color: var(--ink); margin: 0 0 8px; line-height: 1.6; }
.ap-fig figcaption small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.ap-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0; margin: 0 0 10px; font-size: 12px; color: var(--ink-2); }
.ap-legend li { display: flex; align-items: center; gap: 5px; }
.ap-legend svg { width: 14px; height: 14px; overflow: visible; }
.ap-frow { margin: 0 0 8px; }
.ap-flab { font-size: 12.5px; font-weight: 700; margin-bottom: 2px; overflow-wrap: anywhere; }
.ap-flab small { font-weight: 400; color: var(--muted); }
.ap-svg { display: block; width: 100%; overflow: visible; }
.ap-band { fill: var(--accent-soft); }
.ap-zero { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.ap-lane { stroke: var(--grid); stroke-width: 1; }
.ap-axis { stroke: var(--line-strong); stroke-width: 1; }
.ap-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.ap-tickline { stroke: var(--line-strong); stroke-width: 1; }
.mk { stroke: var(--surface); stroke-width: 1.2; }
.mk-hamilton { fill: var(--accent); }
.mk-dhondt { fill: var(--s1); }
.mk-sainte { fill: var(--s3); }
.mk-last { fill: var(--s2); }
.mk-largest { fill: var(--ink-2); }
.ap-fig-note { font-size: 11.5px; color: var(--ink-2); line-height: 1.8; padding-top: 8px; margin: 6px 0 0; border-top: 1px solid var(--grid); }

/* ---- 割り算の表 ---- */
table.ap-qt td.n { font-size: 12.5px; }
table.ap-qt td.sel { color: var(--accent); font-weight: 700; background: color-mix(in srgb, var(--accent-soft) 70%, transparent); }
table.ap-qt td.sel sup { font-size: 10px; font-weight: 600; margin-left: 2px; color: var(--accent); }
table.ap-qt td.cut { box-shadow: inset 0 0 0 2px var(--s2); }
.ap-qt-note { margin: 6px 0 0; }

/* 15桁の比率や1,000兆の合計のような長い数字でも、狭い画面で横にはみ出さないように折り返す */
#resultPanel .formula, #resultPanel .verdict, #resultPanel .note, .ap-flab { overflow-wrap: anywhere; }
/* 順番の読み上げ用の隠し文字（.ms-sr は position: absolute）を表の中に閉じ込める（狭い画面で横にはみ出さないように） */
table.ap-qt td { position: relative; }
