@import url("tokens.css");

/* ---------- ベース ---------- */
*{ box-sizing:border-box; user-select:none; -webkit-user-select:none; -webkit-touch-callout:none; -webkit-tap-highlight-color:transparent; }
html,body{ margin:0; touch-action:manipulation; overscroll-behavior:none; }
body{ min-height:100dvh; background:var(--felt), var(--ground); color:var(--text); font-family:var(--jp); -webkit-font-smoothing:antialiased; line-height:1.4; }
input,button{ font-family:var(--jp); color:inherit; }
input[type=text],input[type=number]{ user-select:text; -webkit-user-select:text; }
a{ color:inherit; text-decoration:none; }
.num{ font-family:var(--mono); font-variant-numeric:tabular-nums; }
.muted{ color:var(--muted); }

/* ---------- 画面枠 ---------- */
.app{ display:flex; flex-direction:column; height:100dvh; width:100%; max-width:1240px; margin:0 auto; padding:12px 16px 8px; gap:8px; }
.topbar{ display:flex; align-items:center; gap:8px; padding-bottom:8px; border-bottom:1px solid var(--line); }
.topbar .spacer{ flex:1; }
.topbar .title{ font-weight:800; font-size:16px; }
.topbar .title b{ color:var(--accent); font-weight:800; }
.turnbar{ text-align:center; }
.turnbar .pill{ display:inline-flex; align-items:baseline; gap:6px; background:var(--panel-2); border:1px solid var(--line); border-radius:999px; padding:4px 16px; color:var(--muted); font-size:14px; }
.turnbar .pill b{ color:var(--accent); font-size:18px; }
.turnbar .pill .inn{ color:var(--text); }

/* ---------- スコア画面（左 P1・中央イニング表・右 P2） ---------- */
.court{ flex:1; min-height:0; display:flex; gap:8px; }
.pane{ flex:1; min-width:0; display:flex; flex-direction:column; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:10px 12px; box-shadow:var(--panel-shadow); }
.pane.active{ border-color:var(--accent); box-shadow:var(--active-glow); background:var(--active-bg); }
.pane .who{ display:flex; align-items:center; gap:8px; font-weight:800; font-size:18px; }
/* 長い名前（区切りの無いローマ字など）がペインからはみ出して画面に横スクロールを出さない */
.pane .who > span:first-child{ min-width:0; overflow-wrap:anywhere; }
.pane .who .target{ margin-left:auto; display:inline-flex; gap:5px; align-items:baseline; background:var(--panel); border:1px solid var(--line); border-radius:999px; padding:2px 11px; font-size:11px; color:var(--muted); }
.pane .who .target b{ color:var(--text); font-size:15px; }
.pane .stats{ display:flex; justify-content:space-around; color:var(--muted); font-size:12px; padding:4px 0; }
.pane .stats b{ display:block; color:var(--text); font-size:16px; }
.pane .score{ flex:1; min-height:0; display:flex; flex-direction:column; justify-content:center; align-items:center; text-align:center; position:relative; }
.pane .run{ color:var(--muted); font-size:12px; letter-spacing:.06em; }
.pane .run b{ display:block; color:var(--accent); font-size:clamp(30px, 5vw, 52px); line-height:1; margin-top:2px; }
.pane .total{ color:var(--muted); font-size:12px; letter-spacing:.06em; margin-top:8px; }
.pane .total b{ display:block; font-size:clamp(60px, 11vw, 112px); line-height:.95; letter-spacing:-.02em; text-shadow:var(--score-glow); }
.pane .banner{ position:absolute; top:0; left:0; right:0; padding:6px 0; border-radius:10px; background:var(--panel-2); color:var(--win); font-weight:800; font-size:28px; letter-spacing:.1em; }
.pane .banner.draw{ color:var(--accent-2); }

.innings{ flex:0 0 clamp(200px, 30%, 360px); overflow-y:auto; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); box-shadow:var(--panel-shadow); }
.innings table{ width:100%; border-collapse:collapse; }
.innings td{ border:1px solid var(--line); padding:5px 2px; text-align:center; font-family:var(--mono); font-variant-numeric:tabular-nums; font-size:15px; width:20%; }
.innings td.no{ background:var(--surface-2); color:var(--muted); font-weight:800; }
.innings td.sum{ color:var(--muted); }
.innings td.active{ background:var(--accent); color:var(--accent-ink); font-weight:800; }
.innings tr.over td.no{ color:var(--accent-2); }

/* ---------- 操作バー ---------- */
.controls{ display:flex; align-items:center; justify-content:space-around; gap:10px; padding:12px 0 4px; }
.controls .mid{ display:flex; flex-direction:column; align-items:center; gap:6px; min-width:clamp(140px, 24vw, 260px); }
.controls .mid .btn{ width:100%; }
.controls .mid .btn-undo{ width:75%; }

/* ---------- ボタン ---------- */
.btn{ border:1px solid var(--line); border-radius:var(--r); background:var(--panel); color:var(--text); cursor:pointer; font-weight:800; line-height:1.2; transition:transform .08s ease, opacity .2s ease; }
.btn:not([disabled]):active{ transform:scale(.97); }
.btn[disabled]{ color:var(--muted); background:var(--surface); border-color:var(--hair); box-shadow:none; opacity:.5; cursor:not-allowed; }
@media (hover:hover){ .btn:not([disabled]):hover{ filter:brightness(1.08); } }
.btn-sm{ font-size:13px; padding:6px 10px; }
.btn-md{ font-size:15px; padding:8px 14px; }
.btn-lg{ font-size:17px; padding:12px 18px; }
.btn-xl{ font-size:22px; padding:18px 28px; }
.btn-primary{ background:var(--accent); color:var(--accent-ink); border-color:transparent; }
.btn-secondary{ background:var(--accent-2); color:var(--accent-2-ink); border-color:transparent; }
.btn-danger{ background:transparent; color:var(--danger); border-color:var(--danger); }
.btn[disabled].btn-primary,.btn[disabled].btn-secondary,.btn[disabled].btn-danger{ background:var(--surface); color:var(--muted); border-color:var(--hair); }
/* ＋ ボタン。.btn-xl の font-size と .btn の border-radius に勝たせるためここに置く */
.plus{ width:clamp(84px, 13vw, 120px); height:clamp(84px, 13vw, 120px); border-radius:28px; font-size:44px; line-height:1; padding:0; box-shadow:var(--plus-shadow); }

/* ---------- モーダル ---------- */
.overlay{ position:fixed; inset:0; z-index:10; display:flex; align-items:center; justify-content:center; padding:16px; background:rgba(0,0,0,.55); backdrop-filter:blur(4px); -webkit-backdrop-filter:blur(4px); }
.modal{ width:min(92vw, 560px); max-height:90dvh; overflow:auto; background:var(--panel); color:var(--text); border:1px solid var(--line); border-radius:var(--r-panel); padding:18px; box-shadow:0 30px 80px -20px rgba(0,0,0,.7); }
.modal-wide{ width:min(92vw, 760px); }
.modal-title{ font-size:20px; font-weight:800; text-align:center; }
.modal-body{ margin-top:10px; text-align:center; }
.modal-body .players-line{ display:flex; justify-content:center; align-items:center; gap:14px; font-size:20px; font-weight:800; }
.modal-body .players-line .vs{ color:var(--muted); font-size:14px; }
.modal-actions{ display:flex; flex-wrap:wrap; justify-content:center; gap:10px; margin-top:18px; }
.modal-actions.stack{ flex-direction:column; align-items:stretch; }
.result-stats{ display:grid; grid-template-columns:repeat(3, minmax(0, 1fr)); gap:8px; margin-top:12px; }
.result-stats div{ background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:8px; font-size:12px; color:var(--muted); }
.result-stats div b{ display:block; color:var(--text); font-size:18px; }
.result-winner{ color:var(--win); font-size:26px; font-weight:900; }
.result-line{ display:flex; justify-content:center; align-items:center; gap:14px; font-size:44px; font-weight:800; margin-top:4px; }
.result-line .lo{ color:var(--muted); }

/* ---------- 設定フォーム ---------- */
.setup{ display:flex; flex-direction:column; gap:12px; text-align:left; }
.field{ display:flex; flex-direction:column; gap:6px; }
.field > label{ color:var(--muted); font-size:12px; font-weight:700; letter-spacing:.04em; }
.pcards{ display:flex; gap:12px; }
.pcard{ flex:1; min-width:0; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:12px 14px; display:flex; flex-direction:column; gap:10px; }
.pcard .pname{ width:100%; padding:6px 0; background:transparent; border:0; border-bottom:1px solid var(--line); border-radius:0; font-size:20px; font-weight:700; outline:none; }
.pcard .pname::placeholder{ color:var(--muted); font-weight:600; }
.pcard .pname:focus{ border-bottom-color:var(--accent); }
.pcard .lbl{ color:var(--muted); font-size:12px; }
.row2{ display:flex; gap:12px; }
.row2 .field{ flex:1; }
.seg{ display:flex; background:var(--panel-2); border:1px solid var(--line); border-radius:11px; padding:3px; }
.seg-item{ flex:1; position:relative; }
.seg-item input{ position:absolute; opacity:0; inset:0; margin:0; cursor:pointer; }
.seg-item span{ display:block; text-align:center; padding:9px 6px; border-radius:8px; color:var(--muted); font-weight:700; font-size:14px; }
.seg-item input:checked + span{ background:var(--accent); color:var(--accent-ink); }
.stepper-row{ display:flex; align-items:center; justify-content:center; gap:8px; }
.stepper-btn{ min-width:44px; min-height:44px; font-size:20px; }
.stepper-number{ width:3.4em; text-align:center; background:var(--panel); border:1px solid var(--line); border-radius:10px; font-family:var(--mono); font-variant-numeric:tabular-nums; font-weight:800; font-size:28px; padding:2px 4px; -moz-appearance:textfield; appearance:textfield; }
.stepper-number::-webkit-inner-spin-button,.stepper-number::-webkit-outer-spin-button{ -webkit-appearance:none; margin:0; }
.stepper-number:focus{ outline:2px solid var(--accent); outline-offset:1px; }
.stepper-range{ -webkit-appearance:none; appearance:none; width:100%; height:44px; margin:6px 0 0; background:transparent; cursor:pointer; touch-action:pan-y; }
.stepper-range:focus{ outline:none; }
.stepper-range::-webkit-slider-runnable-track{ height:8px; border-radius:999px; background:var(--surface-2); border:1px solid var(--line); }
.stepper-range::-webkit-slider-thumb{ -webkit-appearance:none; width:32px; height:32px; margin-top:-13px; border-radius:50%; background:var(--accent); border:3px solid var(--panel); box-shadow:0 4px 12px -4px rgba(0,0,0,.6); }
.stepper-range::-moz-range-track{ height:8px; border-radius:999px; background:var(--surface-2); border:1px solid var(--line); }
.stepper-range::-moz-range-thumb{ width:32px; height:32px; border-radius:50%; background:var(--accent); border:3px solid var(--panel); }

/* ---------- セットマッチ ---------- */
.pane.tappable{ cursor:pointer; }
.pane.tappable:active{ transform:scale(.995); }
.pane .badge{ margin-left:auto; background:var(--panel); border:1px solid var(--line); border-radius:999px; padding:2px 11px; font-size:11px; color:var(--muted); }
.pane .need{ color:var(--accent); font-size:13px; font-weight:800; text-align:center; }
.pane .taphint{ color:var(--muted); font-size:12px; text-align:center; }
/* キャロムの .pane .run（そのイニングの得点）とは意味が違うため別クラスにしている */
.pane .target-line{ color:var(--muted); font-size:12px; letter-spacing:.06em; }
.setbar{ text-align:center; }
.setbar .pill{ display:inline-flex; align-items:baseline; gap:6px; background:var(--panel-2); border:1px solid var(--line); border-radius:999px; padding:4px 16px; color:var(--muted); font-size:14px; }
.setbar .pill b{ color:var(--accent); font-size:18px; font-family:var(--mono); font-variant-numeric:tabular-nums; }
.sethistory{ overflow-x:auto; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:6px; }
.sethistory table{ border-collapse:collapse; }
.sethistory th,
.sethistory td{ border:1px solid var(--line); min-width:22px; height:24px; text-align:center; font-family:var(--mono); font-variant-numeric:tabular-nums; font-size:12px; color:var(--muted); }
.sethistory tbody th{ font-family:var(--jp); font-weight:700; color:var(--text); padding:0 8px; white-space:nowrap; text-align:left; }
.sethistory td.won{ color:var(--accent); font-weight:800; }

/* ---------- ボウラード ---------- */
.totalbar{ text-align:center; }
.totalbar .pill{ display:inline-flex; align-items:baseline; gap:8px; background:var(--panel-2); border:1px solid var(--line); border-radius:999px; padding:4px 18px; color:var(--muted); font-size:14px; }
.totalbar .pill b{ color:var(--text); font-family:var(--mono); font-variant-numeric:tabular-nums; font-size:24px; }
.sheet{ display:flex; gap:4px; overflow-x:auto; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:8px; }
.sheet .frame{ flex:1 0 auto; min-width:56px; border:1px solid var(--line); border-radius:8px; overflow:hidden; }
.sheet .frame.f10{ min-width:78px; }
.sheet .frame.current{ border-color:var(--accent); box-shadow:var(--active-glow); }
.sheet .fnum{ background:var(--surface-2); color:var(--muted); font-size:11px; text-align:center; padding:1px 0; }
.sheet .rolls{ display:flex; justify-content:center; gap:2px; padding:3px 0; }
.sheet .r{ display:grid; place-items:center; min-width:20px; height:22px; border:1px solid var(--line); border-radius:4px; font-family:var(--mono); font-variant-numeric:tabular-nums; font-size:14px; }
.sheet .r.strike,
.sheet .r.spare{ color:var(--accent-ink); background:var(--accent); border-color:transparent; font-weight:800; }
.sheet .fcum{ text-align:center; padding:3px 0 5px; font-family:var(--mono); font-variant-numeric:tabular-nums; font-size:18px; font-weight:800; }
.sheet .fcum.pending{ color:var(--muted); }
.padstate{ text-align:center; color:var(--muted); font-size:13px; }
.padstate b{ color:var(--accent); font-weight:800; }
.pad{ display:grid; grid-template-columns:repeat(6, minmax(0, 1fr)); gap:8px; }
.pad .btn{ min-height:52px; font-size:20px; }
.pad .btn.wide{ grid-column:span 2; }

/* ---------- JPA ---------- */
/* 9ボールの球色は実物に合わせた競技固有の色で、ダーク/ライトのテーマが変わっても変化しないため、
   tokens.css の配色トークンには加えず、この節の冒頭に固定値として定義する。
   以降のルールはこれらの変数（と共通トークン）だけを参照し、生の色を直接書かない。
   1・9番は黄系で明るいので文字色は既存の --accent-ink（濃色）を流用し、
   それ以外の暗めの球にはこの節専用の --jpa-ball-ink（明色・固定）を新設して使う。 */
:root{
  --jpa-ball-1:#C9982F;
  --jpa-ball-2:#2E5FA8;
  --jpa-ball-3:#B8362B;
  --jpa-ball-4:#6B3FA0;
  --jpa-ball-5:#C96A1F;
  --jpa-ball-6:#2E7D4F;
  --jpa-ball-7:#7A4034;
  --jpa-ball-8:#1E1E1E;
  --jpa-ball-9:#A97A16;
  --jpa-ball-ink:#F5F3EC;
}
.jprow{ display:flex; gap:8px; }
/* 先攻・後攻の入れ替え（最初の記録の前だけ）。カードのすぐ下に置く */
.swaprow{ display:flex; justify-content:center; }
/* JCL のプレイヤーカード（.jclcard）も同じ寸法・見た目のカードなので、球の色や .jpresult .rmain と
   同じ扱いでセレクタを並べて共有する。宣言を複製すると、あとで余白などを変えたとき片方だけ直る */
.jpcard,
.jclcard{ flex:1; min-width:0; display:flex; flex-direction:column; gap:8px; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:10px 12px; box-shadow:var(--panel-shadow); }
.jpcard.turn{ border-color:var(--accent); box-shadow:var(--active-glow); background:var(--active-bg); }
.jpcard .who,
.jclcard .who{ display:flex; align-items:center; gap:8px; }
/* 長い名前がカードからはみ出して画面に横スクロールを出さないよう .pane .who と同様に扱う */
.jpcard .who .nm,
.jclcard .who .nm{ font-weight:800; font-size:15px; min-width:0; overflow-wrap:anywhere; }
.jpcard .who .slbadge{ margin-left:auto; white-space:nowrap; background:var(--panel); border:1px solid var(--line); border-radius:999px; padding:2px 10px; font-size:11px; font-weight:700; color:var(--muted); }
.jpcard .who .slbadge b{ color:var(--accent-2); font-family:var(--mono); font-variant-numeric:tabular-nums; }
.ptsline{ display:flex; align-items:baseline; gap:6px; }
.ptsline .pts{ font-family:var(--mono); font-variant-numeric:tabular-nums; font-weight:800; font-size:clamp(26px, 7vw, 40px); line-height:1; text-shadow:var(--score-glow); }
.ptsline .req{ color:var(--muted); font-family:var(--mono); font-variant-numeric:tabular-nums; font-size:14px; }
.pbar{ height:7px; border-radius:999px; overflow:hidden; background:var(--panel); }
.pbar > i{ display:block; height:100%; background:var(--accent); border-radius:999px; }
/* 後攻側のカードは進捗バーの色も変えて一目で見分けられるようにする */
.jprow .jpcard:last-child .pbar > i{ background:var(--accent-2); }
.morebadge{ display:inline-block; background:var(--accent); color:var(--accent-ink); font-weight:900; font-size:12px; padding:3px 10px; border-radius:999px; letter-spacing:.04em; }

.rackpanel{ display:flex; flex-direction:column; gap:10px; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:12px; box-shadow:var(--panel-shadow); }
.rackhead{ text-align:center; color:var(--muted); font-size:13px; }
.rackhead b{ color:var(--text); }
.rack{ display:flex; flex-wrap:wrap; justify-content:center; gap:10px; }
/* 9番のモーダル・結果の画面の「マスワリ」のチェック。指で押しやすいよう行ごと押せる大きさにする */
.brcheck{ display:flex; align-items:center; justify-content:center; gap:10px; padding:10px 12px; border:1px solid var(--line); border-radius:var(--r); background:var(--surface-2); font-weight:800; cursor:pointer; }
.brcheck input{ width:22px; height:22px; accent-color:var(--accent); }
.jball{ width:48px; height:48px; border:none; border-radius:50%; cursor:pointer; position:relative; font-family:var(--mono); font-variant-numeric:tabular-nums; font-weight:800; font-size:16px; color:var(--jpa-ball-ink); transition:transform .08s ease, opacity .2s ease; }
.jball:not([disabled]):active{ transform:scale(.92); }
.jball[disabled]{ cursor:not-allowed; }
@media (hover:hover){ .jball:not([disabled]):hover{ filter:brightness(1.1); } }
/* 落ちた球をボタンごと消す・並びを変えるといった変更が入っても色がずれないよう、
   DOM の並び順（nth-child）ではなく球番号そのもの（data-ball）に色を結び付ける */
/* JCL（.jclrack）も同じ実物の9ボールを使う競技のため、色を JCL 用に定義し直さずここへセレクタだけ足す。
   同じ9ボールの色を2セット持つと片方だけ直す事故が起きる（5番の濃色インク調整もこれで自動的に効く） */
.rack .jball[data-ball="1"],
.jclrack .jball[data-ball="1"]{ background:var(--jpa-ball-1); color:var(--accent-ink); }
.rack .jball[data-ball="2"],
.jclrack .jball[data-ball="2"]{ background:var(--jpa-ball-2); }
.rack .jball[data-ball="3"],
.jclrack .jball[data-ball="3"]{ background:var(--jpa-ball-3); }
.rack .jball[data-ball="4"],
.jclrack .jball[data-ball="4"]{ background:var(--jpa-ball-4); }
/* 5番はオレンジで --jpa-ball-ink（明色）とのコントラストが基準未満のため、1・9番と同じ濃色インクにする */
.rack .jball[data-ball="5"],
.jclrack .jball[data-ball="5"]{ background:var(--jpa-ball-5); color:var(--accent-ink); }
.rack .jball[data-ball="6"],
.jclrack .jball[data-ball="6"]{ background:var(--jpa-ball-6); }
.rack .jball[data-ball="7"],
.jclrack .jball[data-ball="7"]{ background:var(--jpa-ball-7); }
.rack .jball[data-ball="8"],
.jclrack .jball[data-ball="8"]{ background:var(--jpa-ball-8); }
.rack .jball[data-ball="9"],
.jclrack .jball[data-ball="9"]{ background:var(--jpa-ball-9); color:var(--accent-ink); }
.jball.down{ opacity:.32; }
.jball.dead{ opacity:.55; }
/* デッド球は数字の上に斜線を重ねて示す（危険色は共通トークンの --danger を使う） */
.jball.dead::after{ content:""; position:absolute; inset:0; border-radius:50%; background:linear-gradient(45deg, transparent 46%, var(--danger) 46% 54%, transparent 54%); }
.jball .pv{ position:absolute; top:-6px; right:-4px; background:var(--accent); color:var(--accent-ink); font-family:var(--mono); font-variant-numeric:tabular-nums; font-weight:800; font-size:10px; line-height:1.4; padding:0 5px; border-radius:999px; }

.events{ display:flex; gap:8px; }
.events .btn{ flex:1; }
/* 団体戦は TIME を足して4つ並べる。スマホでも1行に収まるよう、ボタンの左右の余白を詰める */
.events.four .btn{ min-width:0; padding-left:4px; padding-right:4px; }

.sheetpanel{ display:flex; flex-direction:column; gap:8px; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:10px 12px; box-shadow:var(--panel-shadow); }
.sslabel{ color:var(--muted); font-size:11px; font-weight:700; }

.innwrap{ overflow-x:auto; border:1px solid var(--line); border-radius:8px; }
/* ボウラードの .sheet と名前が衝突しないよう、イニング式スコアシートは別クラスにしている */
.innsheet{ width:100%; min-width:460px; border-collapse:collapse; }
.innsheet th,
.innsheet td{ border:1px solid var(--line); padding:4px 2px; min-width:28px; text-align:center; font-family:var(--mono); font-variant-numeric:tabular-nums; font-size:12px; }
.innsheet thead th{ background:var(--surface-2); color:var(--muted); font-size:10px; font-weight:800; }
.innsheet th.current,
.innsheet td.current{ background:var(--accent); color:var(--accent-ink); font-weight:800; }
/* 横スクロールしても行名（プレイヤー）が見えるよう左端列だけ固定する。
   名前は maxlength=20 まで入るため、幅の上限を置いて省略記号で切る（切れた分は title 属性で補う）。
   はみ出た名前がイニングの得点セルを覆い隠して1マスも読めなくなる事故を防ぐのが目的。
   table-layout:auto では2つの対策が要る。
   1) セル（.pl）自体に width を指定する。指定が無いと、イニング数が少ない試合では
      表全体が min-width まで引き伸ばされる際に余white-spaceの大半がこの列に配分されてしまう
      （幅の指定がある列は、この余り配分の対象から外れる）。
   2) 中の文字は screen.js 側で .plname（display:block の子要素）にラップし、そこへ
      max-width と overflow:hidden 等を置く。セル自身に max-width を置いても、1行で
      折り返さない中身がある場合は列幅の計算に反映されない（自動レイアウトの仕様）ため、
      子要素の内容量を小さくすることで初めて列幅もそこまでしか広がらなくなる。
      .plname の max-width は「.pl の width から左右padding・borderを引いた値」に揃えること。
      ここがズレると、名前が長いときだけ .plname が内側で入りきらず .pl 自体が押し広げられる。 */
.innsheet .pl{ position:sticky; left:-1px; z-index:1; box-shadow:inset -1px 0 0 var(--line), 2px 0 4px rgba(0,0,0,.08); background:var(--panel-2); text-align:left; padding:4px 8px; font-family:var(--jp); font-weight:800; font-size:12px; width:140px; }
.innsheet .pl .plname{ display:block; max-width:122px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
/* 左上セル（見出し行の th.pl）は行名セルと同じ見た目を継承してしまうため、見出しとしての背景・文字サイズを他の見出しセルに揃える */
/* 左端は left:-1px（罫線を重ねる表なので、0 だと左に1pxの隙間ができ、下を通る数字がのぞく）。
   重ねる罫線は貼り付いた列と一緒に動かないので、右端の線は box-shadow で引く。
   --surface-2 は半透明なので、そのままだと横スクロールで下を通るラック番号が透けて重なる。不透明な --panel-2 の上に重ねる */
.innsheet thead .pl{ background:linear-gradient(var(--surface-2), var(--surface-2)), var(--panel-2); font-size:10px; }
.innsheet td.tot{ background:var(--surface-2); color:var(--text); font-weight:800; }
/* ラックの表のイニング・無効球の棒（スコアシートの書き方） */
/* ラックの表は列の幅を中身に合わせ、入りきらなくなったら横スクロールする（最低幅を付けると、ラックが少ないときに
   列が広がり、右端まで送ったときに今のラックの列の中身が左の名前の列の下に隠れる） */
.innsheet.racksheet{ min-width:0; }
.racksheet td{ position:relative; }
/* タイムアウトの「T」。獲得点の数字と重ならないよう、セルの右端に小さく寄せる */
/* T の分の余白を右に取る（2桁の得点と「TT」でも重ならないように） */
.racksheet td.hast1{ padding-right:12px; }
.racksheet td.hast2{ padding-right:18px; }
.racksheet .tmark{ position:absolute; right:3px; top:50%; transform:translateY(-50%); color:var(--danger); font-family:var(--jp); font-size:10px; font-weight:900; letter-spacing:-.5px; }
.racksheet .tally{ display:block; margin:0 auto; stroke:currentColor; stroke-width:1.6; stroke-linecap:round; }

.tallywrap{ overflow-x:auto; border:1px solid var(--line); border-radius:8px; }
.tallytbl{ width:100%; min-width:320px; border-collapse:collapse; }
.tallytbl th,
.tallytbl td{ border:1px solid var(--line); padding:6px 8px; text-align:center; font-family:var(--mono); font-variant-numeric:tabular-nums; font-weight:800; font-size:14px; }
.tallytbl thead th{ background:var(--surface-2); color:var(--muted); font-size:10px; font-weight:800; }
.tallytbl tbody td{ color:var(--accent); }
.tallytbl td.zero{ color:var(--muted); font-weight:700; }
/* イニング表の .pl と同じ理由・同じ扱いで width と .plname の幅の上限・省略記号を入れる（列数が少なく被害は小さいが揃える） */
.tallytbl .pl{ position:sticky; left:0; background:var(--panel-2); text-align:left; font-family:var(--jp); font-weight:800; font-size:12px; color:var(--text); width:140px; }
.tallytbl .pl .plname{ display:block; max-width:122px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

.jpresult{ display:flex; flex-direction:column; gap:10px; }
/* JCL の結果カード（.jclresult .rmain）も同じ見た目を使う。球の色と同じ理由でセレクタを並べて共有し、
   値を複製しない（複製すると片方だけ直す事故が起きる。JPA の5番球の文字色調整が実際にそれで起きた） */
.jpresult .rmain,
.jclresult .rmain{ background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:16px; text-align:center; }
.scoreline{ display:flex; align-items:center; justify-content:center; gap:14px; font-family:var(--mono); font-variant-numeric:tabular-nums; font-weight:800; font-size:clamp(30px, 7vw, 40px); margin-top:6px; }
.scoreline .vs{ color:var(--muted); font-size:15px; }
.scoreline .lo{ color:var(--muted); }
.rstat{ display:flex; align-items:baseline; justify-content:space-between; gap:10px; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:9px 12px; font-size:12px; color:var(--muted); }
.rstat b{ color:var(--text); font-family:var(--mono); font-variant-numeric:tabular-nums; font-weight:800; font-size:15px; }

/* ---------- JCL ---------- */
.jclrow{ display:flex; gap:8px; }
/* カード自体の見た目は JPA 節の .jpcard と共有している（上記参照）。ここに残すのは JCL 固有の1点だけで、
   受け皿の「ここへ」（.dzhint）を絶対配置で全面に重ねるための基準になる */
.jclcard{ position:relative; }
/* ドラッグ中の球がこのカードの上に来ている状態。JPA の .jpcard.turn・キャロムの .pane.active と同じ「強調」の見た目を流用し、
   競技をまたいで「今ここが対象」の意味が揃うようにする */
.jclcard.drop-hover{ border-color:var(--accent); box-shadow:var(--active-glow); background:var(--active-bg); }
.jclcard .hillbadge{ background:var(--accent); color:var(--accent-ink); font-weight:900; font-size:10px; padding:2px 9px; border-radius:999px; letter-spacing:.08em; white-space:nowrap; }
/* FargoRate バッジ。.who 内では margin-left:auto で右端に寄せる（HILL バッジ等は左詰めのまま残る） */
/* 名前を1文字ずつ縦に折り返さないよう幅を確保し、入りきらない印は次の行へ回す */
.jpcard .who,
.jclcard .who{ flex-wrap:wrap; row-gap:6px; }
.jpcard .who .nm,
.jclcard .who .nm{ flex:1 1 5em; }
/* 先攻・後攻の印。先攻はブレイクの順番が分かるよう強調する */
.jclcard .turnbadge{ white-space:nowrap; border:1px solid var(--line); border-radius:999px; padding:2px 9px; font-size:10px; font-weight:800; color:var(--muted); }
.jclcard .turnbadge.first{ border-color:var(--accent); color:var(--accent); }
.frbadge{ margin-left:auto; white-space:nowrap; background:var(--panel); border:1px solid var(--line); border-radius:999px; padding:2px 10px; font-size:11px; font-weight:700; color:var(--muted); }
.frbadge b{ color:var(--accent-2); font-family:var(--mono); font-variant-numeric:tabular-nums; }

/* 「ヒルヒル」の帯（両者が最後の1ラックのとき）。進行中の強調と同じトークン（--active-bg・--accent）を使う */
.hillhill{ display:flex; align-items:center; justify-content:center; gap:8px; background:var(--active-bg); border:1px solid var(--accent); border-radius:var(--r); padding:8px 12px; text-align:center; font-weight:800; font-size:13px; color:var(--accent); }

/* ドラッグ中だけ描かれる「ここへ」の受け皿。画面は状態が変わるたびに全描き直しになる作りのため、
   表示・非表示の切り替えはここに書かず、ドラッグしていないときはこの要素自体を描画に含めない実装を想定する。
   .jclcard・.deadzone はどちらも position:relative なので、そのまま重なって全面に表示される */
.dzhint{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; background:var(--active-bg); border:1px dashed var(--accent); border-radius:var(--r); font-weight:800; font-size:13px; color:var(--text); pointer-events:none; }
/* 実際に球が乗っている先だけ縁を実線にして「離せばここに入る」ことを区別する */
.jclcard.drop-hover .dzhint,
.deadzone.drop-hover .dzhint{ border-style:solid; color:var(--accent); }

/* デッド（無効球）の受け皿。プレイヤーカード2枚と並ぶ3つ目の落とし先 */
.deadzone{ position:relative; flex:1; min-width:0; display:flex; align-items:center; justify-content:center; min-height:44px; background:var(--panel-2); border:1px dashed var(--line); border-radius:var(--r); padding:8px 12px; color:var(--muted); font-size:12px; font-weight:700; }
.deadzone.drop-hover{ border-color:var(--accent); color:var(--accent); }

/* 1〜9番の球の並び。球そのものの見た目・色は JPA の .jball と --jpa-ball-* をそのまま使うため、
   ここでは並びと、ドラッグ可能であることを示す指定だけを足す */
.jclrack{ display:flex; flex-wrap:wrap; justify-content:center; gap:10px; }
/* タブレットでドラッグ中にページが一緒にスクロールしてしまうのを防ぐ */
.jclrack .jball{ cursor:grab; touch-action:none; }
.jclrack .jball:not([disabled]):active{ cursor:grabbing; }
/* タップで選んだ球（ドラッグの代わりにタップ2回で落とす操作の選択状態） */
.jball.picked{ box-shadow:0 0 0 3px var(--accent); }

/* ドラッグ中に指の下へ出す球の影。.overlay（z-index:10）より確実に前面へ出す */
.dragghost{ position:fixed; z-index:20; transform:translate(-50%, -50%); pointer-events:none; opacity:.9; }
/* 操作の案内文（「球をカードへドラッグ…」／「落とす先をタップ…」） */
.dragstatus{ text-align:center; color:var(--muted); font-size:12px; min-height:18px; }
.dragstatus b{ color:var(--accent); }

/* ラック式スコアシート（横スクロール）。構造・意図は JPA の .innwrap / .innsheet と同じ */
.rkwrap{ overflow-x:auto; border:1px solid var(--line); border-radius:8px; }
.rktbl{ width:100%; min-width:420px; border-collapse:collapse; }
.rktbl th,
.rktbl td{ border:1px solid var(--line); padding:4px 2px; min-width:32px; text-align:center; font-family:var(--mono); font-variant-numeric:tabular-nums; font-size:12px; }
.rktbl thead th{ background:var(--surface-2); color:var(--muted); font-size:10px; font-weight:800; }
.rktbl th.current,
.rktbl td.current{ background:var(--accent); color:var(--accent-ink); font-weight:800; }
/* そのラックで9番を入れた勝者のセル（14点固定） */
.rktbl td.w{ color:var(--accent); font-weight:800; }
.rktbl td.tot{ background:var(--surface-2); color:var(--text); font-weight:800; }
/* 左端の固定列。長い名前が得点セルを覆って1マスも読めなくなる事故を防ぐため、
   .innsheet .pl と同じ理由・同じ考え方で width と .plname の max-width をセットで置く
   （なぜこの2つが両方要るかの詳細は .innsheet の節のコメントを参照） */
.rktbl .pl{ position:sticky; left:0; z-index:1; background:var(--panel-2); text-align:left; padding:4px 8px; font-family:var(--jp); font-weight:800; font-size:12px; width:140px; }
.rktbl .pl .plname{ display:block; max-width:122px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.rktbl thead .pl{ background:var(--surface-2); font-size:10px; }

/* 結果。.rmain は JPA 節の .jpresult .rmain にセレクタを追加する形で共有している（上記参照）。
   .scoreline / .rstat は元々スコープの無いクラスなのでそのまま再利用する */
.jclresult{ display:flex; flex-direction:column; gap:10px; }

/* ---------- 復元・ホーム ---------- */
.blank{ flex:1; }

/* 旧バージョン（carom-legacy.html）への退避リンク */
.legacy-link{ display:block; text-align:center; color:var(--muted); font-size:12px; margin-top:4px; text-decoration:underline; }
/* 旧バージョンに中断した試合が残っているときの案内。見落とすと途中経過に戻れないので強調する */
.legacy-notice{ display:block; text-align:center; color:var(--accent); font-size:13px; font-weight:800; margin-top:4px; padding:8px; border:1px solid var(--accent); border-radius:var(--r); text-decoration:none; }

/* ---------- スマホ縦持ち ---------- */
@media screen and (max-width:640px) and (orientation:portrait){
  .app{ padding:10px 12px 0; }
  .court{ flex-wrap:wrap; overflow-y:auto; align-content:flex-start; }
  .court > .pane{ flex:1 1 calc(50% - 4px); order:1; padding:8px; }
  .court > .innings{ order:3; flex:1 1 100%; min-height:160px; max-height:38dvh; }
  /* 中央のイニング表が無い競技（セットマッチ）は、2つのペインで残りの高さを使い切る */
  .court.court-2{ flex-wrap:nowrap; overflow-y:visible; }
  .court.court-2 > .pane{ flex:1 1 0; }
  .pane .total b{ font-size:56px; }
  .pane .run b{ font-size:28px; }
  .pane .who{ font-size:15px; }
  .sethistory{ max-height:22dvh; }
  .pad{ grid-template-columns:repeat(4, minmax(0, 1fr)); }
  .pad .btn{ min-height:48px; font-size:18px; }
  .sheet .frame{ min-width:48px; }
  /* スコアシートの左端の列（sticky・z-index:1）がスクロールで下に来たとき、操作ボタンの上に重ならないよう前面に置く。
     ダイアログ（.overlay・z-index:10）よりは後ろ */
  .controls{ position:sticky; bottom:0; z-index:2; background:var(--ground); border-top:1px solid var(--line); padding-bottom:calc(8px + env(safe-area-inset-bottom)); }
  .controls .mid{ min-width:120px; }
  .btn-xl{ font-size:18px; padding:12px 16px; }
  .plus{ width:72px; height:72px; font-size:36px; }
  /* ボタン（新しい試合・終了）は1行に保ち、入りきらないときは見出しの文字の方を折り返す
    （ボタンごと次の行へ落ちると、「終了」の位置が試合ごとに変わって押し間違えやすい） */
  .topbar{ flex-wrap:nowrap; }
  .topbar .btn{ flex-shrink:0; }
  .topbar .title{ flex:1 1 auto; min-width:0; overflow-wrap:anywhere; }
  .pcards{ flex-direction:column; }
  .row2{ flex-direction:column; }
  .result-stats{ grid-template-columns:1fr 1fr; }
  /* JPA: 縦持ちでも左右のプレイヤーは常に並べる（.jprow は既定で横並びのため上書き不要）。
     .innwrap も既定の overflow-x:auto のまま横スクロールする */
  /* 球は 1〜5 と 6〜9 の2行にする（3列だと4行になり、記録ボタンまでスクロールが要る）。
     10列のマスに2マスずつ置き、2行目は1マスずらして中央に寄せる */
  .rack{ display:grid; grid-template-columns:repeat(10, minmax(0, 1fr)); gap:8px; }
  .rack .jball{ width:auto; height:auto; aspect-ratio:1/1; grid-column:span 2; }
  .rack .jball[data-ball="6"]{ grid-column:2 / span 2; }
  /* 縦持ちはスクロール枠がさらに狭いので、名前列をもう一段絞ってイニングの得点セルを確保する */
  .innsheet .pl,
  .tallytbl .pl{ width:110px; }
  .innsheet .pl .plname,
  .tallytbl .pl .plname{ max-width:92px; }
  /* JCL: 縦持ちでも左右のプレイヤーカードは常に並べる（.jclrow は既定で横並びのため上書き不要）。
     .rkwrap も既定の overflow-x:auto のまま横スクロールする */
  .jclrack{ display:grid; grid-template-columns:repeat(3, minmax(0, 1fr)); gap:8px; }
  .jclrack .jball{ width:auto; height:auto; aspect-ratio:1/1; }
  .rktbl .pl{ width:110px; }
  .rktbl .pl .plname{ max-width:92px; }
}
@media (prefers-reduced-motion:reduce){ *{ transition:none!important; } }

/* ---------- 店内リーグ（会員ページの「対戦する」から開いたとき） ---------- */
.league-note{ margin:var(--spacer-2) 0; padding:var(--spacer-2) var(--spacer-3); border-radius:var(--r); background:var(--active-bg); border:1px solid var(--accent); font-size:14px; line-height:1.5; }
.league-note.warn{ background:transparent; border-color:var(--danger); color:var(--danger); }
/* 名前は会員ページで決めたものから変えられないので、入力欄ではなく文字で出す */
.pcard .pname.fixed{ border-bottom-color:transparent; }

/* ---------- JPA チーム戦（jpa-team.html） ---------- */
.tm-code{ width:100%; padding:10px 12px; font-family:var(--mono); font-size:28px; letter-spacing:.2em; text-align:center; text-transform:uppercase; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); color:inherit; }
.tm-teams{ display:flex; gap:12px; margin:12px 0; }
.tm-team{ flex:1; min-width:0; background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:10px 12px; text-align:center; }
.tm-team-name{ font-weight:800; font-size:16px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.tm-points{ font-size:36px; font-weight:800; color:var(--accent); }
.tm-games{ display:flex; flex-direction:column; gap:10px; }
.tm-game{ background:var(--panel-2); border:1px solid var(--line); border-radius:var(--r); padding:10px 12px; display:flex; flex-direction:column; gap:8px; }
.tm-game-head{ display:flex; justify-content:space-between; gap:8px; font-size:14px; }
.tm-game-players{ display:grid; grid-template-columns:1fr auto 1fr; gap:8px; align-items:center; }
.tm-game-players > div:last-child{ text-align:right; }
.tm-game-score{ font-weight:800; font-size:18px; }
.tm-game-actions{ display:flex; justify-content:flex-end; }
.tm-forfeit{ color:var(--danger); white-space:nowrap; }
.tm-finished{ display:flex; flex-direction:column; align-items:flex-start; gap:8px; }
.tm-sheet{ display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:8px; margin:12px 0; }
.tm-sheet-actions{ display:flex; flex-wrap:wrap; gap:8px; }
.tm-select{ width:100%; padding:8px; font-size:16px; background:var(--panel); color:inherit; border:1px solid var(--line); border-radius:8px; }
.tm-sync{ flex:0 0 auto; width:4.5em; text-align:right; font-size:12px; color:var(--muted); white-space:nowrap; }
.tm-sync.offline, .tm-sync.error{ color:var(--danger); font-weight:700; }
@media (max-width:480px){
  .tm-teams{ gap:8px; }
  .tm-points{ font-size:28px; }
}
