:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1c1f26;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;
  --rank1: #e0b34a;
  --rank2: #9aa4b2;
  --rank3: #b97a4e;
  --rank4: #c4553f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --card-bg: #1d2027;
    --text: #e7e9ee;
    --muted: #9aa1ad;
    --border: #2b2f38;
    --accent: #5b8cff;
    --accent-soft: #22314f;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* タイトルと同じ行の右側にタブメニューを並べて、ヘッダーの高さを詰める
   （入力画面をできるだけ広く使いたいため）。 */
header {
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border);
}
h1 { font-size: 1.1rem; margin: 0; white-space: nowrap; }
/* エラー文言（動画DL失敗時の例外メッセージ等）が長いと、ヘッダーの
   flex-wrapでタブ列が2行目に押し出されてしまうため、幅を制限して
   省略表示にする（全文はホバー時のtitleで見られる）。 */
.prefetch-status {
  font-size: 0.78rem; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 32vw;
}
.prefetch-status.active { color: #2f7d4f; }
.prefetch-status.stale { color: #c0392b; font-weight: 600; }

#tabs { display: flex; gap: 4px; }
.tab-btn {
  padding: 6px 14px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
/* ヘッダー右端の「パラパラ（キャプチャ）」。タブではない（別ウインドウを開く）ので枠付きで区別する。 */
.header-capture-btn {
  margin-left: 10px; padding: 4px 12px; font-size: 0.8rem; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: none; color: var(--muted);
}
.header-capture-btn:hover { color: var(--accent); border-color: var(--accent); }

main { padding: 20px 24px 60px; max-width: 1100px; margin: 0 auto; }
/* 対局入力タブは2卓横並び表示の幅を確保するため上限を外す */
main.wide-main { max-width: none; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }

.filter-row { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.hidden { display: none !important; }

.player-select-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; flex-wrap: wrap; }
.player-select-main { display: flex; align-items: center; gap: 14px; }
.player-photo { width: 48px; height: 66px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); background: var(--bg); flex: none; }
.player-team-history { color: var(--muted); font-size: 1.7rem; text-align: left; line-height: 1.6; }
.player-team-history .team-history-item { display: flex; white-space: nowrap; }
.player-team-history .team-history-period { min-width: 9em; flex: none; }

/* 期間指定（日）フィルタ用の自前カレンダーピッカー */
.date-picker-input { cursor: pointer; width: 110px; }
.date-picker-popup {
  position: absolute; z-index: 500; background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); width: 240px;
}
.date-picker-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.date-picker-title { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.date-picker-nav {
  background: none; border: none; color: var(--text); font-size: 1.1rem;
  padding: 2px 8px; margin: 0; cursor: pointer;
}
.date-picker-nav:hover { background: var(--bg); border-radius: 4px; }
.date-picker-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.date-picker-weekday { text-align: center; font-size: 0.75rem; color: var(--muted); padding: 2px 0; }
.date-picker-cell { text-align: center; padding: 5px 0; font-size: 0.85rem; border-radius: 4px; }
.date-picker-cell.empty { visibility: hidden; }
.date-picker-cell.enabled { cursor: pointer; color: var(--text); }
.date-picker-cell.enabled:hover { background: var(--accent); color: white; }
.date-picker-cell.disabled { color: var(--muted); opacity: 0.35; cursor: not-allowed; }

select, input[type=number] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.9rem;
}
select[multiple] { min-width: 140px; }

label { font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
label.chk { flex-direction: row; align-items: center; gap: 6px; display: inline-flex; margin-right: 10px; }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-left: 10px;
}
button:hover { opacity: 0.9; }

.tab-panel.hidden { display: none; }

.note { color: var(--muted); font-size: 0.8rem; margin: 8px 0 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.stat-tile .label { font-size: 0.72rem; color: var(--muted); }
.stat-tile .value { font-size: 1.25rem; font-weight: 600; margin-top: 2px; }
.stat-tile .player-name-label {
  font-size: 1.15rem; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 8px; flex-wrap: nowrap;
}
/* 名前は先頭2文字だけを縦書きで表示する（誰かは顔写真で分かるため）。
   文字数に関わらず常に2文字ぶんの高さで揃うので、下のボタン位置がズレない。 */
.stat-tile .player-name-text {
  writing-mode: vertical-rl; text-orientation: upright;
  line-height: 1.15; flex: none;
}
.player-photo { width: 52px; height: 72px; border-radius: 8px; object-fit: cover; flex: none; }
.chombo-btn {
  font-size: 0.62rem; padding: 2px 6px; border-radius: 10px; line-height: 1.4;
  border: 1px solid #c4553f; color: #c4553f; background: transparent; white-space: nowrap;
}
.chombo-btn:hover { background: #c4553f; color: white; }
.stat-tile .score-value { font-size: 2.1rem; }
/* 進行中対局で現在の親を一目で分かるようにする（東場=赤、南場=緑） */
.stat-tile.dealer-tile-east { border: 2px solid #c4293a; background: color-mix(in srgb, #c4293a 8%, var(--bg)); }
.stat-tile.dealer-tile-south { border: 2px solid #2e9e5b; background: color-mix(in srgb, #2e9e5b 8%, var(--bg)); }
/* 常に4列固定・カード幅は最大165px（1frだと1卓だけ表示している時にパネル全体の
   横幅いっぱいまでカードが伸びて間延びしてしまうため、上限を付けて4人分がまとまって
   見えるようにする）。minmax(0, 165px)なので、2卓同時表示でパネル自体が狭い時は
   逆に165pxより縮んで4人目が折り返されるのを防ぐ側にも働く。 */
.entry-panel .stat-grid { grid-template-columns: repeat(4, minmax(0, 165px)); justify-content: start; gap: 12px; }
.entry-panel .stat-tile { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.stat-tile .score-value.negative { color: #c4553f; }
/* 選手検索の得点欄（最高/最低得点・対戦履歴の得点）のマイナス表示 */
.stat-tile .value .negative,
.match-history-table .seat-score .negative { color: #c4553f; }

/* 選手検索の「基本成績」カードだけ文字サイズを1.5倍にする（対局入力の.stat-tileとは別扱い） */
.basic-stats-card h2 { font-size: 1.575rem; }
.basic-stats-card .stat-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.basic-stats-card .stat-tile .label { font-size: 1.08rem; }
.basic-stats-card .stat-tile .value { font-size: 1.875rem; }
/* 役・点数選択に応じた収支のプレビュー（このまま確定した場合の増減） */
/* 「-」の直後は改行してよい箇所とブラウザに解釈されるため、nowrapがないと
   マイナスの増減（例:「-4500」）だけ「-」と数字の間で折り返されカードが縦に伸びてしまう。 */
.score-delta-preview { font-size: 0.9rem; font-weight: 600; margin-left: 6px; white-space: nowrap; }
.score-delta-preview.positive { color: #2e9e5b; }
.score-delta-preview.negative { color: #c4553f; }

/* 対局検索の結果など、終了済み対局の持ち点の横に小さく獲得ポイントを添える */
.score-points { font-size: 0.62rem; font-weight: 600; color: var(--muted); margin-left: 3px; white-space: nowrap; }

.rank-bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; margin: 8px 0 4px; }
.rank-bar span { display: flex; align-items: center; justify-content: center; font-size: 0.75rem; color: white; }
.rank-bar .r1 { background: var(--rank1); }
.rank-bar .r2 { background: var(--rank2); }
.rank-bar .r3 { background: var(--rank3); }
.rank-bar .r4 { background: var(--rank4); }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover { background: var(--accent-soft); }

/* 100%幅で無理に引き伸ばさず、内容分だけの幅で左詰めにする。
   それでも収まらない場合は親を横スクロールさせる（切れて見えなくなるのを防ぐ）。 */
.hand-history-wrap { overflow-x: auto; }
.hand-history-table { width: auto; white-space: nowrap; }
.hand-history-table th, .hand-history-table td { padding: 6px 8px; }
.hand-history-table th:nth-child(n+7), .hand-history-table td:nth-child(n+7) { text-align: left; }
.hand-history-table td.negative { color: #c4553f; }

/* 対局検索の簡易表示（1試合1行、着順を列に固定） */
.simple-search-table th, .simple-search-table td { text-align: center; }
.simple-search-table td { line-height: 1.5; }
/* 対局日ごとにまとめて交互に網掛け（同じ日の複数試合は同じ色になる） */
.simple-search-table tr.date-shade td { background: rgba(127, 127, 127, 0.12); }

/* 対局検索: 一覧の右側に、今表示している対局だけの個人/チームポイントランキングを
   並べる。一覧側を優先して縮めたくないので、ランキング側は横幅を固定気味にし、
   画面が狭い時は下に折り返す。 */
.search-results-row { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.search-results-table-wrap { flex: 3 1 600px; min-width: 0; }
.search-ranking-panel { flex: 1 1 260px; min-width: 240px; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.search-ranking-panel h3 { margin: 0; font-size: 0.95rem; }
.search-ranking-panel h3:not(:first-child) { margin-top: 8px; }
.search-ranking-table { width: 100%; white-space: normal; }
.search-ranking-table th, .search-ranking-table td { text-align: right; padding: 4px 6px; }
.search-ranking-table th:nth-child(1), .search-ranking-table td:nth-child(1) { text-align: center; width: 2em; }
.search-ranking-table th:nth-child(2), .search-ranking-table td:nth-child(2) { text-align: left; }
.search-ranking-table td.negative { color: #c4553f; }
.search-ranking-team-cell { display: flex; align-items: center; gap: 5px; }

/* 終了済み局履歴の「編集」ボタンとその場に開く編集フォーム */
.hand-edit-btn { margin-left: 8px; font-size: 0.72rem; padding: 2px 8px; }
tr.hand-edit-row td { background: var(--accent-soft); padding: 12px !important; }
.hand-edit-form .yaku-picker { margin: 0 0 10px; }
.hand-edit-actions { display: flex; align-items: center; gap: 10px; }

/* 終了済みパネルの実況・解説編集欄 */
.announcer-edit-row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-top: 10px; }

/* 対局情報（シーズン/ステージ/対局日/卓・戦番号）編集欄。前回入力から選択が
   残ったまま新規作成してしまった場合等の訂正用（進行中・終了済み両パネル共通）。 */
.gameinfo-edit-row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-top: 10px; }
.gameinfo-edit-row .edit-season { width: 6em; }
.gameinfo-edit-row .edit-table-no, .gameinfo-edit-row .edit-game-no { width: 4em; }

/* 「結果だけ先に入力」欄（局を1つも入れていない対局のみ表示）。 */
.quick-finish-row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-top: 10px; }
.quick-finish-row .note { flex-basis: 100%; margin: 0 0 4px; }
.quick-finish-score { width: 6em; }

.error { color: #c4553f; font-size: 0.9rem; }
.hand-error { margin-left: 10px; }

.table-wrap { overflow-x: auto; }
.match-history-table { width: auto; min-width: 100%; white-space: nowrap; font-size: 1.275rem; }
.match-history-table th, .match-history-table td { padding: 6px 10px; text-align: center; }
.match-history-table th:nth-child(-n+3), .match-history-table td:nth-child(-n+3) { text-align: left; }
.match-history-table .seat-name { font-size: 1.275rem; }
.match-history-table .seat-rank, .match-history-table .seat-score, .match-history-table .seat-points {
  font-size: 1.125rem; color: var(--muted);
}
/* 雀荘のスコア表ツールに合わせた着順の網掛け（1着=薄黄色, 2着=薄青, 3着=薄ピンク, 4着=無地） */
.match-history-table td.seat-rank-1 { background: rgba(255, 202, 40, 0.22); }
.match-history-table td.seat-rank-2 { background: rgba(66, 165, 245, 0.18); }
.match-history-table td.seat-rank-3 { background: rgba(240, 98, 146, 0.18); }
/* 検索対象の本人は網掛けではなく赤枠で囲んで区別する（outlineはborder-collapseの影響を受けない） */
.match-history-table td.seat-self { outline: 2px solid #c4553f; outline-offset: -2px; border-radius: 6px; }
.match-history-table td.seat-self .seat-name { font-weight: 700; }

/* シーズン検索: 左からレギュラー/セミファイナル/ファイナルの列を並べ、各列の中で
   チーム順位カードの下に個人順位カードを重ねる。セミファイナルが無いシーズンは
   その列自体をDOMから省くので、flexで詰めて隣り合わせになる。 */
.season-summary-columns { display: flex; flex-wrap: wrap; gap: 16px; align-items: start; }
.season-summary-col { flex: 1 1 320px; min-width: 280px; display: flex; flex-direction: column; gap: 16px; }
.season-summary-table { font-size: 1.08rem; }
.season-summary-table th, .season-summary-table td { padding: 6px 8px; }
.season-summary-table th:nth-child(1), .season-summary-table td:nth-child(1) { text-align: center; width: 2.2em; }
.season-summary-table th:nth-child(n+3), .season-summary-table td:nth-child(n+3) { text-align: right; width: 5em; }
.season-summary-table tr.seat-rank-1 td { background: rgba(255, 202, 40, 0.22); }
.season-summary-table tr.seat-rank-2 td { background: rgba(66, 165, 245, 0.18); }
.season-summary-table tr.seat-rank-3 td { background: rgba(240, 98, 146, 0.18); }
.season-summary-table .negative { color: #c4553f; }
.season-summary-table tr.season-summary-advance-cutoff td { border-bottom: 3px dashed #2f7de1; }
/* ファイナル・セミファイナルのチーム順位表は数値列が3つ（繰越pt/ポイント/合計
   ポイント）あるので、通常の5emだと少し窮屈になりがちな数値列だけ詰める
   （シーズン検索タブ自体はwide-mainで幅の上限を外しているので、これくらいの
   微調整で十分収まる。万一収まらない場合は親のtable-wrapがoverflow-x: autoなので
   カード内で横スクロールに逃げる）。 */
.final-team-table th:nth-child(n+3), .final-team-table td:nth-child(n+3) { width: 4em; }
.season-summary-name-cell { display: flex; align-items: center; gap: 5px; text-align: left; }
.season-summary-photo { width: 28px; height: 38px; border-radius: 5px; object-fit: cover; flex: none; }
.season-summary-search-row { display: flex; align-items: flex-end; gap: 8px; }
#season-summary-select { align-self: flex-start; width: auto; }
.team-roster-grid-title { margin: 24px 0 12px; }
.team-roster-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.team-roster-card { min-width: 0; }
.team-roster-card .season-summary-table th:nth-child(1), .team-roster-card .season-summary-table td:nth-child(1) { text-align: left; width: auto; }
.team-roster-card .season-summary-table th:nth-child(2), .team-roster-card .season-summary-table td:nth-child(2) { text-align: right; width: 5em; }
.team-roster-total td { font-weight: 700; border-top: 2px solid var(--border); }

/* チームロゴ（web/teams/配下）。テーブル内の行アイコンは小さく、カード見出しは
   少し大きめに。SVGは背景色に依存する塗りのものがあるため、白背景の丸チップに
   乗せてダークテーマでも視認できるようにする。 */
.team-logo { width: 34px; height: 34px; object-fit: contain; flex: none; vertical-align: middle; background: #fff; border-radius: 5px; padding: 3px; box-sizing: border-box; }
.team-logo-lg { width: 48px; height: 48px; border-radius: 8px; padding: 4px; margin-right: 4px; }
.team-roster-card-title { display: flex; align-items: center; gap: 8px; }

/* --- 対局入力タブ --- */
.entry-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
  align-items: end;
}
.entry-form-grid input, .entry-form-grid select { width: 100%; }
.entry-form-grid input[type=number] { width: 64px; }
/* ステージ・対局日・卓・試合は中身のサイズだけ使って左に詰める
   （grid の 1fr だと余白まで均等に広がってしまうため flex に切り替える）。 */
.entry-form-grid-narrow { display: flex; flex-wrap: wrap; align-items: end; gap: 20px; }
.entry-form-grid-narrow .inline-label,
.entry-form-grid-narrow .table-gameno-group { flex: none; }
#new-stage { width: 130px; }
#new-date { width: 150px; }
/* 「対局を検索」は検索ボタンの右にシーズン等の絞り込み欄を全部並べ、
   グリッドの1frで間延びさせず中身のサイズのまま左に詰める。 */
.search-header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.search-header .inline-label { font-size: 0.8rem; gap: 4px; }
#search-date-from, #search-date-to { width: 128px; }
#search-season { width: 100px; }
#search-stage { width: 110px; }
/* 卓と戦(半荘番号)を1グリッド枠の中で横並びにする */
.table-gameno-group { display: flex; gap: 16px; }
/* 起家〜北家の名前欄も、grid の 1fr で間延びしないよう flex で左に詰める */
.player-form-row { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; }
.player-form-row .inline-label { flex: none; }
.player-form-row .player-search-picker { width: 150px; }
/* 新規対局設定カードは対局パネル（2卓横並び）と違って全幅にする必要がないので、
   wide-main で幅上限を外していても、ここだけ元のコンパクトな幅に戻す */
.entry-setup-card { max-width: 900px; margin-bottom: 0; }
/* 新規対局設定と対局検索を横並びにして、空いた右側のスペースを使う */
.entry-top-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 18px; }
.entry-search-card { flex: 1; min-width: 320px; margin-bottom: 0; }

/* 対局が始まったら入力パネルだけに集中できるよう、「新規対局設定」「対局検索」を
   カードごと表示/非表示するトグルボタン。非表示中は目立たない見た目にする。
   両方隠すとこのバーだけが最上部に残るので、可能な限り薄くしてスペースを詰める */
.entry-toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.entry-toolbar button {
  margin-left: 0; padding: 4px 10px; font-size: 0.78rem;
}
.entry-toolbar button.card-hidden {
  background: var(--card-bg); color: var(--muted); border: 1px solid var(--border);
}
.entry-toolbar .auto-post-toggle {
  display: flex; align-items: center; gap: 6px; margin-left: auto;
  font-size: 0.8rem; color: var(--muted); flex-direction: row;
}

.dora-row { display: flex; align-items: end; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.dora-row input[type=number] { width: 56px; }

.player-picker { display: flex; gap: 6px; align-items: center; flex: 1; }
/* ラベルを入力枠の上ではなく左に並べる（ステージ・対局日・卓・戦・起家〜北家 共通） */
.inline-label { flex-direction: row; align-items: center; gap: 8px; white-space: nowrap; }
.small-btn {
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px; font-size: 0.75rem; margin: 0; cursor: pointer;
}
.small-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.simple-search-race-video-btn, .simple-search-race-video-preview-btn { margin-left: 4px; }

/* 局毎の動画開始位置を全局分入れ終えた試合は「詳細表示」を目立たせ、一覧上で
   入れ終わったかどうかが一目で分かるようにする。 */
.simple-search-detail-btn-timed {
  background: #2f7d4f; color: white; border-color: #2f7d4f;
}
/* 全局分の牌譜URL（アプリ内牌譜再生用）が揃っている場合は青にする
   （動画開始位置が全局分揃った緑より後に定義し、両方trueの時は青を
   優先させる）。 */
.simple-search-detail-btn-kifu {
  background: #2f5fa8; color: white; border-color: #2f5fa8;
}

/* 牌譜・ABEMAリンク（<a>に.small-btnを当てると下線が出てボタンと見た目が
   揃わないため、リンク固有の見た目だけここで上書きする）。 */
.link-btn { display: inline-block; text-decoration: none; }

.player-search-picker { position: relative; flex: 1; }
.player-search-picker input { width: 100%; }
.player-search-picker .player-search-input { padding-right: 22px; }
/* 名前欄の右上の赤×でその場でクリアできるようにする */
.player-clear-btn {
  position: absolute; top: -6px; right: -6px; z-index: 21;
  width: 18px; height: 18px; padding: 0; margin: 0; border-radius: 50%;
  background: #c4293a; color: white; border: none; font-size: 12px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.player-clear-btn:hover { background: #a3211f; }
.player-search-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px;
  margin-top: 2px; max-height: 220px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.player-search-item { padding: 6px 10px; font-size: 0.85rem; cursor: pointer; }
.player-search-item:hover { background: var(--accent-soft); }
.player-search-empty { padding: 6px 10px; font-size: 0.8rem; color: var(--muted); }

/* 顔写真の長押しで出す、その席だけの選手変更ポップアップ */
.player-change-popup {
  position: absolute; z-index: 500; background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); width: 220px;
}
.player-change-popup .player-search-input { width: 100%; }
.player-change-popup .player-search-results {
  position: static; border: none; box-shadow: none; margin-top: 4px; max-height: 260px;
}
.player-photo[data-seat] { cursor: pointer; touch-action: none; }

.tile-history-str { font-size: 0.72rem; }
.hand-remark { display: inline-block; font-size: 0.72rem; color: #b58a2e; }
/* 対局検索一覧: 結果（最終点数）だけ入力されていて局の詳細がまだの対局を目立たせる
   （局データが1つでもあれば通常表示、0件ならこのラベルが出る）。 */
.simple-search-score-only { color: #b58a2e; font-weight: 600; }
.simple-search-duration { margin-left: 6px; }
.frame-review-cached-badge {
  margin-left: 6px; font-size: 0.75rem; color: #2f7d4f; border: 1px solid #2f7d4f;
  border-radius: 4px; padding: 1px 5px;
}

/* ドラ牌の見た目（Unicode麻雀牌グリフはWindows標準フォントでほぼ表示されないため
   画像/絵文字を使わず、数字＋スート漢字を牌っぽくCSSだけで組む） */
.tile-face {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.05; font-weight: 700;
}
.tile-face .tile-num { font-size: 1.05em; }
.tile-face .tile-suit { font-size: 0.62em; margin-top: 1px; }
.tile-face .tile-honor { font-size: 1.05em; }
.tile-face .tile-unknown { font-size: 1.15em; }

/* 実写アイコン（web/dora_icons/<code>.png）をCSS牌の上に重ねておき、画像が無い
   （404）種類だけ img側のonerrorで消してCSS牌を見せるための入れ物。ボタン等
   親要素いっぱいに広げたい場面ごとに .tile-face-wrap へ幅/高さを指定する。 */
.tile-face-wrap { position: relative; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; box-sizing: border-box; }
.tile-face-photo {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; box-sizing: border-box;
  object-fit: cover; object-position: 50% 35%; border-radius: 4px;
}
.yaku-picker { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.yaku-group { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
/* ドラ/赤/裏ドラのカウンターと「状況」（ハイテイ等）を同じ行にまとめ、
   点数選択欄までスクロール無しで収まるよう行数を減らす。 */
.yaku-group-row { display: flex; flex-wrap: wrap; gap: 4px 24px; align-items: center; }
.yaku-group-label {
  font-size: 0.72rem; color: var(--muted); min-width: 42px; font-weight: 600;
}
.toggle-btn-gap { display: inline-block; width: 12px; }
.toggle-btn-break { flex-basis: 100%; height: 0; }

.riichi-stick-icon { height: 14px; width: auto; vertical-align: -2px; margin-right: 2px; }

.seat-picker-block { margin: 10px 0; }
.seat-picker-block > label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.seat-toggle-group { display: flex; gap: 8px; flex-wrap: wrap; }
.seat-toggle-btn {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; font-size: 0.85rem; cursor: pointer; margin: 0;
  line-height: 1.4; text-align: center; min-width: 84px;
}
.seat-toggle-btn:hover { border-color: var(--accent); }
/* リーチ・テンパイのトグルボタンも独立した見た目にする */
.seat-toggle-btn.selected { background: #2e7dd1; color: white; border-color: #2e7dd1; font-weight: 600; }
/* リーチは宣言の重みを出すため赤系にする（局の履歴編集のリーチ修正トグルも同じ色に揃える） */
.seat-toggle-btn.riichi-live-btn.selected,
.seat-toggle-btn.hand-edit-riichi-btn.selected { background: #c4293a; border-color: #c4293a; }
/* リーチ/面前・ツモ/ロンは横並びにして、1人分をコンパクトな2ボタン幅に収める */
.seat-row-h { display: flex; gap: 4px; }
.seat-row-h .seat-toggle-btn { min-width: 64px; padding: 6px 8px; font-size: 0.78rem; }
.agari-btn-row { min-height: 34px; }
.agari-tsumo-btn, .agari-ron-btn, .tenpai-select-btn {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px; font-size: 0.78rem; cursor: pointer; margin: 0;
  line-height: 1.4; text-align: center; min-width: 64px;
}
.agari-tsumo-btn:hover, .agari-ron-btn:hover, .tenpai-select-btn:hover { border-color: var(--accent); }
.agari-tsumo-btn:disabled, .agari-ron-btn:disabled { opacity: 0.35; cursor: not-allowed; }
/* stat-tile の背景色（--bg）とボタンの初期背景色が同じで見分けにくいため、
   得点タイルの中にあるときだけボタン背景をカード色に変えて浮き上がらせる */
.stat-tile .seat-toggle-btn:not(.selected),
.stat-tile .agari-tsumo-btn:not(.selected),
.stat-tile .agari-ron-btn:not(.selected):not(.houjuu-btn),
.stat-tile .tenpai-select-btn:not(.selected) {
  background: var(--card-bg); border-color: var(--muted);
}
/* 和了確定（ツモ、またはロンの和了者本人）は和了を表す緑系 */
.agari-tsumo-btn.selected, .agari-ron-btn.selected:not(.houjuu-btn) {
  background: #2e9e5b; color: white; border-color: #2e9e5b; font-weight: 600;
}
/* 放銃候補（誰が放銃したか未確定）は薄い赤、確定すると濃い赤に変わる */
.agari-ron-btn.houjuu-btn { background: #f2b6ac; color: #6b1c12; border-color: #f2b6ac; }
.agari-ron-btn.houjuu-btn.selected { background: #b7291b; color: white; border-color: #b7291b; font-weight: 600; }
/* テンパイ/ノーテンは流局用の選択。テンパイ=緑系、ノーテン=グレー系で区別する */
.tenpai-select-btn.tenpai-btn.selected { background: #2e9e5b; color: white; border-color: #2e9e5b; font-weight: 600; }
.tenpai-select-btn.noten-btn.selected { background: #6b7280; color: white; border-color: #6b7280; font-weight: 600; }
/* 確定ボタンは他の操作ボタンと見分けやすいよう緑系にする */
.submit-hand-btn { background: #1f8a4c; font-weight: 600; }
/* 不備なく押せる状態になったことがリアルタイムで分かるよう、文字を赤くする */
.submit-hand-btn.ready { color: #ff5252; }
/* 半荘終了は他の青系ボタン（前局確定前へ・前局取消等）と被らないよう琥珀系にする */
.finish-btn { background: #c9821f; font-weight: 600; }

/* 役ボタン（ON/OFF）: 数が多いのでコンパクトに */
.toggle-btn {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 14px; padding: 4px 10px; font-size: 0.75rem; cursor: pointer; margin: 0;
}
.toggle-btn:hover { border-color: var(--accent); }
.toggle-btn.selected { background: var(--accent); color: white; border-color: var(--accent); font-weight: 600; }

/* 面前/鳴き切り替えボタン */
.menzen-toggle-btn {
  background: var(--accent); color: white; border: 1px solid var(--accent);
  border-radius: 8px; padding: 8px 14px; font-size: 0.85rem; cursor: pointer; margin: 0; min-width: 84px;
}
.menzen-toggle-btn.naki { background: #b7401b; border-color: #b7401b; }

/* ドラ/赤/裏ドラ: 押すたびにカウントアップするボタン */
.counter-btn {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; font-size: 0.85rem; cursor: pointer; margin: 0; min-width: 64px;
}
.counter-btn:hover { border-color: #9b59d0; }
.counter-btn.selected { background: #7a3fc2; color: white; border-color: #7a3fc2; font-weight: 600; }
/* 役ボタンと並べる時は役ボタンと同じ大きさに揃える */
.counter-btn.toggle-size {
  border-radius: 14px; padding: 4px 10px; font-size: 0.75rem; min-width: unset;
}

/* 2卓同時入力: 対局パネルを横並びで複数表示 */
.entry-panels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
  align-items: start;
}
.entry-panel .card h2 { font-size: 0.98rem; }
.entry-panel .card h3 { font-size: 0.92rem; margin: 0 0 10px; }

/* 「閉じる」「対局削除」等の頻繁に押さない操作をまとめる行。以前は見出し（h2）内に
   float:rightで置いていて、(1) ドラ選択のすぐ近くにあって誤押ししやすい、
   (2) 見出しの文字数が卓によって変わると2卓同時表示時にボタンの折り返し位置がずれ、
   パネル同士の選手カードの縦位置が揃わなくなる、という2つの問題があったため、
   通常の操作ボタン列とは別に、間隔を空けた小さいボタンの行として切り出した。 */
.panel-admin-row { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

/* 点数早見表（子/親・ツモ/ロンで自動切替） */
.score-table-wrap { margin: 10px 0 14px; }
.score-table { width: auto; }
.score-table th, .score-table td { padding: 2px 3px; text-align: center; border: none; }
.score-table thead th { font-size: 0.68rem; color: var(--muted); font-weight: 500; }
.score-table tbody th { font-size: 0.75rem; color: var(--muted); text-align: right; padding-right: 6px; }
.score-table-gap { width: 28px; padding: 0 !important; }
.score-cell {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 6px; font-size: 0.72rem; cursor: pointer; margin: 0; white-space: nowrap;
}
.score-cell:hover { border-color: var(--accent); }
.score-cell.selected { background: var(--accent); color: white; border-color: var(--accent); }
/* 役の選択から満貫以上・ピンフ/七対子が自動判定できた場合は符×翻の早見表を隠す
   （点数は win-points 欄に直接表示されるのでこれで十分）。 */
.score-table-wrap.auto-mode .score-table { display: none; }

/* 役を選んだのに（4翻以下等で）点数がまだ自動/手動どちらでも確定していない間、
   点数指定エリアをうっすら色付けして「このまま確定すると翻数エラーになる」ことに
   気付けるようにする。点数が決まれば自動で消える。 */
.score-table-container.score-unconfirmed {
  background: rgba(201, 130, 31, 0.16);
  border-radius: 8px;
  padding: 6px;
}

/* マスタ編集タブ */
.master-table input[type=text] { width: 100%; min-width: 90px; }
.master-table td, .master-table th { text-align: left; }
.master-table .m-save-status { margin-left: 6px; }
#master-player-filter { width: 260px; }
.m-announcer-drag-handle { cursor: grab; color: var(--muted); text-align: center; width: 1.5em; user-select: none; }
.m-announcer-row-dragging { opacity: 0.4; }
.m-announcer-row-dragging .m-announcer-drag-handle { cursor: grabbing; }
.tenure-summary { max-width: 280px; }
.team-editor-row td { background: var(--bg); padding: 12px; }
.team-tenure-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.team-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent-soft); border-radius: 12px; padding: 3px 8px; font-size: 0.78rem;
}
.team-chip-remove {
  background: none; border: none; color: var(--muted); cursor: pointer; margin: 0; padding: 0 2px; font-size: 0.85rem;
}
.team-chip-remove:hover { color: #c4553f; }
.team-add-row { display: flex; gap: 6px; align-items: center; margin-left: 8px; }

/* 「この局を確定」直後に自動生成される結果カード画像のプレビュー */
.result-card-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(10, 12, 16, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
/* 縦長の生成画像（ゲーム開始カード等）だと、以前はモーダル自体が画面の高さを
   超えて伸び、下の「画像を保存」「閉じる」が画面外に隠れてしまっていた
   （右クリック保存・モーダル外クリックで閉じる、という回避策が必要だった）。
   画像部分だけをスクロール領域にし、操作ボタンは常に見える位置に固定する。 */
.result-card-modal {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px;
  max-width: min(900px, 92vw); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column; overflow: hidden;
}
.result-card-scroll { overflow-y: auto; padding: 16px 16px 0; }
.result-card-preview { width: 100%; height: auto; border-radius: 10px; display: block; }
.result-card-actions {
  display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.result-card-save {
  background: #1f8a4c; color: white; border: none; border-radius: 6px;
  padding: 8px 16px; font-size: 0.9rem; text-decoration: none; font-weight: 600;
}
.result-card-close { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

/* 旧フォーマット（Excelテンプレート切り抜き）画像プレビュー。3枚まとめて縦に並べて
   見せる（サイズがバラバラ＝チーム成績抜粋は小さく、詳細は横長なので、1枚ずつの
   result-card-modalとは別に、スクロールできる縦積みレイアウトにしている）。
   以前はモーダル全体をスクロールしていたため、下までスクロールすると見出しの
   「閉じる」が画面外に出てしまっていた。見出しは固定し、画像部分だけを
   スクロール領域にする。 */
.legacy-xlsx-modal {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px;
  max-width: min(1000px, 92vw); max-height: min(90vh, calc(100vh - 48px));
  display: flex; flex-direction: column; overflow: hidden;
}
.legacy-xlsx-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-shrink: 0; padding: 16px 16px 14px; border-bottom: 1px solid var(--border);
}
.legacy-xlsx-header h3 { margin: 0; }
.legacy-xlsx-body { display: flex; flex-direction: column; gap: 20px; overflow-y: auto; padding: 14px 16px 16px; }
.legacy-xlsx-item { display: flex; flex-direction: column; gap: 8px; }
.legacy-xlsx-item h4 { margin: 0; color: var(--muted, #888); font-size: 0.9rem; }
.legacy-xlsx-preview {
  width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--border);
  background: #ffffff;
}

/* 「局の履歴」の動画一括取得（フレームレビュー）: 動画左上の局表示を1秒ごとに
   切り出したコマをパラパラ漫画のように1コマずつ表示し、マウスホイール/矢印キーで
   前後させながら、表示が変わった瞬間でクリック確定→上から順に局へ割り当てる。
   OCRでの自動判定は放送のワイプ演出等で精度が出なかったため、この半自動方式にした。 */
.frame-review-overlay {
  position: fixed; inset: 0; z-index: 1200;
  background: rgba(10, 12, 16, 0.78);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.frame-review-box {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px;
  max-width: min(720px, 94vw); max-height: calc(100vh - 40px);
  display: flex; flex-direction: column; overflow: hidden;
}
.frame-review-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.frame-review-current-hand {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  font-size: 3.15rem; font-weight: 700; text-align: center; padding: 8px 16px 0; flex-shrink: 0;
}
/* ドラ牌表示は局表示と同じ目線で比べられれば十分なので、文字そのものは
   局表示より一回り小さく、牌らしく枠で囲って並べる。実機のテロップと見た目を
   揃えるため、0.75倍に縮小している。 */
.frame-review-current-hand-dora { display: flex; gap: 8px; }
.frame-review-current-hand-dora:empty { display: none; }
.frame-review-current-hand-dora .tile-face {
  width: 3.375rem; height: 4.275rem; font-size: 3.375rem; line-height: 1;
  border: 2px solid var(--muted); border-radius: 6px; background: var(--card-bg);
}
.frame-review-current-hand-dora .tile-face-wrap { width: 3.375rem; height: 4.275rem; }
.frame-review-current-hand-dora .tile-face-photo {
  border-radius: 6px; border: 2px solid var(--muted);
}
/* 実機テロップ（供託リーチ棒の本数が上段、本場数が下段）と同じ並びを再現。 */
.frame-review-current-hand-counters {
  display: flex; flex-direction: column; gap: 4px; font-size: 1.3rem; font-weight: 700;
}
.fr-counter-row { display: flex; align-items: center; gap: 6px; }
.fr-counter-icon { height: 1.3rem; width: auto; }
.frame-review-next { font-size: 0.95rem; }
.frame-review-next b { color: #2f7d4f; }
.frame-review-time { font-variant-numeric: tabular-nums; color: var(--muted); }
.frame-review-viewport-wrap { padding: 14px 16px 0; display: flex; justify-content: center; align-items: center; gap: 10px; flex-shrink: 0; }
.frame-review-viewport {
  border: 2px solid var(--border); border-radius: 6px; background-color: #000;
  background-repeat: no-repeat; cursor: pointer; image-rendering: pixelated;
}
.frame-review-viewport.fr-flash { border-color: #2f7d4f; }
.frame-review-dora-nav { display: flex; flex-direction: column; gap: 8px; }
.frame-review-dora-row { display: flex; gap: 8px; }
.frame-review-dora-nav .fr-dora-btn { padding: 15px 8px; }
.frame-review-left-nav { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.frame-review-ryuukyoku-flag { font-size: 1.3rem; font-weight: bold; color: #b33; }
.frame-review-controls {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; flex-shrink: 0;
}
.frame-review-confirm { background: #2f7d4f; color: white; border: none; }
.frame-review-hint { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 0 16px; flex-shrink: 0; }
.frame-review-list {
  overflow-y: auto; padding: 10px 16px 16px; border-top: 1px solid var(--border); margin-top: 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.frame-review-list-item {
  display: flex; justify-content: space-between; gap: 10px; padding: 3px 6px; border-radius: 4px;
  cursor: pointer; font-size: 0.85rem;
}
.frame-review-list-item:hover { background: var(--bg); }
.frame-review-list-item.fr-current { background: rgba(47, 125, 79, 0.15); font-weight: 600; }
.frame-review-list-item.fr-done { color: var(--muted); }
.frame-review-list-item .fr-time { font-variant-numeric: tabular-nums; }

/* アプリ内の牌譜ビューアー（卓ビュー再生）。4人の手牌・捨て牌・鳴きを卓の形に
   並べ、1手ずつ進める。座席の配置は実際の卓と同じ時計回り（自分=下、下家=右、
   対面=上、上家=左）で固定し、局ごとに変わる親の位置はラベルの風だけで表す。 */
.kifu-player-overlay {
  position: fixed; inset: 0; z-index: 1200;
  background: rgba(10, 12, 16, 0.78);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.kifu-player-box {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px;
  /* 卓は正方形で高さ基準で拡大率が決まるため、横幅を画面いっぱい(98vw)に
     固定すると、卓と右側パネル（固定幅）の右に大きな未使用の白い余白が
     残ってしまう。横幅は中身（卓の実サイズ＋右側パネル）に合わせて
     自動で詰める（widthはJS側のfitTableZoomで都度設定するので、ここは
     上限だけ決めておく）。 */
  width: fit-content; max-width: 98vw; height: calc(100vh - 24px);
  display: flex; flex-direction: column; overflow: hidden;
  /* クリックで牌譜を送る操作中に、牌（テキスト・画像）がドラッグ選択で
     青く反転したり、画像のネイティブドラッグが始まったりしないように
     する（ドラッグ中にマウスを離してもmousedownしっぱなし扱いのように
     見えるバグの原因にもなっていた）。 */
  user-select: none; -webkit-user-select: none;
}
.kifu-player-box img { -webkit-user-drag: none; user-drag: none; }
.kifu-player-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.kifu-player-header h3 { margin: 0; }
/* 1試合を通して見られるよう、ヘッダーに前の局・次の局へのボタンを置く。 */
.kifu-player-hand-nav {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  flex-shrink: 0; flex-wrap: wrap;
}
/* ドラ表示は中央の点数パネルの中に移した。操作ボタン・結果表示は卓の
   右側に出すスペースができたので、本体を卓＋右側パネルの横並びにする。 */
/* align-items/justify-contentをcenterにすると、卓が領域より大きいときに
   はみ出した分（特に開始側）がスクロールしても見えなくなるFlexboxの
   既知の挙動がある（西家の手牌が隠れていたのはこれが原因）ため、
   centerは使わずflex-startのままにする（卓は左詰め、右側には今後の
   操作機能のためのスペースを広く残す）。 */
.kifu-player-body {
  flex: 1; min-height: 0; display: flex; align-items: flex-start; justify-content: flex-start;
  gap: 16px; padding: 10px; overflow: auto;
}
.kifu-player-dora {
  display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 4px;
}
.kifu-player-dora-tiles { display: flex; gap: 2px; }
/* 手牌・捨て牌・鳴き牌と同じ大きさにする。 */
.kifu-player-dora-tiles .kifu-tile .tile-face, .kifu-player-dora-tiles .kifu-tile .tile-face-wrap {
  width: 2.3rem; height: 2.9rem; font-size: 2.1rem;
}
/* カンドラ表示牌はまだカンが入っていない間、空き枠として場所だけ確保して
   おく（カンが入るたびに実際の牌に差し替わっても表示エリアの幅が
   変わらないように）。中身が分からない牌という扱いで、手牌ONの黄色塗りと
   同じ見た目（牌の形はそのまま、中身だけ黄色で伏せる）にする。 */
.kifu-tile-dora-empty {
  display: inline-block; width: 2.3rem; height: 2.9rem; box-sizing: border-box;
  border: 1px solid #333; border-radius: 3px; background: var(--tile-back, #f4d35e);
}
.kifu-player-side {
  /* 残りスペースを埋め尽くす(flex:1)のではなく、操作機能を置くのに
     十分な固定幅だけ確保する。箱全体の横幅はfit-contentなので、これより
     右に余計な白い余白は残らない。 */
  flex: 0 0 360px; width: 360px; min-width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
/* 本家の卓ビュー（緑のフェルト＋中央の得点パネル）に見た目を寄せる。
   東家（手牌が外側＝下、捨て牌がその内側＝中央パネル側、鳴きは手牌の
   右）の並びを基準の「ブロック」とし、南家はブロック全体を反時計回りに
   90度、西家は180度、北家は時計回りに90度回転させて配置する
   （本家ビューアーと同じ考え方。並び順はどの席も共通で、回転だけで
   向きを変える）。 */
.kifu-player-table {
  position: relative;
  display: grid;
  /* 各家の表示は90度ずつ回転しただけの同じブロックなので、上下左右で
     完全に対称。よって卓全体も正方形になるはずで、縦横で別々の値を
     使うのをやめ、同じ2つの変数（ブロックの長辺・短辺）だけで
     行と列の両方を組み立てる。
     ・長辺（--kifu-block-main）：手牌＋鳴きの横幅。東家・西家ではそのまま
       列の幅、南家・北家では回転するので行の高さとして使う。
     （CSSのtransformはレイアウト計算に影響しないため、回転後に必要な
       サイズは自動計算されず、ここで明示的に指定する必要がある。）
     ・短辺（--kifu-block-cross）：捨て牌＋手牌行の縦幅（名前ラベルぶんの
       余白込み）。東家・西家ではそのまま行の高さ、南家・北家では列の幅。 */
  /* 鳴きは手牌の空きスペースに重ねて表示するが、チー・ポン・大明槓は
     「鳴き3〜4枚」に対して手牌から抜けるのは2〜3枚だけなので、鳴き1つに
     つき実質1枚ぶんずつ幅が足りなくなる。最大4つ鳴く場合でも自摸牌と
     重ならないよう、余裕を4枚ぶん確保しておく。 */
  --kifu-block-main: calc(14 * 2.3rem + 6px + 4 * 2.3rem);
  /* 捨て牌（3段）と手牌の間は牌1枚ぶん（2.9rem）空ける。 */
  --kifu-block-cross: calc(3 * 2.9rem + 2.9rem + 2.9rem);
  /* 中央の行・列は中央パネル（220px）に合わせた小さい固定サイズにする。
     東家・西家・南家・北家の各ブロックは手牌＋鳴きぶん（--kifu-block-main、
     現状の中央の行・列より大きい）必要だが、その分は position:absolute に
     して行・列のサイズ計算から外し、卓全体（3行/3列ぶんの高さ・幅）を
     使って中央寄せする。こうすることで、中央の行・列を無駄に広げずに
     済み、捨て牌が中央パネルのすぐ外側にくっつくようになる。 */
  /* 中央パネルの横幅は必ず捨て牌6枚ぶん（calc(6 * 2.3rem)）と面一にする。 */
  --kifu-center-size: calc(6 * 2.3rem);
  grid-template-columns: var(--kifu-block-cross) var(--kifu-center-size) var(--kifu-block-cross);
  grid-template-rows: var(--kifu-block-cross) var(--kifu-center-size) var(--kifu-block-cross);
  grid-template-areas:
    ".          seat-top    .          "
    "seat-left  center      seat-right "
    ".          seat-bottom .          ";
  gap: 6px; margin: 0; padding: 14px;
  /* 正方形になるよう、親(.kifu-player-box)の横幅いっぱいに
     ストレッチさせず、グリッドが必要とする自然なサイズのままにする。
     ドラ表示・操作ボタンを外に出して空いたスペースを使い、卓全体を
     大きく表示する（拡大率は画面サイズに合わせてJS側で動的に設定する。
     固定値だと画面が小さい環境で下側が見切れてしまうため）。左詰めにし、
     右側には今後操作機能を追加するスペースを広めに残す（margin:autoに
     よる中央寄せはしない）。 */
  width: fit-content; flex-shrink: 0;
  background: radial-gradient(ellipse at center, #2a6b4a 0%, #1f5338 75%, #184229 100%);
  border: 6px solid #3b2318; border-radius: 16px;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.45);
  overflow: auto;
}
.kifu-player-seat { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
/* position:absolute + 3行/3列ぶんのgrid-row/grid-columnで、サイズ計算には
   影響させず卓全体の中で中央寄せする。幅・高さは内容（回転前のサイズ）に
   頼らず明示的に指定する（頼ると、回転前の長辺ぶんそのまま箱が広がって
   隣の列・行にはみ出してしまうため）。 */
.kifu-player-seat-top, .kifu-player-seat-bottom {
  position: absolute; grid-column: 1 / 4;
  width: var(--kifu-block-main); height: var(--kifu-block-cross);
  left: 50%; margin-left: calc(var(--kifu-block-main) / -2);
  display: flex; justify-content: center; align-items: center;
}
/* grid-row/columnは終了線も明示する（「3」だけだと終了側がautoになり、
   position:absoluteの包含ブロックがグリッド線ではなくグリッド全体の
   パディングエッジまで広がってしまう＝bottom:0/right:0がそのパディング
   ぶん（14px）余計に離れた位置になり、上家・左家側とだけ隙間が
   揃わなくなるため）。 */
.kifu-player-seat-top { grid-row: 1 / 2; top: 0; }
.kifu-player-seat-bottom { grid-row: 3 / 4; bottom: 0; }
.kifu-player-seat-left, .kifu-player-seat-right {
  position: absolute; grid-row: 1 / 4;
  width: var(--kifu-block-cross); height: var(--kifu-block-main);
  top: 50%; margin-top: calc(var(--kifu-block-main) / -2);
  display: flex; justify-content: center; align-items: center;
}
.kifu-player-seat-left { grid-column: 1 / 2; left: 0; }
.kifu-player-seat-right { grid-column: 3 / 4; right: 0; }
/* 選手名は手牌の左端の真上（鳴きエフェクトと同じ、捨て牌と手牌の間の
   余白の行）に表示する。.kifu-player-seat-content の中に置くことで、
   ブロック全体の回転（南家90度・西家180度・北家-90度）に牌と同じように
   そのまま従う。 */
.kifu-player-seat-name {
  position: absolute; left: calc(2 * 2.3rem); bottom: calc(2.9rem + 6px);
  color: #e8ead8; font-size: 1.275rem; font-weight: 700; white-space: nowrap;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; gap: 4px;
}
.kifu-player-seat-team-logo {
  width: 1.3em; height: 1.3em; object-fit: contain; flex: none;
  background: #fff; border-radius: 4px; padding: 1px; box-sizing: border-box;
}
/* 「東家ブロック」本体。手牌・鳴き・捨て牌はお互いに依存しない絶対位置に
   し、ブロック自体のサイズも実際の枚数に関係なく常に同じ固定サイズに
   する。そうしないと（a）鳴きの有無で手牌の幅が変わるたびに手牌自体や
   捨て牌の位置がズレる、（b）対面（東家⇔西家、南家⇔北家）同士で手牌の
   内容量が違うと回転の基準点がズレて捨て牌が左右で揃わない、（c）回転後
   の高さが内容量次第で不定になり卓の外にはみ出す、といった問題が起きる。
   幅・高さを固定した箱の中で、手牌は左端、捨て牌は水平中央に固定し、
   鳴きは手牌の後ろに続く（箱からはみ出す場合はそのまま見た目だけ超過
   させる＝滅多に起きない極端な鳴き数の場合のみ）。 */
.kifu-player-seat-content {
  position: relative;
  width: var(--kifu-block-main);
  height: var(--kifu-block-cross);
}
.kifu-player-handrow {
  /* 鳴き用に広げたブロック左側の余白を少し手牌側にも分け、左隣（回転で
     隣接する別の家）のブロックと手牌が重ならないようにする。 */
  position: absolute; left: calc(2 * 2.3rem); bottom: 0;
}
/* 手牌は配牌13枚＋自摸牌1枚ぶん（常に14枚分）の幅を常に確保しておく。
   実際の枚数（鳴きで減る、自摸前は13枚など）で幅が変わると、中身は
   左端固定でも手牌全体・鳴きの位置がズレて見えてしまうため、実際の枚数に
   関係なく常に同じ幅・同じ左端を維持する。 */
.kifu-player-hand {
  display: flex; flex-wrap: nowrap; justify-content: flex-start;
  min-width: calc(14 * 2.3rem + 6px);
}
/* 鳴きは手牌14枚固定グリッドの右端に固定し、自摸（手牌が一時的に14枚に
   増える）のたびに位置がぴょこぴょこ動かないようにする（実際の手牌の
   枚数ぶんの位置に重ねると、自摸るたびその枚数が変わって鳴き牌まで
   動いてしまうため）。row-reverseにして、最初に鳴いた牌が右端、次に
   鳴いた牌はその左、という順番にする。
   .kifu-player-handrow（手牌14枚ぶんの幅しかない）の中ではなく、
   ブロック全体（--kifu-block-mainぶんの幅があり、鳴き用の余白もここに
   含まれる）の右端を基準にする。手牌側の右端を基準にすると、鳴きが
   2つ以上になった時にその余白へ出られず、実際の手牌（自摸牌）と
   重なってしまうため。 */
.kifu-player-melds {
  position: absolute; bottom: 0; right: 0;
  display: flex; flex-direction: row-reverse; flex-wrap: nowrap;
}
/* 捨て牌は0枚でも6×3のスペースを最初から確保し、左上から1枚ずつ埋めて
   いく。箱の水平中央に固定で置く（手牌の幅に一切左右されない）ことで、
   対面同士（東家⇔西家、南家⇔北家）の捨て牌が常に同じ横位置で揃う。
   リーチ宣言牌（横向きで幅が広がる）の分だけその行の後続の牌をJS側で
   右へずらすため、CSS Gridではなく各牌をposition:absoluteで配置する
   （Gridの列幅を広げる方式だと、同じ列の他の行にまで余白が及んで
   隣の牌とズレて被って見えてしまうため）。 */
.kifu-player-river {
  position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  width: calc(6 * 2.3rem); height: calc(3 * 2.9rem);
}
.kifu-player-river .kifu-tile { position: absolute; }
/* リーチ宣言牌は中の.tile-face-wrapだけがさらに90度回転するため、
   見た目の縦横比が他の牌と入れ替わる（2.3×2.9→2.9×2.3）。外側の
   .kifu-tileはサイズ無指定（中身に合わせて自動）のままだと、回転前の
   2.3×2.9のまま扱われてしまい、実際に見えている2.9×2.3の内容を
   囲いきれず、隣の牌側へわずかにはみ出して見える。外側も同じ比率に
   して余った分はoverflow:hiddenで切り、はみ出さないようにする。 */
.kifu-player-river .kifu-tile-riichi {
  width: 2.9rem; height: 2.3rem; overflow: hidden;
  /* 中の.tile-face-wrap（2.3×2.9のまま、回転だけ90度）は幅・高さの比率が
     外側（2.9×2.3）と逆なので、通常の配置（左上基準）のままだと回転の
     中心が外側の中心とズレて片側にはみ出す。中央寄せして回転の中心を
     揃える。 */
  display: flex; align-items: center; justify-content: center;
}
.kifu-player-melds:empty, .kifu-player-river:empty { min-height: 0; }
/* 鳴いた直後の1手だけ、鳴いた側のブロックの横位置中央に「ポン」等を
   一瞬表示する（1手進めるとまた空に戻る）。向きは牌と同じ扱いにし、
   打ち消さずブロックの回転（南家90度・西家180度・北家270度）に
   そのまま従わせる。 */
.kifu-player-call-banner {
  position: absolute; left: 50%; bottom: calc(2.9rem + 6px); transform: translateX(-50%);
  color: #fff; font-weight: 800; font-size: 4rem; white-space: nowrap;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.75), 0 0 16px rgba(0, 0, 0, 0.5);
  pointer-events: none; z-index: 5;
}
.kifu-player-call-banner:empty { display: none; }
/* ブロック全体を東家基準で回転する。南家は反時計回りに90度、西家は180度、
   北家は時計回りに90度。箱のサイズが固定なので、回転の基準点（中心）も
   内容量に関係なく常に同じになり、対面同士の位置がきちんと揃う。 */
.kifu-player-seat-top .kifu-player-seat-content { transform: rotate(180deg); }
.kifu-player-seat-right .kifu-player-seat-content { transform: rotate(-90deg); }
.kifu-player-seat-left .kifu-player-seat-content { transform: rotate(90deg); }
.kifu-tile .tile-face, .kifu-meld .tile-face {
  width: 1.9rem; height: 2.4rem; font-size: 1.7rem; line-height: 1;
  border: 1px solid #333; border-radius: 3px; background: #faf6ec;
  /* 実写画像は牌の縁取りごと描かれているので、下に重ねた文字版は
     画像が読み込めた時は完全に隠す（読み込み失敗時のみ、img側の
     onerrorでvisibility:visibleに戻してフォールバック表示にする）。 */
  visibility: hidden;
}
.kifu-tile .tile-face-wrap, .kifu-meld .tile-face-wrap { width: 1.9rem; height: 2.4rem; }
/* 手牌・捨て牌・鳴き牌は同じ大きさで表示する。 */
.kifu-player-hand .kifu-tile .tile-face, .kifu-player-hand .kifu-tile .tile-face-wrap,
.kifu-player-river .kifu-tile .tile-face, .kifu-player-river .kifu-tile .tile-face-wrap,
.kifu-player-melds .kifu-tile .tile-face, .kifu-player-melds .kifu-tile .tile-face-wrap {
  width: 2.3rem; height: 2.9rem; font-size: 2.1rem;
}
/* 牌譜再生用の実写画像（web/kifu_tiles/）は素材自体が横向きなので、
   縦横を入れ替えたサイズで中央に置いてから90度回転し正立させる
   （先に正立サイズのまま切り抜くと、横長の絵柄が余計に欠けてしまう
   ため）。鳴き・立直で牌自体を横向きに見せたい場合は、外側の
   .tile-face-wrap側に90度回転がかかり、ここでの90度と打ち消し合って
   素材そのまま（横向き）の見た目になる。 */
.kifu-tile .tile-face-photo, .kifu-meld .tile-face-photo {
  width: 2.4rem; height: 1.9rem; top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  /* containだと素材自体の縦横比のせいで枠内に隙間ができ、隣の牌との間に
     卓の緑が見えてしまう。下地はもう常に隠しているので、fillで枠いっぱいに
     伸ばして隙間なく隣接させる。 */
  object-fit: fill;
}
.kifu-player-hand .kifu-tile .tile-face-photo, .kifu-player-hand .kifu-meld .tile-face-photo,
.kifu-player-river .kifu-tile .tile-face-photo, .kifu-player-river .kifu-meld .tile-face-photo,
.kifu-player-melds .kifu-tile .tile-face-photo, .kifu-player-melds .kifu-meld .tile-face-photo,
.kifu-player-dora-tiles .kifu-tile .tile-face-photo {
  width: 2.9rem; height: 2.3rem;
}
.kifu-tile-drawn { margin-left: 6px; }
/* 横向きにすると幅が高さぶん（2.9rem）に広がる。牌を縮小するのではなく、
   その牌が属する列のグリッド幅自体をJS側（render内）で2.9remに広げて
   対応するため、ここでは回転だけ行う。 */
/* 回転だけだと中心基準で上下に均等な隙間ができ、上の行の牌と近づいて
   被って見えることがあるため、鳴き牌の横向き表示と同様に下端を揃える。 */
/* 外側(.kifu-tile-riichi)を中央寄せにしたので、ここでの回転は中心基準の
   ままでよい（translateYでずらすと中央寄せとズレて逆に片側へはみ出す）。 */
.kifu-tile-riichi .tile-face-wrap, .kifu-tile-riichi .tile-face { transform: rotate(90deg); }
/* 鳴き牌のうち相手から取った1枚は横向きにし、鳴いた相手の方角を示す
   （チーは常に上家なので先頭、ポン・槓は上家/対面/下家の位置に応じる）。 */
/* 横向きにすると中の.tile-face-wrapの見た目は2.3×2.9→2.9×2.3に入れ替わる。
   外側(.kifu-tile-called)は無指定だと回転前の2.3×2.9のまま扱われ、実際の
   見た目（2.9×2.3）とズレて片側にはみ出したり、逆に上下どちらかに
   隙間ができたりする（translateYでの補正は西家など180度回転した家では
   上下が逆転し、狙った側と逆に隙間ができてしまう）。外側も見た目どおりの
   比率にし、中央寄せで回転の中心を一致させることで、どの家でもズレなく
   隣に詰めて表示できるようにする。 */
.kifu-tile-called {
  width: 2.9rem; height: 2.3rem; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  /* .kifu-meld（flex）は他の牌（高さ2.9rem）に対して、この牌だけ高さが
     2.3remと低いため、align-items:stretchが効かずデフォルトで上揃え
     （_||ではなく''''||）になってしまう。下揃えにする。 */
  align-self: flex-end;
}
.kifu-tile-called .tile-face-wrap, .kifu-tile-called .tile-face {
  transform: rotate(90deg);
}
/* 1人で複数鳴いた場合、ブロック同士の間にスペースは入れずくっつける
   （余白があると、鳴き牌が占める分だけ手牌・自摸牌側が窮屈になり、
   自摸牌が左隣の鳴き牌と被ってしまうため）。 */
.kifu-meld { display: inline-flex; padding: 2px; border: 1px solid transparent; border-radius: 6px; }
/* 暗カン：牌の裏面画像が無いので、両脇2枚を黒塗りの牌で代用する。 */
.kifu-meld .kifu-tile-back {
  display: inline-block; width: 2.3rem; height: 2.9rem; box-sizing: border-box;
  background: var(--tile-back, #f4d35e); border: 1px solid #333; border-radius: 3px; vertical-align: top;
}
/* 加カン：ポンで横になった牌の上に、自分で引いた4枚目を重ねて表示する。
   -55%だと牌同士の文字が重なって読みにくくなるため、重ならないよう
   真上（牌1枚ぶん）にそのまま積む。 */
.kifu-kakan-pair { position: relative; display: inline-flex; align-self: flex-end; }
.kifu-kakan-pair .kifu-tile-kakan-stack { position: absolute; left: 0; top: -100%; }
/* 中央の得点パネル。上段をドラ表示専用にし、下段に局・本場・供託・
   各家の開始時持ち点を置く。画面上の位置（上/右/下/左）は席ではなく、
   その位置に座っているプレイヤー（局ごとに変わる）の風と開始時点の
   持ち点を表示する。 */
.kifu-center {
  position: relative;
  grid-area: center;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto auto auto;
  grid-template-areas:
    "dora dora  dora"
    ".    top   ."
    "left mid   right"
    ".    bottom .";
  align-items: center; justify-items: center; gap: 2px;
  background: #16321f; border-radius: 10px; padding: 6px;
  /* 中央パネルも正方形にする。 */
  width: calc(6 * 2.3rem); height: calc(6 * 2.3rem); margin: auto; box-sizing: border-box;
}
.kifu-center-dora-row {
  grid-area: dora; width: 100%; padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.kifu-center-score { color: #f2f2f2; font-size: 0.8rem; text-align: center; line-height: 1.15; white-space: nowrap; }
/* 「東 25,000」（画面下＝自分）を基準に、他の席も牌の向きと同じ条件
   （画面上の位置に応じて180度/90度/-90度）で回転させる。縦書き
   （writing-mode）だと数字の向きが牌と揃わないため使わない。画面上で
   いちばん上の家はドラ表示に場所を譲ったが、他の家と同様に
   局・本場・供託の枠（.kifu-center-mid）の外側・専用の行に表示する。
   CSS Gridは「回転前（横書きのままの）幅」を列幅として使うため、
   nowrapのまま1行に収めようとすると、回転後は逆に「高さ」になった
   その幅ぶん、列・行がムダに大きくなり、見た目の横幅（＝回転前の
   高さ）との差が左右の余白として出てしまう（90度/-90度回転は幅と
   高さが入れ替わるため、正方形でないと必ずこのズレが起きる）。この
   問題が起きるのは回転する左右（南家・北家）だけなので、正方形の
   箱に収めるのも左右だけでよい（上下（東家・西家）まで同じ正方形に
   すると、縦方向に無駄な高さを取ってパネル下側にはみ出してしまう）。 */
.kifu-center-score-right, .kifu-center-score-left {
  position: relative;
  width: 53px; height: 53px; box-sizing: border-box; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.kifu-center-score-top, .kifu-center-score-bottom {
  position: relative;
  overflow: visible; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2px 4px;
}
/* 「点数の下にリーチ棒」はその家自身の目線（＝回転後にその家から見て
   読める向き）での上下であって、画面上の上下ではない。上家は180度
   回転しているので、その家の目線での「下」は画面上では「上」になる
   （DOM順はどの家も score-line→stick で統一し、column-reverseは
   使わない。使うと画面上の見た目が点数→棒の順に揃ってしまい、
   上家の目線で見ると棒が点数の上に来てしまう）。 */
.kifu-center-score-top { grid-area: top; transform: rotate(180deg); }
.kifu-center-score-right { grid-area: right; transform: rotate(-90deg); }
.kifu-center-score-bottom { grid-area: bottom; }
.kifu-center-score-left { grid-area: left; transform: rotate(90deg); }
.kifu-center-score-line { display: flex; align-items: center; }
.kifu-center-wind { font-weight: 700; margin-right: 3px; }
.kifu-center-score-num { font-variant-numeric: tabular-nums; }
/* リーチ中、点数表示の下に供託表示と同じ大きさの千点棒を出す。下家は
   箱の余白が特に無いので、多少パネルからはみ出ても隠さない
   （score-top/bottomはoverflow:visibleにして切らないようにする）。
   供託の千点棒画像（白地に赤丸、ma-jan_tenbou1000.png）とは別に、リーチ棒
   だけ視認性のため青で表示したいという要望があり、不透明な背景込みの
   画像をCSSフィルタで青く見せるのは色が濁りやすいため、CSS単体で
   青い棒＋中央の白丸を描画する方式に変更した（画像は使わない）。 */
.kifu-center-score-riichi-stick {
  height: 0.4rem; width: 3.6rem; display: block; margin-top: 1px;
  border-radius: 2px; background: #2f6fe0;
  background-image: radial-gradient(circle at center, #ffffff 0, #ffffff 1.5px, transparent 2px);
}
.kifu-center-mid {
  position: relative;
  grid-area: mid; color: #f2f2f2; text-align: center; padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 6px;
}
/* 親番ランプ：全自動雀卓のサイコロボタンのイメージで、局表示の囲いの
   縁に赤い長方形を乗せる。得点表示側ではなく局表示（mid）側の子要素に
   することで、点数表示の文字と重ならずに済む（midにはoverflow:hiddenが
   無いので、縁をまたいでも切れない）。辺に沿う向きに合わせて横長/縦長を
   切り替える。4箇所分の要素を常に置いているが、実際の親の位置以外は
   非表示にする。 */
.kifu-center-dealer-lamp {
  display: none; position: absolute; background: transparent; box-sizing: border-box;
}
.kifu-center-dealer-lamp-on { display: block; background: #d8291c; }
.kifu-center-dealer-lamp-top, .kifu-center-dealer-lamp-bottom {
  left: 50%; width: 20px; height: 7px; transform: translateX(-50%);
}
.kifu-center-dealer-lamp-top { top: -4px; }
.kifu-center-dealer-lamp-bottom { bottom: -4px; }
.kifu-center-dealer-lamp-left, .kifu-center-dealer-lamp-right {
  top: 50%; width: 7px; height: 20px; transform: translateY(-50%);
}
.kifu-center-dealer-lamp-left { left: -6px; }
.kifu-center-dealer-lamp-right { right: -6px; }
/* 起家マーク：親番ランプ（局ごとに回転する現在の親）とは別に、その対局で
   最初に東家だった人（起家）を固定で示す。実物の起家マーカー（木札に
   「東」の焼印）をイメージし、その人が今表示されている位置の角に置く。
   視点を変えて表示位置が変わってもついていく。東場はオレンジ、南場は青。
   牌・親番ランプと同じ回転規則（下=基準・右=-90度・上=180度・左=90度）で
   文字の向きをその人のブロックに揃える。画面正面で見た形は、上下＝横長・
   左右＝縦長になるのが正しい（回転前のサイズは常に同じ横長39x21のまま
   にし、左右は回転で見た目だけ縦長に変わる）。回転は中心を軸にするため、
   right/top等のオフセットは「回転後の見た目がパネルの角に収まる位置」
   から逆算してあり、回転前の位置が多少パネル外にずれて見えても正しい
   （はみ出し対策）。 */
.kifu-center-qijia-mark {
  display: none; position: absolute; align-items: center; justify-content: center;
  box-sizing: border-box; width: 39px; height: 21px; font-size: 1.05rem;
  background: #e0995a; border: 1px solid #8a5a2a; border-radius: 4px;
  color: #3a2200; font-weight: 900; line-height: 1;
}
.kifu-center-qijia-mark-minami { background: #4a86c8; border-color: #244a73; color: #0c1f33; }
/* パネル（.kifu-center）基準の絶対配置。下家・左家はパネルの角＝その人の
   点数表示の角でもあるのでそのままでよいが、上家・右家はパネルの角だと
   一番上のドラ表示列にかぶってしまうため、ドラ表示の高さぶん（約55px）
   下にずらし、実際の点数表示の角に合わせてある。 */
.kifu-center-qijia-mark-bottom-right { display: flex; right: 3px; bottom: 3px; transform: rotate(0deg); }
.kifu-center-qijia-mark-top-left { display: flex; left: 3px; top: 68px; transform: rotate(180deg); }
.kifu-center-qijia-mark-top-right { display: flex; right: -6px; top: 77px; transform: rotate(-90deg); }
.kifu-center-qijia-mark-bottom-left { display: flex; left: -6px; bottom: 12px; transform: rotate(90deg); }
/* 局表示（例:「東2」）を左、その右に供託・本場の点棒アイコンを縦に
   並べる。 */
.kifu-center-roundrow { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 2px; }
.kifu-center-round { font-size: 1.4rem; font-weight: 700; }
.kifu-center-sub {
  font-size: 0.75rem; color: #c9d6cc;
  display: flex; flex-direction: column; align-items: flex-start; gap: 0;
}
.kifu-center-sub .fr-counter-row { justify-content: flex-start; gap: 0; }
/* このアイコンは素材自体が横に長く、1.3rem（パラパラ漫画と同じ大きさ）の
   ままだと中央パネルの横幅を無駄に広げてしまうため、ここではさらに
   小さくする（パラパラ漫画側の.fr-counter-iconの共通定義は変えない）。
   数字が大きいと行の高さに引っ張られてアイコンとの間隔も空いて見える
   ため、数字を70%に縮小し、アイコンとももっと詰める。 */
/* 10本場等、本場・供託が2桁になった時に右の数字と棒の先端が被らない
   よう、棒の長さ（横幅）に8割ほど余裕を持たせておく。 */
.kifu-center-sub .fr-counter-icon { height: 0.4rem; width: 2.15rem; }
.kifu-counter-num { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
/* 局終了時、卓全体を少し暗くしてその上に結果（符・翻・点数、役、各家の
   持ち点増減）を表示する（tenhou.net本家ビューアの結果表示を参考に、
   役の一覧も追加）。.kifu-player-tableの一番上に重ねるので、卓の内容を
   隠さないよう普段はdisplay:noneにしておく。 */
.kifu-result-overlay {
  display: none; position: absolute; inset: 0; z-index: 10;
  align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55); border-radius: 16px;
}
.kifu-result-box {
  background: rgba(10, 30, 20, 0.92); border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px; padding: 20px 28px; color: #f2f2f2; text-align: center;
  min-width: 260px;
}
/* 局終了時の詳細表示の一番上に、牌譜画面と同じ形式（3枠・空き枠はダッシュ
   枠のまま）でドラ表示牌・裏ドラ表示牌を出す。裏ドラは実際にデータが
   ある（リーチで和了した）時だけ中身が埋まり、無ければ3枠とも空のまま。 */
.kifu-result-dora {
  margin-bottom: 10px; display: flex; align-items: center; justify-content: center; gap: 18px;
}
.kifu-result-dora-row { display: flex; align-items: center; justify-content: center; gap: 6px; }
.kifu-result-dora-label { font-size: 0.65rem; color: #f2f2f2; }
.kifu-result-dora-tiles { display: flex; gap: 2px; }
.kifu-result-dora-tiles .kifu-tile .tile-face, .kifu-result-dora-tiles .kifu-tile .tile-face-wrap {
  width: 1.8rem; height: 2.3rem; font-size: 1.6rem;
}
.kifu-result-dora-tiles .kifu-tile .tile-face-photo { width: 2.3rem; height: 1.8rem; }
.kifu-result-dora-tiles .kifu-tile-dora-empty { width: 1.8rem; height: 2.3rem; }
.kifu-result-title { font-size: 1.6rem; font-weight: 800; }
.kifu-result-winner { font-size: 1.1rem; font-weight: 700; margin-top: 4px; }
.kifu-result-yaku { font-size: 0.85rem; color: #c9d6cc; margin-top: 6px; max-width: 320px; }
/* 行ごとにflexでcenterすると、増減（+4500等）の有無で行全体の幅が変わり
   名前・点数の横位置がずれてしまう。4列ぶん（風/名前/点数/増減）を
   .kifu-result-scores側の1つのグリッドにまとめ、各行はdisplay:contentsで
   そのグリッド列に直接参加させることで、全行で同じ列幅・同じ横位置に
   揃える。 */
.kifu-result-scores {
  margin-top: 14px; display: grid; grid-template-columns: auto auto auto auto;
  column-gap: 10px; row-gap: 4px; justify-content: center; font-size: 0.95rem;
}
.kifu-result-score-row { display: contents; }
.kifu-result-score-wind { font-weight: 700; justify-self: end; }
.kifu-result-score-name { color: #c9d6cc; text-align: left; justify-self: start; }
.kifu-result-score-num { font-variant-numeric: tabular-nums; justify-self: end; }
.kifu-result-score-extra { display: flex; align-items: center; gap: 6px; justify-self: start; }
.kifu-result-delta { font-variant-numeric: tabular-nums; font-weight: 700; }
.kifu-result-delta-plus { color: #5ec8e8; }
.kifu-result-delta-minus { color: #e85e5e; }
.kifu-result-tenpai-tag {
  font-size: 0.75rem; color: #c9d6cc; border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px; padding: 0 4px;
}
/* 最終局の結果詳細をクリックした時に出す、試合全体の最終結果（順位・
   最終点数）。局結果とは別の単純な縦並びにする。 */
.kifu-game-result-rows { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.kifu-game-result-row {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  font-size: 1.05rem;
}
.kifu-game-result-rank { font-weight: 800; width: 2.6em; text-align: right; }
.kifu-game-result-team-logo { width: 1.4em; height: 1.4em; object-fit: contain; flex: none; background: #fff; border-radius: 4px; padding: 1px; box-sizing: border-box; }
.kifu-game-result-name { min-width: 7em; text-align: left; }
.kifu-game-result-score { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 5em; text-align: right; }
.kifu-game-result-points { font-size: 0.85rem; font-weight: 400; color: #6fd0ff; margin-left: 4px; }
.kifu-game-result-points-minus { color: #ff8a80; }
.kifu-player-controls {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  flex-shrink: 0; flex-wrap: wrap;
}
/* 「開始 ◀ 進捗 ▶ 終了」一式を通常の1.5倍の大きさにする。 */
.kifu-player-controls .small-btn { font-size: 1.125rem; padding: 6px 12px; }
.kifu-player-progress { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 1.125rem; }
.kifu-player-autoplay-controls {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  flex-shrink: 0; flex-wrap: wrap; margin-top: 10px;
}
.kifu-player-viewpoint-controls {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  flex-shrink: 0; flex-wrap: wrap; margin-top: 10px;
}
.kifu-player-display-controls {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  flex-shrink: 0; flex-wrap: wrap; margin-top: 10px;
}
.kifu-player-display-controls .small-btn.kifu-toggle-on {
  background: #2f6b3a; border-color: #2f6b3a; color: #fff;
}
/* 自動再生・視点変更は押し間違えにくいよう通常の2倍の大きさにする。 */
.kifu-player-autoplay-big, .kifu-player-viewpoint-big {
  font-size: 1.5rem; padding: 8px 16px;
}
.kifu-player-autoplay-big.kifu-toggle-on {
  background: #2f6b3a; border-color: #2f6b3a; color: #fff;
}
/* 手牌ON: 視点（下側）以外の手牌を黄色く塗りつぶして見えなくする。 */
.kifu-tile-hidden .tile-face-wrap::after {
  content: ''; position: absolute; inset: 0;
  background: var(--tile-back, #f4d35e); border-radius: 2px;
}
/* 暗転ON: ツモ切り（自摸った牌をそのまま捨てた）の捨て牌を網掛け表示にする。 */
.kifu-tile-tsumogiri-dim .tile-face-wrap::after {
  content: ''; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.3) 0 4px, rgba(0, 0, 0, 0.08) 4px 8px);
}

/* 画像生成と同時に自動投稿するXへの結果を知らせるトースト通知。複数同時に出ても
   重ならないよう、1つの縦積みコンテナにまとめる（rc_postToastContainer参照）。 */
#x-post-toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 1100;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.x-post-toast {
  padding: 12px 18px; border-radius: 8px; font-size: 0.9rem; font-weight: 600;
  max-width: 360px; box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  animation: x-post-toast-in 0.2s ease-out;
  user-select: text; /* エラー文言をコピーできるように */
}
.x-post-toast.ok { background: #1f8a4c; color: #fff; }
.x-post-toast.error { background: #b3402f; color: #fff; cursor: pointer; }
.x-post-toast-hint { margin-top: 4px; font-size: 0.75rem; font-weight: 400; opacity: 0.85; }
@keyframes x-post-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== ハイフ作成（牌譜エディター） ===== */
.haifu-editor .kifu-player-side.haifu-side { flex: 0 0 540px; width: 540px; gap: 10px; align-items: stretch; }
.haifu-guide { font-weight: 700; line-height: 1.4; min-height: 2.8em; }
.haifu-hint { color: #c0392b; font-size: 0.85rem; min-height: 1.2em; }
.haifu-seat-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.haifu-seat-btn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.haifu-seat-btn.kifu-toggle-on, .haifu-btn.kifu-toggle-on { background: #f4d35e; color: #222; border-color: #b8962a; }
.haifu-palette { display: flex; flex-direction: column; gap: 4px; }
.haifu-palette-row { display: flex; gap: 3px; flex-wrap: wrap; }
.haifu-palette-item {
  position: relative; padding: 0; border: 1px solid transparent; border-radius: 4px;
  background: transparent; cursor: pointer; line-height: 0;
}
.haifu-palette-item:hover { border-color: #f4a62a; }
.haifu-palette-empty { opacity: 0.25; cursor: not-allowed; }
.haifu-palette-count {
  position: absolute; right: -2px; bottom: -2px; line-height: 1;
  font-size: 0.6rem; background: rgba(0, 0, 0, 0.7); color: #fff; border-radius: 3px; padding: 1px 2px;
}
.haifu-actions { display: flex; flex-direction: column; gap: 4px; }
.haifu-action-row { display: flex; gap: 4px; }
.haifu-action-row .haifu-btn { flex: 1; padding: 6px 0; font-size: 0.95rem; }
.haifu-info { font-size: 0.85rem; color: var(--muted, #666); line-height: 1.5; }
.haifu-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.85rem; margin-top: auto; }
.haifu-save-error { color: #c0392b; }
.haifu-discard-btn { color: #c0392b; }
.haifu-editor .haifu-hand-tile { cursor: pointer; }
.haifu-editor .haifu-hand-tile:hover { filter: brightness(0.85); }
.haifu-tile-selected { transform: translateY(-10px); outline: 3px solid #f4d35e; border-radius: 3px; }
.haifu-seat-active .kifu-player-seat-name {
  background: #f4d35e; color: #222; text-shadow: none; border-radius: 6px; padding: 0 8px;
}
.haifu-dora-target { outline: 3px solid #f4a62a; }
.hand-haifu-edit-btn.haifu-has-draft { border-color: #f4a62a; }
/* パレットは1スート10枚（1〜9＋赤5）が1行に収まる大きさにする。 */
.haifu-palette-row { flex-wrap: nowrap; }
.haifu-palette .kifu-tile .tile-face, .haifu-palette .kifu-tile .tile-face-wrap { width: 2.33rem; height: 2.93rem; font-size: 2.1rem; }
.haifu-palette .kifu-tile .tile-face-photo { width: 2.93rem; height: 2.33rem; }
/* 手番者の手牌（13枚＋ツモ牌）がパネル幅に1行で収まる大きさにする。 */
.haifu-haipai-preview .kifu-tile .tile-face, .haifu-haipai-preview .kifu-tile .tile-face-wrap { width: 2.15rem; height: 2.7rem; font-size: 1.95rem; }
.haifu-haipai-preview .kifu-tile .tile-face-photo { width: 2.7rem; height: 2.15rem; }
.haifu-haipai-preview-tiles { padding-top: 10px; }
.haifu-palette-count { font-size: 0.75rem; }
/* 配牌入力中だけ、パレットの下に入力順のまま配牌を並べる（卓に目を移さずに
   押し間違い・押せていない牌に気付けるように）。牌を押すと取り消せる。 */
.haifu-haipai-preview { display: flex; flex-direction: column; gap: 4px; padding: 6px; border: 1px dashed #b8962a; border-radius: 6px; }
.haifu-haipai-preview:empty { display: none; }
.haifu-haipai-preview-label { font-size: 0.85rem; font-weight: 700; }
.haifu-haipai-preview-tiles { display: flex; gap: 2px; min-height: 2.7rem; }
.haifu-haipai-preview-tiles .kifu-tile { cursor: pointer; }
.haifu-haipai-preview-tiles .kifu-tile:hover { filter: brightness(0.85); }
/* 各家のブロックは回転した長方形で、見た目より広い範囲（隣の家の手牌の端）に
   重なっている。後に描かれる家のブロックが手前に来てクリックを奪ってしまうため、
   エディターではブロック自体はクリックを素通りさせ、手牌の牌だけ反応させる。 */
.haifu-editor .kifu-player-seat, .haifu-editor .kifu-player-seat-content { pointer-events: none; }
.haifu-editor .haifu-hand-tile { pointer-events: auto; }
/* 河の牌は押すと差し替え（入力ミスを後から直す）。差し替え中の牌は橙の枠で示す。 */
.haifu-editor .haifu-river-tile { pointer-events: auto; cursor: pointer; }
.haifu-editor .haifu-river-tile:hover { filter: brightness(1.12); }
.haifu-editor .haifu-replace-target { outline: 3px solid #ff9800; outline-offset: -1px; border-radius: 3px; z-index: 2; }
/* 裏ドラ表示牌はドラ表示牌の下に同じ5枠で並べる（エディターのみ）。 */
.haifu-editor .kifu-center-dora-row { flex-direction: column; gap: 3px; }
.haifu-ura-tiles { cursor: pointer; }
.haifu-slot-disabled { opacity: 0.35; }
/* 裏ドラ行を出している間は、ドラ・裏ドラの2行とも少し小さくして中央パネルの
   伸びを最小限にし、上下均等に伸ばす（下家・対面の捨て牌に被らないように）。
   上側の角に置く起家マークも、伸びたぶんだけ下げる。 */
.haifu-ura-shown .kifu-player-dora-tiles .kifu-tile .tile-face, .haifu-ura-shown .kifu-player-dora-tiles .kifu-tile .tile-face-wrap {
  width: 1.6rem; height: 2rem; font-size: 1.45rem;
}
.haifu-ura-shown .kifu-player-dora-tiles .kifu-tile .tile-face-photo { width: 2rem; height: 1.6rem; }
.haifu-ura-shown .kifu-player-dora-tiles .kifu-tile-dora-empty { width: 1.6rem; height: 2rem; }
.haifu-ura-shown .kifu-center-dora-row { padding-bottom: 3px; }
.haifu-editor .kifu-center.haifu-ura-shown { height: auto; min-height: calc(6 * 2.3rem); margin: 0; align-self: center; justify-self: center; }
.haifu-ura-shown .kifu-center-qijia-mark-top-left { top: calc(68px + 1.1rem); }
.haifu-ura-shown .kifu-center-qijia-mark-top-right { top: calc(77px + 1.1rem); }
.haifu-haipai-preview-label { display: flex; align-items: center; gap: 6px; }
.haifu-preview-name {
  display: inline-flex; align-items: center; gap: 4px;
  background: #f4d35e; color: #222; border-radius: 6px; padding: 2px 8px;
  font-size: 1.15rem; font-weight: 700;
}
.haifu-preview-name .kifu-player-seat-team-logo { width: 1.4rem; height: 1.4rem; }
.haifu-preview-wind { font-size: 0.9rem; margin-right: 2px; }
/* 流局時のテンパイ／ノーテン確認 */
.haifu-tenpai-box { display: flex; flex-direction: column; gap: 4px; padding: 8px; border: 2px solid #f4a62a; border-radius: 8px; }
.haifu-tenpai-box:empty { display: none; }
.haifu-tenpai-title { font-weight: 700; }
.haifu-tenpai-state { font-size: 0.8rem; margin-left: 6px; color: #b8962a; }
.haifu-tenpai-row { display: grid; grid-template-columns: 1fr 6.5rem 9rem; align-items: center; gap: 6px; }
.haifu-tenpai-toggle { padding: 4px 0; }
.haifu-tenpai-toggle.kifu-toggle-on { background: #5ec8e8; color: #10202a; border-color: #2d8fb0; }
.haifu-tenpai-auto { font-size: 0.8rem; color: var(--muted, #666); }
.haifu-tenpai-confirm { margin-top: 4px; padding: 6px 0; font-weight: 700; }
/* 案内文・赤字の注意の文量が変わっても、下のパレットの位置が動かないように
   高さを固定する（同じ位置で待機しているマウスが別の牌を押してしまわないように）。
   案内文は3行、注意は2行ぶんを常に確保する。 */
.haifu-guide { height: 4.2em; min-height: 0; line-height: 1.4; overflow: hidden; flex-shrink: 0; }
.haifu-hint { height: 2.6em; min-height: 0; line-height: 1.3; overflow: hidden; flex-shrink: 0; }
/* 確定ボタンは枠の見出しの右側に置く（枠の下端が画面外にはみ出しても押せるように）。 */
.haifu-tenpai-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.haifu-tenpai-title .haifu-tenpai-confirm { margin-top: 0; padding: 4px 18px; }
.haifu-header-btns { display: flex; align-items: center; gap: 8px; }
.haifu-next-hand-btn { background: #2d8fb0; color: #fff; border-color: #1f6b85; font-weight: 700; padding: 6px 14px; }
.haifu-next-hand-btn:disabled { background: #eee; color: #888; border-color: #ccc; font-weight: 400; }

/* 牌の裏面の色（伏せた手牌・暗カンの両脇・未確定のカンドラ枠）。既定は黄色。
   ハイフ作成エディターで局ごとに青を選べる（自動卓は2色の牌を局ごとに入れ替えるため）。 */
.tile-back-blue { --tile-back: #3b7dd8; }
.haifu-back-toggle .haifu-back-chip {
  display: inline-block; width: 0.8em; height: 1.05em; margin-right: 4px; vertical-align: -0.15em;
  border: 1px solid #333; border-radius: 2px; background: var(--tile-back, #f4d35e);
}

/* 動画位置設定のパラパラ：まとめ画像の読み込み待ちの表示 */
.frame-review-viewport { position: relative; }
.frame-review-loading { position: absolute; top: 8px; right: 8px; display: none; pointer-events: none; z-index: 2;
  background: rgba(245,158,11,.92); color: #111; font-weight: 600; padding: 4px 10px; border-radius: 6px; font-size: 12px; }
