/* 確率計算ツールの見た目。外部の部品やフォントは読み込まない。 */

:root {
  --text: #222;
  --sub: #5a5f66;
  --line: #d5d9de;
  --panel: #fff;
  --back: #f5f6f8;
  --soft: #f9fafb;
  --accent: #1d5f8a;
  --accent-soft: #e6f0f7;
  --error: #b3261e;
  --error-soft: #fdecea;
}

* { box-sizing: border-box; }

/* hidden を付けた要素は、ほかの display の指定より優先して隠す */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--back);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.7;
}

.tool {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

h1 {
  font-size: 1.4rem;
  line-height: 1.4;
  margin: 0 0 8px;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 12px;
  padding-left: 10px;
  border-left: 4px solid var(--accent);
  line-height: 1.4;
}

h3 { font-size: 1rem; margin: 0; line-height: 1.4; }

.lead { margin: 0 0 16px; color: var(--sub); }

/* 使い方 */
.usage {
  margin: 0 0 16px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.usage summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.usage ol { margin: 10px 0 4px; padding-left: 1.4em; }
.usage li { margin: 4px 0; }
.usage ul { margin: 4px 0 0; padding-left: 1.2em; }

/* 計算の前提 */
.premises ul { margin: 0; padding-left: 1.2em; font-size: 0.9rem; }
.premises li { margin: 4px 0; }

.site-footer {
  margin-top: 8px;
  text-align: center;
  font-size: 0.875rem;
}
.site-footer a { color: var(--accent); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label { display: block; font-weight: 600; margin-bottom: 4px; }

.line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.hint { margin: 6px 0 0; color: var(--sub); font-size: 0.875rem; }
.panel > .hint:first-of-type { margin: 0 0 12px; }

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

input[type="number"], input[type="text"], select {
  height: 44px;
  padding: 0 10px;
  border: 1px solid #a9b0b8;
  border-radius: 6px;
  background: #fff;
}

input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid #8fc0e0;
  outline-offset: 1px;
}

.num { width: 5.5em; text-align: right; }

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.4; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* カードの表 */
.card-head, .card-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 5.5em 1.2em 3.6em;
  gap: 8px;
  align-items: center;
}
.card-head { font-size: 0.875rem; color: var(--sub); margin-bottom: 4px; }
.card-row { margin-bottom: 8px; }
.card-row input[type="text"] { width: 100%; }
.card-row .num { width: 100%; }

.remove {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--sub);
  font-size: 0.875rem;
}
.remove:not(:disabled):hover { border-color: var(--error); color: var(--error); }

.add {
  min-height: 44px;
  padding: 0 16px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}

.others { margin: 12px 0 0; color: var(--sub); font-size: 0.9rem; }

/* B案と比べる：カードの行に「A案」「B案」の枚数を並べる（狭い画面では、カード名の下に回る） */
.card-row.with-b {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.card-row.with-b input[type="text"] { flex: 1 1 180px; min-width: 0; }
.plan-count { display: inline-flex; align-items: center; gap: 6px; }
.plan-count .num { width: 4.6em; }
.plan-tag { font-size: 0.8rem; font-weight: 600; color: var(--sub); }
.plan-b { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.plan-b > .hint { margin: 4px 0 0; }
#plan-b-box { margin-top: 10px; }
.plan-b-deck { margin-bottom: 10px; }
.plan-b-deck label { font-weight: 600; }
.plan-compare { margin-top: 14px; }
.plan-compare h3 { margin: 0 0 4px; font-size: 0.95rem; }
.plan-table tr.diff th, .plan-table tr.diff td { font-weight: 700; color: var(--accent); }
@media (max-width: 480px) {
  /* 狭い画面では、カード名を1行目、「A案」「B案」の枚数を2行目にそろえる */
  .card-row.with-b input[type="text"] { flex-basis: 100%; }
  .plan-count .num { width: 4em; }
}

/* 条件：パターンと、＆でつなぐ条件 */
.pattern {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 12px;
  margin-bottom: 12px;
}
.pattern-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.cell {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}
.cell-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.cell-title { font-size: 0.875rem; font-weight: 600; color: var(--sub); }

.card-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.card-chips .hint { margin: 0; }
.card-chip {
  min-height: 40px;
  max-width: 100%;
  padding: 0 12px;
  border: 1px solid #a9b0b8;
  border-radius: 20px;
  background: #fff;
  color: var(--text);
  overflow-wrap: anywhere;
}
.card-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.card-chip[aria-pressed="true"]::before { content: "✓ "; }

.and {
  margin: 6px 0;
  text-align: center;
  font-weight: 700;
  color: var(--accent);
}

.add-cell { margin-top: 10px; }

.pattern-note {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--error-soft);
  color: var(--error);
  font-size: 0.9rem;
}
.pattern-note:empty { display: none; }

.pattern-result {
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.pattern-result:empty { display: none; }

#add-pattern { margin-top: 2px; }

/* 前提 */
.check-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}
.check-line input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
#premise-box { margin-top: 12px; }
#premise-box .hint { margin: 10px 0 0; }

/* 引く・持ってくる */
#effects-box { margin-top: 12px; }
.effect {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 12px;
  margin-bottom: 12px;
}
.effect .pattern-head { margin-bottom: 6px; }
.effect-line { margin-top: 8px; }
.effect-line select { max-width: 100%; }
.effect-label { margin: 10px 0 6px; font-size: 0.875rem; font-weight: 600; color: var(--sub); }
.effect .card-chips { margin-bottom: 0; }
.howto ul { margin: 8px 0 0; padding-left: 1.2em; }
.howto li { margin: 4px 0; }

/* 相手のデッキとの対面 */
#matchup-box { margin-top: 12px; }
.matchup .sub-title { margin: 20px 0 6px; font-size: 0.95rem; padding-top: 12px; border-top: 1px solid var(--line); }
.matchup .sub-title:first-child { margin-top: 4px; padding-top: 0; border-top: none; }
.matchup .sub-title + .hint { margin: 0 0 10px; }
.matchup-sizes { margin-bottom: 4px; }
.matchup-sizes label { font-weight: 600; }
.matchup-result { margin-top: 18px; padding-top: 14px; border-top: 2px solid var(--accent); }
.matchup-result h3 { margin: 14px 0 0; font-size: 0.95rem; }
.matchup-result h3:first-child { margin-top: 0; }
.matchup-table tr.total th, .matchup-table tr.total td { font-weight: 700; color: var(--accent); }

/* 条件の入れ方の切り替え */
.mode-switch { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.mode-btn {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 22px;
  background: #fff;
  color: var(--accent);
}
.mode-btn[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* 組み合わせ表 */
.combo-title { margin: 16px 0 8px; font-size: 0.95rem; }
.combo-title:first-of-type { margin-top: 4px; }
#mode-combo > .hint:first-child { margin: 0 0 4px; }
.combo-hint-wide, .combo-hint-narrow { margin: 0 0 10px; }

.combo-matrix { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.combo-table { border-collapse: collapse; font-size: 0.9rem; }
.combo-table th, .combo-table td { border: 1px solid var(--line); }
.combo-table thead th {
  vertical-align: bottom;
  padding: 6px 2px;
  font-weight: 600;
  background: var(--soft);
}
.combo-table .vname {
  display: inline-block;
  writing-mode: vertical-rl;
  text-orientation: upright;
  max-height: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.2;
}
.combo-table tbody th {
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  background: var(--soft);
}
.combo-table .rname {
  display: inline-block;
  max-width: 12em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.combo-table td { width: 44px; height: 44px; padding: 0; text-align: center; }
.combo-table td.same { background: var(--soft); }
.combo-table input[type="checkbox"] { width: 22px; height: 22px; margin: 0; cursor: pointer; accent-color: var(--accent); }
.combo-table td label { display: flex; align-items: center; justify-content: center; width: 100%; height: 44px; cursor: pointer; }

.combo-row { margin-bottom: 12px; }
.combo-row-title { margin: 0 0 6px; font-size: 0.9rem; font-weight: 600; }

.combo-generated { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.combo-generated h3 { margin: 0 0 6px; font-size: 0.95rem; }
.combo-generated ol { margin: 0; padding-left: 1.6em; font-size: 0.9rem; }
.combo-generated li { margin: 2px 0; }
.combo-generated .skip { color: var(--error); }
.combo-generated .copy { margin-top: 10px; }

/* 広い画面では表、狭い画面ではカードごとのボタン */
.combo-list, .combo-hint-narrow { display: none; }
@media (max-width: 599px) {
  .combo-matrix, .combo-hint-wide { display: none; }
  .combo-list, .combo-hint-narrow { display: block; }
}

.howto { margin-top: 14px; font-size: 0.9rem; }
.howto summary { cursor: pointer; color: var(--accent); }
.howto p { margin: 8px 0 0; }

/* 結果 */
.result { border-color: var(--accent); }

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.summary-col {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--accent-soft);
}
.summary-label { margin: 0; font-size: 0.9rem; font-weight: 600; color: var(--sub); }
.summary-sub { margin: 2px 0 0; font-size: 0.8rem; font-weight: 600; color: var(--accent); }
.effect-table tr.final th, .effect-table tr.final td { font-weight: 700; color: var(--accent); }
.result-sub-note { margin: 6px 0 0; font-size: 0.85rem; color: var(--sub); }
.result-number {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.result-exact {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.result-note { margin: 12px 0 0; }
.condition-text { margin: 12px 0 0; }

.result h3 { margin: 16px 0 0; font-size: 0.95rem; }
.pattern-table {
  width: 100%;
  margin-top: 6px;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.pattern-table th, .pattern-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.pattern-table thead th { font-size: 0.8rem; color: var(--sub); font-weight: 600; }
.pattern-table td, .pattern-table thead th.value {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pattern-table .sentence { display: block; font-weight: normal; color: var(--sub); overflow-wrap: anywhere; }

/* 計算の根拠 */
.rationale {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.rationale summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}
.rationale p { margin: 10px 0 0; }
.rationale-switch { display: flex; gap: 8px; margin-top: 12px; }
.switch {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 20px;
  background: #fff;
  color: var(--accent);
}
.switch[aria-pressed="true"] { background: var(--accent); color: #fff; }

.formula {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.table-wrap {
  margin-top: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.rationale-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 100%;
}
.rationale-table caption {
  text-align: left;
  font-weight: 600;
  padding-bottom: 6px;
}
.rationale-table th, .rationale-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.rationale-table thead th {
  font-weight: 600;
  color: var(--sub);
  vertical-align: bottom;
}
.rationale-table .col-name, .rationale-table .col-size { display: block; }
.rationale-table .col-size { font-weight: normal; }
.rationale .scroll-hint { margin: 4px 0 0; font-size: 0.8rem; color: var(--sub); }
.rationale-table .formula-cell { text-align: left; color: var(--sub); }
.rationale-table tfoot th, .rationale-table tfoot td { font-weight: 700; border-bottom: none; }
.rationale .notes { margin: 10px 0 0; padding-left: 1.2em; font-size: 0.85rem; color: var(--sub); }

/* 枚数を変えたときの比較 */
.compare { margin-top: 12px; }
.compare-field { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.compare-field label { font-weight: 600; font-size: 0.9rem; }
.compare-field select { max-width: 100%; }
.rationale-table tr.now th, .rationale-table tr.now td { background: var(--accent-soft); font-weight: 700; }
.rationale-table tbody th { text-align: left; font-weight: 600; }
.compare-table thead th:first-child { text-align: left; }
.target-list { margin: 12px 0 0; padding-left: 1.2em; }
.target-list li { margin: 6px 0; }
.compare .errors { margin-top: 12px; }
.compare .table-wrap + .scroll-hint + .notes, .compare .table-wrap + .notes { margin-top: 6px; }

/* 共有 */
.load-notice {
  margin: -8px 0 16px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.9rem;
}
.load-notice.bad { background: var(--error-soft); color: var(--error); }

.share-line { display: flex; gap: 8px; }
.share-line input { flex: 1; min-width: 0; color: var(--sub); font-size: 0.85rem; }
.action {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
}
.copy-status { margin: 6px 0 0; font-size: 0.875rem; color: var(--accent); }
.copy-status:empty { display: none; }
.copy-status.bad { color: var(--error); }
.share-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.share-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 22px;
  color: var(--accent);
  text-decoration: none;
}
.share-link:hover { background: var(--accent-soft); }
.share-link[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }

.errors {
  margin: 0;
  padding: 12px 12px 12px 30px;
  border-radius: 6px;
  background: var(--error-soft);
  color: var(--error);
}

/* 固定ページの枠の中：背景を透明にし、余白を固定ページの本文に任せる。
   見出しは固定ページのタイトルと重なるので、画面読み上げ用に残して見えなくする */
.embedded body { background: transparent; }
.embedded .tool { max-width: none; padding: 0 0 4px; }
.embedded h1 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.embedded .site-footer { display: none; }
/* 枠の高さを中身に合わせているとき（app.js の fitFrame）は、枠の中にスクロールバーを出さない */
.fitted, .fitted body { overflow: hidden; }

@media (max-width: 420px) {
  .tool { padding: 16px 12px 32px; }
  .embedded .tool { padding: 0 0 4px; }
  .panel { padding: 14px 12px; }
  .pattern { padding: 10px 8px; }
  .summary { gap: 8px; }
  .summary-col { padding: 8px 10px; }
  .result-number { font-size: 1.9rem; }
  .rationale-table { font-size: 0.8rem; }
  .rationale-table th, .rationale-table td { padding: 6px 5px; }
}
