:root {
  --bg: #0f1a2e;
  --panel: #14223a;
  --border: #3b4a63;
  --text: #eef2f7;
  --muted: #a9b4c6;
  --accent: #7fb3ff;
  --bet: #ff7a45;
  --bet-bg: #4a2418;
  --check: #45c26b;
  --check-bg: #163b25;
  --error: #ff8080;
  --card-bg: #ffffff;
  --card-text: #111;
  --red-suit: #c8102e;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  min-width: 0;
}

/* hidden 属性は .row / .pagination などの display 指定より必ず優先する */
[hidden] { display: none !important; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 1.5rem;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border);
}
.title { font-size: 1.2rem; margin: 0; }
.title .sub { font-weight: normal; color: var(--muted); font-size: 0.95rem; }
.status { margin: 0; color: var(--muted); font-size: 0.95rem; overflow-wrap: anywhere; }

.layout {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 1rem;
  padding: 1rem; max-width: 1400px; margin: 0 auto;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.9rem; min-width: 0;
}
.panel-title { font-size: 1.05rem; margin: 0 0 0.6rem; overflow-wrap: anywhere; }
.section-title { font-size: 1rem; margin: 0.8rem 0 0.4rem; color: var(--accent); }
.section-title.small { font-size: 0.95rem; }

.field { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.6rem; min-width: 0; }
label, .cond-label, dt { font-size: 0.9rem; color: var(--muted); }
select, input[type="text"] {
  font: inherit; color: var(--text); background: #0c1526;
  border: 1px solid var(--border); border-radius: 4px; padding: 0.35rem 0.5rem; max-width: 100%; min-width: 0;
}
.hint { margin: 0.1rem 0 0; font-size: 0.875rem; color: var(--muted); }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--error); margin: 0.4rem 0 0; min-height: 1.2em; font-size: 0.95rem; overflow-wrap: anywhere; }
.error:empty { display: none; }
.count { margin: 0.5rem 0; font-size: 0.9rem; color: var(--muted); }
.notice { font-size: 0.9rem; color: var(--muted); margin: 0.5rem 0 0.3rem; }
.details summary { cursor: pointer; font-size: 0.9rem; color: var(--muted); }

.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.4rem; }

.btn {
  font: inherit; font-size: 0.95rem; padding: 0.4rem 0.85rem; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--accent); background: #1d3358; color: var(--text);
}
.btn:hover:not(:disabled) { background: #264472; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--border); }
.mode-toggle { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.8rem 0 0.6rem; }
.mode-btn[aria-pressed="true"] { background: var(--accent); color: #0b1526; border-color: var(--accent); font-weight: bold; }

:focus-visible { outline: 3px solid #ffd166; outline-offset: 2px; }

/* ---------- 公開用ナビ・会員ゲート（追加分。既存の [hidden] 優先ルールを崩さない） ---------- */
.site-nav { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; font-size: 0.95rem; min-width: 0; }
.site-nav a { color: var(--accent); overflow-wrap: anywhere; }
.gate {
  max-width: 640px; margin: 1.5rem auto; padding: 1rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; min-width: 0;
}
@media (max-width: 860px) { .gate { margin: 1rem; max-width: none; } }
.gate-title { font-size: 1.05rem; margin: 0 0 0.6rem; }
.gate-state { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.gate-state p { margin: 0.4rem 0; }
.gate-state a.btn { display: inline-block; text-decoration: none; }

/* 場面一覧は高さを抑えて縦スクロール（30件でも学習面を押し下げない） */
.scenario-list {
  display: flex; flex-direction: column; gap: 0.4rem;
  max-height: 60vh; overflow-y: auto; padding: 2px; scroll-padding: 4px;
}
@media (max-width: 860px) {
  .scenario-list { max-height: 38vh; }
}
.scenario-btn {
  display: flex; flex-direction: column; gap: 0.25rem; text-align: left; width: 100%; min-width: 0;
  background: #0c1526; border: 1px solid var(--border); border-radius: 5px; padding: 0.5rem; color: var(--text);
  font: inherit; cursor: pointer; overflow-wrap: anywhere;
}
.scenario-btn:hover { border-color: var(--accent); }
.scenario-btn[aria-current="true"] { border-color: var(--accent); background: #1d3358; }
.scenario-btn .meta { font-size: 0.875rem; color: var(--muted); }
.pagination { justify-content: space-between; }
.page-label { font-size: 0.9rem; color: var(--muted); }

.cards { display: inline-flex; gap: 0.25rem; flex-wrap: wrap; }
.card {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.2rem; height: 2.9rem; padding: 0 0.3rem; border-radius: 4px;
  background: var(--card-bg); color: var(--card-text); font-weight: bold; font-size: 1.05rem;
  border: 1px solid #ccc; font-family: ui-monospace, Menlo, monospace;
}
.card.red { color: var(--red-suit); }
.board-row, .hand-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin: 0.3rem 0; }
.role { font-size: 0.9rem; color: var(--muted); }

.cond-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.3rem 1rem; margin: 0.4rem 0;
}
.cond-grid > div { display: flex; flex-direction: column; border-left: 2px solid var(--border); padding-left: 0.5rem; min-width: 0; }
.cond-grid dd { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }

.bars { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) 6rem; gap: 0.5rem; align-items: center; }
@media (max-width: 480px) { .bar-row { grid-template-columns: minmax(0, 1fr) 5.5rem; } .bar-row .bar-label { grid-column: 1 / -1; } }
.bar-label { font-size: 0.95rem; min-width: 0; overflow-wrap: anywhere; }
.bar-label .pct { color: var(--muted); font-size: 0.85rem; margin-left: 0.3rem; }
.bar-track { height: 1.1rem; background: #0c1526; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; }
.bar-fill.bet, .bar-fill.allin { background: var(--bet); }
.bar-fill.check { background: var(--check); }
.bar-value { font-variant-numeric: tabular-nums; text-align: right; font-size: 0.95rem; }
.bar-row.chosen .bar-label { font-weight: bold; text-decoration: underline; }
.bar-row.chosen .bar-label::after { content: " ← あなたの選択"; color: var(--accent); font-size: 0.85rem; }

.action-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0; }
.action-btn { min-width: 8rem; max-width: 100%; }
.action-btn.bet, .action-btn.allin { border-color: var(--bet); background: var(--bet-bg); }
.action-btn.check { border-color: var(--check); background: var(--check-bg); }
.action-btn[aria-pressed="true"] { outline: 2px solid var(--text); }

/* 13×13 手札表：狭い画面ではラッパー内だけ横スクロール（ページ全体は溢れさせない） */
.grid-scroll { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: 2px; margin: 0.4rem 0; }
.hand-grid { display: grid; grid-template-columns: repeat(13, minmax(4.4rem, 1fr)); gap: 2px; width: max-content; min-width: 100%; }
.hand-grid [role="row"] { display: contents; }
.grid-cell {
  display: flex; flex-direction: column; align-items: stretch; gap: 0.05rem; width: 100%; min-height: 3.6rem;
  padding: 0.2rem 0.25rem; border: 1px solid var(--border); border-radius: 3px; cursor: pointer;
  background: #0c1526; color: var(--text); font: inherit; text-align: left; line-height: 1.2;
  /* 色は補助。塗りの濃さはアクション平均に応じて JS が --fill を設定する */
  background-image: linear-gradient(var(--fill-color, transparent), var(--fill-color, transparent));
  background-size: var(--fill, 0%) 100%; background-repeat: no-repeat;
}
.grid-cell.pair { border-color: #5a6c8a; }
.grid-cell.bet { --fill-color: rgba(255, 122, 69, 0.35); }
/* オールインは既存の ALLIN アクション型として扱う（練習ボタン・棒グラフと同じベット系の色。値は必ず文字で併記） */
.grid-cell.allin { --fill-color: rgba(255, 122, 69, 0.5); }
.grid-cell.check { --fill-color: rgba(69, 194, 107, 0.35); }
.grid-cell.empty { color: var(--muted); background: #101a2c; cursor: pointer; }
/* 選択中：button 側の aria-pressed とラッパー（role=gridcell）側の aria-selected を同時に更新する */
.grid-cell[aria-pressed="true"], [role="gridcell"][aria-selected="true"] > .grid-cell {
  outline: 2px solid var(--accent); outline-offset: -2px; background-color: #1d3358;
}
.grid-cell:hover { border-color: var(--accent); }
.grid-cell .sym { font-weight: bold; font-size: 0.95rem; font-family: ui-monospace, Menlo, monospace; }
.grid-cell .cnt { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.grid-cell .mean { font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.grid-cell.empty .mean { font-size: 0.75rem; }
.grid-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.3rem 1rem; margin: 0.4rem 0; }
.grid-legend > div { border-left: 2px solid var(--border); padding-left: 0.5rem; min-width: 0; }
.grid-legend dd { margin: 0; font-size: 0.875rem; color: var(--muted); }
.grid-legend dt { font-size: 0.9rem; color: var(--text); }
.cell-detail { border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.7rem 0.7rem; margin: 0.6rem 0 1rem; }
.cell-detail:empty, .cell-detail.inactive { display: none; }
.cell-symbol { font-family: ui-monospace, Menlo, monospace; color: var(--text); }
.combo-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.3rem 0; }
.combo-btn { font-family: ui-monospace, Menlo, monospace; min-width: 4.5rem; }
.combo-btn[aria-pressed="true"] { background: var(--accent); color: #0b1526; font-weight: bold; }
.combo-excluded { flex-basis: 100%; margin: 0.2rem 0 0; }
.grid-action-field { max-width: 420px; }

/* フロップの続き（保存経路の探索） */
.breadcrumb { list-style: none; display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; padding: 0; margin: 0.4rem 0; }
.breadcrumb li { display: flex; align-items: center; gap: 0.3rem; min-width: 0; }
.breadcrumb li + li::before { content: "→"; color: var(--muted); }
.crumb { font-family: ui-monospace, Menlo, monospace; font-size: 0.875rem; overflow-wrap: anywhere; }
.crumb.current { color: var(--text); font-weight: bold; padding: 0.4rem 0.6rem; border: 1px solid var(--accent); border-radius: 4px; background: #1d3358; }
#explorer-node-heading { outline-offset: 4px; overflow-wrap: anywhere; }
.explorer-context { margin-bottom: 0.6rem; }
.node-action { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; text-align: left; }
.node-action-label { font-size: 0.95rem; }
.node-action-raw { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; color: var(--muted); }
.action-btn.fold { border-color: var(--border); background: #1a2338; }
.action-btn.call, .action-btn.raise { border-color: var(--bet); background: var(--bet-bg); }
.action-btn.raise { border-style: double; }
.bar-fill.raise { background: var(--bet); }
.bar-fill.call { background: #d9a441; }
.bar-fill.fold { background: #6b7a94; }

/* 表は折り返しで収め、必要な場合のみラッパー内でスクロール */
.table-wrap { max-width: 100%; overflow-x: auto; }
.recap { border-collapse: collapse; width: 100%; max-width: 560px; margin-top: 0.4rem; font-size: 0.95rem; }
.recap th, .recap td { border: 1px solid var(--border); padding: 0.3rem 0.5rem; text-align: left; overflow-wrap: anywhere; }
.recap td:nth-child(2), .recap td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
