/* ===== リセット・基本 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a5c1d;
  --primary-light: #2e8a31;
  --primary-dark: #163f18;
  --secondary: #8b6914;
  --danger: #c0392b;
  --success: #27ae60;
  --warning: #e67e22;
  --info: #2980b9;
  --bg: #f2f5f2;
  --card-bg: #ffffff;
  --text: #2c2c2c;
  --name-color: #182d1c;
  --text-muted: #777;
  --border: #ddd;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
}

body {
  font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== ナビ ===== */
.navbar {
  background: linear-gradient(135deg, var(--primary-dark) 0%, #2c7030 100%);
  color: white;
  padding: 0.8rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.nav-brand a {
  color: white; text-decoration: none;
  font-size: 1.25rem; font-weight: bold;
  letter-spacing: 0.01em;
}
.nav-links { display: flex; gap: 0.5rem 1rem; align-items: center; flex-wrap: wrap; }
.nav-links a {
  color: rgba(255,255,255,0.9); text-decoration: none;
  font-size: 0.9rem; transition: color 0.15s;
}
.nav-links a:hover { color: white; }
.admin-link {
  background: var(--warning); padding: 0.2rem 0.6rem;
  border-radius: 5px; font-weight: 600;
}
.user-name { color: rgba(255,255,255,0.65); font-size: 0.85rem; }

/* ===== コンテナ ===== */
.container { max-width: 960px; margin: 0 auto; padding: 1.5rem; flex: 1; }

/* ===== セクション ===== */
.section { margin-bottom: 2rem; }
.section h2 {
  font-size: 1.1rem;
  border-left: 4px solid var(--primary);
  padding: 0.35rem 0.6rem 0.35rem 0.75rem;
  margin-bottom: 1rem;
  background: linear-gradient(90deg, rgba(26,92,29,0.08), transparent);
  border-radius: 0 6px 6px 0;
}

/* ===== アラート ===== */
.flash-messages { margin-bottom: 1rem; }
.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 0.5rem; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ===== ボタン ===== */
.btn {
  display: inline-block; padding: 0.5rem 1rem; border: none; border-radius: 8px;
  cursor: pointer; font-size: 0.9rem; text-decoration: none;
  transition: opacity 0.18s, transform 0.12s;
  font-weight: 600;
}
.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
}
.btn-secondary { background: #6c757d; color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-block { width: 100%; text-align: center; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; border-radius: 5px; white-space: nowrap; }
.btn-line {
  background: #06C755; color: white;
  display: flex; align-items: center; justify-content: center;
}
.btn-line:hover { background: #05b04b; opacity: 1; }

/* ===== フォーム ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.3rem; font-weight: 600; font-size: 0.9rem; }
.form-control {
  width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.95rem; transition: border-color 0.2s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(26,92,29,0.12); }
.form-control.small { width: 80px; }
.form-group.checkbox { display: flex; align-items: center; gap: 0.5rem; }
.form-group.checkbox label { margin: 0; font-weight: normal; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.error { color: var(--danger); font-size: 0.8rem; display: block; }
.hint { color: var(--text-muted); font-size: 0.8rem; }

/* ===== 認証カード ===== */
.auth-card {
  max-width: 420px; margin: 3rem auto; background: var(--card-bg);
  padding: 2rem; border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}
.auth-card h1 { margin-bottom: 1.5rem; font-size: 1.5rem; color: var(--primary); }
.auth-link { margin-top: 1rem; text-align: center; font-size: 0.9rem; }
.auth-divider {
  text-align: center; margin: 1rem 0; position: relative;
}
.auth-divider::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%;
  border-top: 1px solid var(--border);
}
.auth-divider span {
  background: var(--card-bg); position: relative; padding: 0 0.75rem;
  color: var(--text-muted); font-size: 0.85rem;
}

/* ===== テーブル ===== */
.table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.07); }
.table th, .table td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th {
  background: var(--primary);
  color: white; font-weight: 600;
  white-space: nowrap;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f4f8f4; }
.table.small-table { max-width: 300px; }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive .table { min-width: 500px; }

/* ===== レースカード ===== */
.home-container { width: 100%; min-width: 0; }
.race-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.race-card {
  min-width: 0;
  background: var(--card-bg); border-radius: 10px; padding: 1.2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-top: 3px solid var(--border);
  transition: box-shadow 0.18s, transform 0.15s;
}
.race-card:hover {
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  transform: translateY(-2px);
}
.race-card.open { border-top-color: var(--primary); }
.race-date { font-size: 0.85rem; color: var(--text-muted); }
.race-name { font-weight: bold; font-size: 1rem; margin: 0.4rem 0; }
.race-list-label { display: flex; align-items: center; gap: 0.35rem; min-width: 0; color: var(--name-color); }
a.race-list-label { font-weight: 600; text-decoration: none; }
a.race-list-label:hover,
a.race-list-label:focus-visible { color: var(--name-color); }
a.race-list-label:hover .race-list-text,
a.race-list-label:focus-visible .race-list-text { text-decoration: underline; }
a.race-list-label:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 3px; }
.race-list-label .grade-badge,
.race-list-label .race-country-flag { flex: 0 0 auto; margin-right: 0; }
.race-list-label .race-country-flag { margin-top: 0; }
.race-list-text { min-width: 0; overflow-wrap: anywhere; }
.home-results-table { table-layout: fixed; width: 100%; }
.home-results-table th:first-child { width: 5em; }
.home-results-table th:last-child { width: 6em; }
.home-results-table .race-list-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.my-pick { font-size: 0.85rem; margin-bottom: 0.75rem; color: var(--primary); }
.my-pick.no-pick { color: var(--text-muted); }

/* ===== 今週の予定レース（コンパクトリスト） ===== */
.upcoming-race-list { display: flex; flex-direction: column; gap: 0.4rem; }
.upcoming-race-item {
  display: grid; grid-template-columns: 7em minmax(0, 1fr) auto;
  align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--card-bg); border-radius: 6px;
  border-left: 3px solid var(--border);
  font-size: 0.88rem;
}
.upcoming-race-date { color: var(--text-muted); white-space: nowrap; min-width: 7em; }
.upcoming-race-name { min-width: 0; font-weight: 600; }
.upcoming-race-status {
  font-size: 0.78rem; color: var(--text-muted);
  background: var(--bg); padding: 0.15rem 0.5rem;
  border-radius: 10px; white-space: nowrap;
}

/* ===== バッジ ===== */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 12px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.badge-open { background: #d4edda; color: #155724; }
.badge-finished { background: #d1ecf1; color: #0c5460; }
.badge-closed { background: #f8f9fa; color: #6c757d; }
.badge-locked { background: #fff3cd; color: #856404; }
.race-time-label { font-size: 0.82rem; color: var(--text-muted); margin-left: 0.25rem; }
.locked-banner {
  background: linear-gradient(135deg, #fffdf0, #fff8d6);
  border: 2px solid #e6c200;
  border-radius: 10px; padding: 1rem 1.2rem;
  margin-bottom: 1rem; font-size: 0.95rem;
}
.locked-banner p { margin-bottom: 0.4rem; }
.locked-banner p:last-child { margin-bottom: 0; }

/* 予想の馬名・騎手名を別々の行に置き、長い名前も折り返して全文表示する。 */
.prediction-summary { display: flex; align-items: baseline; gap: 0.4rem; }
.prediction-summary-label { flex: 0 0 auto; white-space: nowrap; }
.prediction-summary-details { display: grid; gap: 0.15rem; flex: 1; min-width: 0; }
.prediction-summary-horse,
.prediction-summary-jockey {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}

/* ===== 格付けバッジ ===== */
.grade-badge {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 800; letter-spacing: 0.02em;
  padding: 0.15rem 0.45rem; border-radius: 5px;
  vertical-align: middle; margin-right: 0.35rem;
  white-space: nowrap;
}
.grade-G1 {
  background: #1a3580;
  color: #fff;
  box-shadow: 0 1px 4px rgba(26,53,128,0.4);
}
/* 5大クラシック（桜花賞・オークス・皐月賞・日本ダービー・菊花賞）は金文字 */
.grade-G1.grade-classic {
  color: #f9d71c;
  text-shadow: 0 0 4px rgba(249,215,28,0.35);
}
.grade-G2 {
  background: #d93025;
  color: #fff;
  box-shadow: 0 1px 4px rgba(217,48,37,0.4);
}
.grade-G3 {
  background: #2a9d4e;
  color: #fff;
  box-shadow: 0 1px 4px rgba(42,157,78,0.3);
}
.grade-L {
  background: #1a1a1a;
  color: #fff;
  border: none;
}
.grade-OP {
  background: #fff;
  color: #111;
  border: 1.5px solid #999;
}

/* ===== レース詳細 ===== */
.race-detail-container { width: 100%; }
.race-header { margin-bottom: 1.5rem; }
.race-header h1 { overflow-wrap: anywhere; color: var(--name-color); }
.race-meta { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; flex-wrap: wrap; }
.race-date { font-size: 0.95rem; color: var(--text-muted); }

/* ===== 出馬表・予想 ===== */
/* 現在の予想バナー */
.current-pick-banner {
  background: linear-gradient(135deg, #f0f8f0, #e0f0e0);
  border: 2px solid var(--primary);
  border-radius: 10px; padding: 0.75rem 1.2rem;
  margin-bottom: 1.2rem; font-size: 0.95rem; color: var(--primary);
}

/* カードグリッド */
.horse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

/* 馬カード */
.horse-card {
  display: flex; align-items: stretch;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.18s ease;
  overflow: hidden;
  position: relative;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.horse-card:hover {
  border-color: var(--primary-light);
  box-shadow: 0 4px 14px rgba(26,92,29,0.18);
  transform: translateY(-2px);
}
.horse-card:has(input:checked),
.horse-card.selected {
  border-color: var(--primary);
  background: linear-gradient(135deg, #f0f8f0, #e8f5e8);
  box-shadow: 0 4px 16px rgba(26,92,29,0.25);
}
.horse-card input[type="radio"] { display: none; }

/* 枠番部分 */
.horse-card-gate {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  width: 40px; min-height: 80px;
  flex-shrink: 0;
  gap: 2px;
}
.horse-card-gate-num {
  font-size: 1.1rem; font-weight: bold; line-height: 1;
}
.horse-card-gate-label {
  font-size: 0.6rem; opacity: 0.75;
}
/* 枠番背景色 */
.gate-bg-1 { background: #f5f5f5; color: #333; border-right: 1px solid #ccc; }
.gate-bg-2 { background: #1a1a1a; color: white; }
.gate-bg-3 { background: #c0392b; color: white; }
.gate-bg-4 { background: #2471a3; color: white; }
.gate-bg-5 { background: #f4d03f; color: #333; }
.gate-bg-6 { background: #1e8449; color: white; }
.gate-bg-7 { background: #e67e22; color: white; }
.gate-bg-8 { background: #d63384; color: white; }

/* 馬情報部分 */
.horse-card-body {
  flex: 1; min-width: 0; padding: 0.65rem 0.75rem;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.horse-card-num {
  font-size: 1rem; color: var(--text); font-weight: 800;
  line-height: 1.2;
}
.horse-card-name {
  font-size: 0.95rem; font-weight: bold; color: var(--text);
  line-height: 1.3; overflow-wrap: anywhere;
}
.horse-card-jockey {
  font-size: 0.72rem; color: var(--text-muted); margin-top: 2px;
}

/* チェックマーク */
.horse-card-check {
  display: none; align-items: center; justify-content: center;
  width: 36px; color: var(--primary); font-size: 1.6rem; font-weight: bold;
  flex-shrink: 0; padding-right: 0.5rem;
}
.horse-card:has(input:checked) .horse-card-check,
.horse-card.selected .horse-card-check { display: flex; }

/* 旧スタイル（後方互換） */
.gate-num {
  display: inline-block; width: 40px; height: 24px; line-height: 24px;
  text-align: center; border-radius: 4px; font-size: 0.75rem; font-weight: bold;
}
.gate-1 { background: #fff; border: 1px solid #999; }
.gate-2 { background: #111; color: white; }
.gate-3 { background: #c0392b; color: white; }
.gate-4 { background: #2980b9; color: white; }
.gate-5 { background: #f9d71c; color: #333; }
.gate-6 { background: #27ae60; color: white; }
.gate-7 { background: #e67e22; color: white; }
.gate-8 { background: #e91e8c; color: white; }
.horse-num { font-weight: bold; min-width: 30px; }
.horse-name { font-size: 1rem; }

.pick-actions { display: flex; align-items: center; gap: 1rem; margin-top: 0.5rem; }
.btn-lg { padding: 0.7rem 1.8rem; font-size: 1rem; }
.current-pick { color: var(--primary); font-size: 0.9rem; }
.my-pick-badge {
  background: var(--primary); color: white; font-size: 0.75rem;
  padding: 0.1rem 0.4rem; border-radius: 4px; margin-left: 0.4rem;
  white-space: nowrap;
}

/* レスポンシブ: スマホは1列 */
@media (max-width: 600px) {
  /* 国内の1列表示に揃え、長い海外レース名でページ幅が広がらないようにする。 */
  .race-detail-container { max-width: 320px; }
  .horse-grid { grid-template-columns: 1fr; gap: 0.4rem; }
  .horse-card { min-height: 64px; }
  .horse-card-gate { min-height: 64px; }
}

/* ===== 結果テーブル ===== */
.result-table .rank-1 td { background: #fffacd; font-weight: bold; }
.result-table .rank-2 td { background: #f5f5f5; }
.result-table .rank-3 td { background: #fdf0e0; }
.result-table .my-horse { border-left: 4px solid var(--primary); }
.result-table .scratched td { color: var(--text-muted); text-decoration: line-through; }
.finish-pos { font-weight: bold; font-size: 1.1rem; }

/* ===== ポイント ===== */
.points { font-weight: bold; }
/* 1着系 (100pt / G1 150pt) */
.points-100, .points-150 { color: #e74c3c; }
/* 2着系 (50pt / G1 75pt) */
.points-50, .points-75 { color: #e67e22; }
/* 3着系 (30pt / G1 45pt) */
.points-30, .points-45 { color: #f39c12; }
/* 4着系 (20pt / G1 30pt) */
.points-20 { color: #27ae60; }
/* 5着系 (10pt / G1 15pt) */
.points-10, .points-15 { color: #3498db; }
/* 0pt */
.points-0 { color: var(--text-muted); }
/* ランキングセル */
.points-cell { font-weight: bold; font-size: 1.1rem; }

/* ===== ランキング ===== */
.ranking-table .rank-gold td { background: rgba(255,215,0,0.15); }
.ranking-table .rank-silver td { background: rgba(192,192,192,0.15); }
.ranking-table .rank-bronze td { background: rgba(205,127,50,0.15); }
.ranking-table .my-row td { font-weight: bold; }
.rank-num { font-size: 1.1rem; }
.you-badge { background: var(--primary); color: white; font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 4px; margin-left: 0.4rem; }

.ranking-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.month-selector select { padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; margin-right: 0.3rem; }

.ranking-links { display: flex; gap: 1rem; }

/* ===== ポイント凡例 ===== */
.point-legend { margin-top: 2rem; }
.point-legend h3 { margin-bottom: 0.5rem; }
.point-note { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.5rem; }
/* 横向きポイント表 */
.point-table-wrap { overflow-x: auto; }
.point-table-h th,
.point-table-h td { text-align: center; white-space: nowrap; }

/* ===== G1ボーナス通知 ===== */
.g1-bonus-notice {
  background: linear-gradient(135deg, #1a3580 0%, #2a4aad 100%);
  color: white; font-weight: bold;
  padding: 0.65rem 1rem; border-radius: 8px;
  margin-bottom: 1rem; text-align: center;
  font-size: 0.95rem; letter-spacing: 0.02em;
}

/* ===== その他 ===== */
.empty-msg { color: var(--text-muted); font-style: italic; padding: 1rem; }
.my-row td { font-weight: 600; }
.text-muted { color: var(--text-muted); }

/* ===== ユーザー内訳ページ ===== */
/* 内訳テーブルは500px min-widthを無効化してモバイルで収まるようにする */
.table-responsive .picks-breakdown-table { min-width: 0; }
.user-link { color: var(--name-color); text-decoration: none; font-weight: 600; border-bottom: 1px dotted var(--name-color); }
.user-link:hover { color: var(--name-color); border-bottom-color: var(--name-color); }
.race-link { color: var(--name-color); text-decoration: none; }
.race-link:hover { color: var(--name-color); text-decoration: underline; }
.picks-breakdown-table .race-list-text { overflow: hidden; text-overflow: ellipsis; }
.period-label { font-size: 0.9rem; color: var(--text-muted); margin-top: 0.25rem; }
.horse-num-sm {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--text); color: white;
  font-size: 0.72rem; font-weight: bold;
  width: 20px; height: 20px; border-radius: 3px;
  margin-right: 0.3rem; vertical-align: middle; flex-shrink: 0;
}
.picks-breakdown-table .td-date { white-space: nowrap; color: var(--text-muted); font-size: 0.9rem; }
.picks-breakdown-table .td-result { text-align: center; }
.picks-breakdown-table .td-points { text-align: right; white-space: nowrap; }
.picks-breakdown-table tfoot .total-row td { border-top: 2px solid var(--border); background: #f8f9fa; font-weight: bold; }
.picks-breakdown-table tfoot .total-label { text-align: right; color: var(--text-muted); }
.picks-breakdown-table tfoot .total-points { font-size: 1.15rem; color: var(--primary); }

/* ===== 省略テキスト吹き出し ===== */
.cell-tooltip {
  position: fixed;
  background: rgba(20,20,20,0.92);
  color: #fff;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  max-width: 220px;
  z-index: 2000;
  box-shadow: 0 3px 14px rgba(0,0,0,0.35);
  white-space: normal;
  line-height: 1.5;
  display: none;
  pointer-events: none;
}
.cell-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: var(--arrow-left, 50%);
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(20,20,20,0.92);
}
.cell-tooltip.tip-below::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: rgba(20,20,20,0.92);
}

/* ===== フッター ===== */
footer {
  background: linear-gradient(135deg, var(--primary-dark) 0%, #2c7030 100%);
  color: rgba(255,255,255,0.7); text-align: center; padding: 1rem; font-size: 0.85rem;
}

/* ===== モーダル ===== */
.modal {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center;
}
.modal-content {
  background: white; padding: 2rem; border-radius: 12px; min-width: 340px; max-width: 500px;
}

/* ===== 管理画面共通 ===== */
.action-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 0.5rem;
}
.horse-add-form {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  align-items: center; margin-bottom: 1rem;
}
.horse-add-form .form-control { flex: 1; min-width: 80px; width: auto; }
.horse-add-form .form-control.small { flex: 0 0 70px; }
.info-table { max-width: 500px; }
.info-table th { width: 160px; }

/* モバイルで非表示にする管理テーブル列 */
.col-hide-mobile { /* デフォルト表示 */ }

/* ===== レスポンシブ ===== */
@media (max-width: 600px) {
  .container { padding: 1rem 0.75rem; }

  /* ナビ */
  .navbar { flex-direction: column; gap: 0.4rem; padding: 0.6rem 1rem; }
  .nav-links { flex-wrap: wrap; gap: 0.35rem; justify-content: center; }
  .nav-links a { font-size: 0.78rem; }
  .user-name { font-size: 0.78rem; }

  /* レースカード */
  .race-cards { grid-template-columns: 1fr; }
  .race-name { font-size: 0.9rem; }

  /* 日付・受付状態と名前を分け、海外の長い略称も横幅いっぱいに表示する。 */
  .upcoming-race-item {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "date status" "name name";
    gap: 0.35rem 0.75rem;
    padding: 0.65rem 0.75rem;
  }
  .upcoming-race-date { grid-area: date; min-width: 0; }
  .upcoming-race-name { grid-area: name; }
  .upcoming-race-status { grid-area: status; justify-self: end; }

  /* テーブル */
  .table th, .table td { padding: 0.5rem 0.5rem; font-size: 0.82rem; }

  /* ランキング */
  .ranking-nav { flex-direction: column; gap: 0.5rem; }
  .ranking-links { flex-direction: column; gap: 0.5rem; }

  /* 内訳ページ */
  .picks-page-header { flex-direction: column; align-items: flex-start; }
  .picks-page-header .btn { align-self: flex-start; white-space: nowrap; }

  /* 予想ボタン */
  .pick-actions { flex-direction: column; align-items: stretch; }
  .btn-lg { text-align: center; }

  /* 名前の表示幅を確保するため、予想のラベルだけを上段に置く。 */
  .prediction-summary { display: block; }
  .prediction-summary-label { display: block; margin-bottom: 0.15rem; font-size: 0.85rem; }

  /* セクション見出し */
  .section h2 { font-size: 1rem; }

  /* ページタイトル */
  h1 { font-size: 1.4rem; }
  .race-header h1 { font-size: 1.3rem; }

  /* 結果テーブル: 騎手列を非表示 */
  .result-table th:last-child,
  .result-table td:last-child { display: none; }

  /* 国旗・バッジ・名前を同じ行に収め、狭い画面でも日程とポイントを確保する。 */
  .home-results-table th:first-child { width: 4.2em; }
  .home-results-table th:last-child { width: 5.3em; }
  .home-results-table .race-list-label { gap: 0.25rem; }
  .home-results-table .race-country-flag { width: 20px; }
  /* 日程・ポイント列を折り返し禁止にする。 */
  .home-results-table th:first-child,
  .home-results-table td:first-child { white-space: nowrap; }
  .home-results-table th:last-child,
  .home-results-table td:last-child { white-space: nowrap; }

  /* 管理画面: モバイル不要列を非表示 */
  .col-hide-mobile { display: none; }

  /* 管理画面: スクロール可能テーブルはセル折り返し禁止 */
  .table-responsive td { white-space: nowrap; }
  /* 内訳テーブル: 固定レイアウトで4列を375pxに収める（着順列は非表示） */
  .picks-breakdown-table { table-layout: fixed; width: 100%; }
  .picks-breakdown-table th,
  .picks-breakdown-table td { padding: 0.5rem 0.3rem; font-size: 0.78rem; white-space: nowrap; overflow: hidden; }
  .picks-breakdown-table thead th:nth-child(4),
  .picks-breakdown-table tbody td:nth-child(4) { display: none; }
  .picks-breakdown-table th:nth-child(1), .picks-breakdown-table td:nth-child(1) { width: 13%; }
  .picks-breakdown-table th:nth-child(2), .picks-breakdown-table td:nth-child(2) { width: 40%; text-overflow: ellipsis; }
  .picks-breakdown-table th:nth-child(3), .picks-breakdown-table td:nth-child(3) { width: 31%; text-overflow: ellipsis; }
  .picks-breakdown-table th:nth-child(5), .picks-breakdown-table td:nth-child(5) { width: 16%; text-align: right; }
  .picks-breakdown-table tfoot .total-points { font-size: 0.85rem; }

  /* 管理画面: 馬追加フォームを縦積みに */
  .horse-add-form { flex-direction: column; align-items: stretch; }
  .horse-add-form .form-control,
  .horse-add-form .form-control.small { flex: none; width: 100%; }
}


/* ===== ガチャ & コレクション ===== */

/* ポイントバー */
.gacha-points-bar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.8rem 1.2rem; margin-bottom: 1.2rem;
}
.gacha-points-info { display: flex; align-items: baseline; gap: 0.5rem; }
.gacha-points-label { font-size: 0.85rem; color: var(--text-muted); }
.gacha-points-value { font-size: 1.4rem; font-weight: bold; color: var(--primary); }
.gacha-stats { font-size: 0.85rem; color: var(--text-muted); display: flex; gap: 1rem; }
.gacha-stats a { margin-left: auto; }
.gacha-no-points { text-align: center; color: var(--text-muted); margin: 1rem 0; font-size: 0.9rem; }

/* 排出率 */
.gacha-rates-detail {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.8rem 1.2rem; margin-bottom: 1.2rem;
}
.gacha-rates-detail summary { cursor: pointer; font-size: 0.9rem; color: var(--text-muted); }
.gacha-rates-content { margin-top: 0.8rem; }
.gacha-rates-table { width: auto; border-collapse: collapse; font-size: 0.9rem; margin-bottom: 0.5rem; }
.gacha-rates-table th, .gacha-rates-table td { padding: 0.3rem 1rem; border: 1px solid var(--border); text-align: center; }
.gacha-note { font-size: 0.82rem; color: var(--text-muted); }

/* ガチャボタンエリア */
.gacha-pull-area { display: flex; gap: 1rem; margin: 1.5rem 0; flex-wrap: wrap; }
.btn-gacha-single, .btn-gacha-ten {
  display: flex; flex-direction: column; align-items: center;
  padding: 1rem 2rem; border-radius: 12px; border: none;
  cursor: pointer; font-family: inherit; transition: transform 0.1s, opacity 0.2s;
  min-width: 150px;
}
.btn-gacha-single:active, .btn-gacha-ten:active { transform: scale(0.97); }
.btn-gacha-single {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
}
.btn-gacha-ten {
  background: linear-gradient(135deg, #8b6914, #d4a017);
  color: white;
}
.btn-gacha-single.disabled, .btn-gacha-ten.disabled { opacity: 0.45; cursor: not-allowed; }
.gacha-btn-label { font-size: 1rem; font-weight: bold; }
.gacha-btn-cost { font-size: 0.85rem; opacity: 0.85; margin-top: 0.2rem; }

/* レアリティバッジ（汎用） */
.rarity-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 0.75rem; font-weight: 800; letter-spacing: 0.05em;
}
.rarity-badge.rarity-SR { background: #1a3580; color: #ffd700; border: 1px solid #ffd700; }
.rarity-badge.rarity-R  { background: #6a1a8a; color: #e0aaff; border: 1px solid #e0aaff; }
.rarity-badge.rarity-N  { background: #2c5f2e; color: #a8d5a2; border: 1px solid #a8d5a2; }

/* 記念カード：上部のレース名・写真・下部の銘板を全画面で共用する。 */
.gacha-card {
  --card-ink: #0e192b;
  --card-accent: #c7a78a;
  container-type: inline-size;
  width: 100%; min-width: 0; aspect-ratio: 2 / 3;
  padding: 4%; position: relative; overflow: hidden;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--card-ink); color: var(--card-accent);
  border: 1px solid var(--card-ink); border-radius: 12px;
  box-shadow: 0 4px 12px rgba(8,18,32,0.2);
  font-family: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
}
.gacha-card::before {
  content: ''; position: absolute; inset: 2%; z-index: 2;
  border: 3px double var(--card-accent); border-radius: 8px; pointer-events: none;
}
.gacha-card.rarity-SR { --card-accent: #dfbc71; }
.gacha-card.rarity-R { --card-accent: #c9d6e5; }
.gacha-card.color-blue   { --card-ink: #0e192b; }
.gacha-card.color-gold   { --card-ink: #231e13; }
.gacha-card.color-green  { --card-ink: #102421; }
.gacha-card.color-purple { --card-ink: #1b1830; }
.gacha-card.color-red    { --card-ink: #29181e; }
.gacha-card.color-orange { --card-ink: #281d17; }
.gacha-card.color-pink   { --card-ink: #291a29; }
.gacha-card-header {
  min-width: 0; padding: 0 2% 2%;
  display: flex; align-items: center; gap: 4%;
  border-bottom: 1px solid var(--card-accent);
}
.gacha-card-rarity-badge {
  flex-shrink: 0; color: var(--card-accent);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(1rem, 6.8cqi, 2rem); font-weight: bold; line-height: 1.1;
}
.gacha-card-new-badge {
  position: absolute; top: 5px; right: 5px; z-index: 2;
  background: #922e36; color: #fff; font-size: 0.65rem; font-weight: bold;
  font-family: 'Helvetica Neue', Arial, Meiryo, sans-serif;
  padding: 1px 5px; border-radius: 3px;
}
.gacha-card-image { position: relative; min-height: 0; overflow: hidden; background: var(--card-ink); }
.gacha-card-image > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.gacha-card-image.is-manual > img { object-fit: cover; }
.gacha-card-image.has-overlay::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  border: 1px solid var(--card-accent);
}
.gacha-card-body {
  min-width: 0; padding: 5% 2% 2%; text-align: center;
  border-top: 1px solid var(--card-accent);
}
.gacha-card-name {
  font-size: clamp(0.85rem, 8cqi, 2rem); font-weight: bold; line-height: 1.35;
  overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; overflow: hidden;
}
.gacha-card-race {
  min-width: 0; flex: 1; font-size: clamp(0.625rem, 4.3cqi, 1.15rem); line-height: 1.4;
  overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; overflow: hidden; text-align: center;
}
.gacha-card-jockey { font-size: clamp(0.625rem, 3.6cqi, 0.9rem); line-height: 1.4; margin-top: 3px; color: #d7d9df; }
.gacha-card-jockey:empty { display: none; }
.gacha-card-brand { font-size: clamp(0.625rem, 5cqi, 1.1rem); line-height: 1.4; }
.gacha-card-corner, .gacha-card-divider {
  /* 輝度マスクで装飾画像の黒地を抜き、3Dフリップ中も枠色を保つ。 */
  display: block; background: var(--card-accent);
  pointer-events: none; user-select: none;
}
.gacha-card-corner {
  position: absolute; z-index: 3; width: 10%; aspect-ratio: 1;
  mask: url('../img/gacha/classic-corner.png') center / contain no-repeat;
  mask-mode: luminance;
}
.corner-top-left { top: -0.5%; left: -0.5%; }
.corner-top-right { top: -0.5%; right: -0.5%; transform: rotate(90deg); }
.corner-bottom-left { bottom: -0.5%; left: -0.5%; transform: rotate(-90deg); }
.corner-bottom-right { bottom: -0.5%; right: -0.5%; transform: rotate(180deg); }
.gacha-card-divider {
  width: 78%; height: clamp(7px, 3cqi, 12px); margin: 3% auto;
  mask: url('../img/gacha/classic-divider.png') center / cover no-repeat;
  mask-mode: luminance;
}

/* ガチャ結果グリッド */
.gacha-result-section { margin-top: 2rem; scroll-margin-top: 1rem; }
.gacha-result-title { font-size: 1.3rem; margin-bottom: 1rem; text-align: center; }
.gacha-result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}
.gacha-result-actions { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; }

/* 結果のカードだけを裏面から順に公開する（単発0.9秒、10連1.89秒）。 */
.gacha-result-grid.gacha-result-single {
  grid-template-columns: minmax(0, 280px);
  justify-content: center;
}
.gacha-result-slot { min-width: 0; display: grid; perspective: 800px; }
.gacha-result-flip { display: grid; transform-style: preserve-3d; }
.gacha-result-flip > .gacha-card,
.gacha-card-back {
  grid-area: 1 / 1;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.gacha-result-flip > .gacha-card,
.gacha-result-flip .gacha-card-new-badge { animation: none; }
.gacha-result-flip > .gacha-card.rarity-SR { box-shadow: 0 4px 16px rgba(0,0,0,0.18); }
.gacha-card-back {
  display: grid; place-content: center; gap: 0.6rem;
  min-height: 190px; padding: 1rem;
  transform: rotateY(180deg);
  border: 2px solid #c9a85e; border-radius: 12px;
  background: #0e192b;
  color: #dfbc71; text-align: center;
  box-shadow: inset 0 0 0 6px #0e192b, inset 0 0 0 7px #c9a85e;
}
.gacha-card-back-mark { font-size: 2rem; line-height: 1; }
.is-revealing .gacha-result-flip {
  animation: gacha-card-flip 0.65s cubic-bezier(0.3, 0.1, 0.2, 1) both;
  animation-delay: calc(0.25s + var(--reveal-index) * 0.11s);
}
.is-revealing .gacha-result-flip > .gacha-card.rarity-SR {
  animation: gacha-card-glow 0.4s ease-out both;
  animation-delay: calc(0.9s + var(--reveal-index) * 0.11s);
}
@keyframes gacha-card-flip {
  from { transform: rotateY(180deg); }
  to { transform: rotateY(0); }
}
@keyframes gacha-card-glow {
  0%, 100% { box-shadow: 0 4px 16px rgba(0,0,0,0.18); }
  45% { box-shadow: 0 0 14px rgba(255,215,0,0.4), 0 4px 16px rgba(0,0,0,0.18); }
}
@media (prefers-reduced-motion: reduce) {
  .is-revealing .gacha-result-flip,
  .is-revealing .gacha-result-flip > .gacha-card.rarity-SR { animation: none; }
}

/* アニメーション */
@keyframes gacha-reveal {
  from { opacity: 0; transform: scale(0.65) rotateY(90deg); }
  to   { opacity: 1; transform: scale(1) rotateY(0); }
}
@keyframes new-badge-pop {
  0%   { transform: scale(0); }
  70%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* コレクションページ */
.collection-header {
  display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 0.8rem;
}
.collection-header-info { display: flex; gap: 1rem; font-size: 0.9rem; color: var(--text-muted); }
.collection-count { font-weight: bold; }
.collection-actions { margin-bottom: 1.2rem; }
.collection-section { margin-bottom: 2rem; }
.collection-section-title {
  font-size: 1rem; margin-bottom: 0.8rem;
  display: flex; align-items: center; gap: 0.5rem;
  padding-bottom: 0.4rem; border-bottom: 1px solid var(--border);
}
.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}
.collection-card-wrap { position: relative; min-width: 0; }
.collection-card-count {
  position: absolute; top: -8px; right: -8px; z-index: 3;
  background: var(--warning); color: white;
  font-size: 0.72rem; font-weight: bold;
  border-radius: 50%; width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.collection-empty { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.collection-empty p { margin-bottom: 1rem; }

/* 管理画面: カラードット */
.color-dot { font-size: 0.8rem; padding: 2px 8px; border-radius: 10px; color: white; font-weight: bold; }
.color-dot.color-blue   { background: #1a3580; }
.color-dot.color-gold   { background: #8b6914; }
.color-dot.color-green  { background: #2c5f2e; }
.color-dot.color-purple { background: #6a1a8a; }
.color-dot.color-red    { background: #8b0a0a; }
.color-dot.color-orange { background: #8b4500; }
.color-dot.color-pink   { background: #8b1a50; }

/* 管理画面: 代表レースセル */
.notable-race-cell { font-size: 0.82rem; max-width: 220px; }

/* レスポンシブ */
@media (max-width: 600px) {
  .gacha-pull-area { flex-direction: column; }
  .btn-gacha-single, .btn-gacha-ten { width: 100%; }
  .gacha-result-grid { grid-template-columns: repeat(2, 1fr); }
  .collection-grid  { grid-template-columns: repeat(2, 1fr); }
  .gacha-points-bar { flex-direction: column; align-items: flex-start; }
}

/* 海外は国内の枠色と区別し、ゲート番号を表示する。 */
.race-country-flag { display: inline-block; width: 24px; height: auto; margin-right: .35em; vertical-align: -.1em; }
.overseas-gate { background: #e7f0f4; color: #245469; }
.horse-card.scratched { opacity: .55; cursor: not-allowed; }

.overseas-race-time { display: block; }
