/* 住信SBIネット銀行のブランドカラー(青・緑・赤)を基調にした配色 */
:root {
  --brand-blue: #0058A0;
  --brand-blue-dark: #00447d;
  --brand-green: #00AB84;
  --brand-red: #E7242E;
  --bg: #f4f7fa;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5eaef;
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Noto Sans JP", "Hiragino Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

/* 見出しの背景: 走るボート+航跡+スピード線のイラスト(自作SVG、水面のグラデーション付き) */
.hero {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  margin: 0 0 1.5rem;
  padding: 2.2rem 1.75rem;
  background-color: var(--brand-blue-dark);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 900 260'%3E%3Cdefs%3E%3ClinearGradient id='sky' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%230058A0'/%3E%3Cstop offset='1' stop-color='%2300335f'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='900' height='260' fill='url(%23sky)'/%3E%3Cpath d='M0,185 Q110,165 220,185 T440,185 T660,185 T880,185 L900,185 L900,260 L0,260 Z' fill='%23004b8c' opacity='0.55'/%3E%3Cpath d='M0,208 Q110,192 220,208 T440,208 T660,208 T880,208 L900,208 L900,260 L0,260 Z' fill='%23003b70' opacity='0.7'/%3E%3Cg stroke='%23ffffff' stroke-opacity='0.3' stroke-width='5' stroke-linecap='round'%3E%3Cline x1='470' y1='118' x2='580' y2='104'/%3E%3Cline x1='450' y1='140' x2='570' y2='126'/%3E%3Cline x1='430' y1='162' x2='560' y2='148'/%3E%3C/g%3E%3Cellipse cx='700' cy='184' rx='55' ry='10' fill='%23ffffff' opacity='0.28'/%3E%3Cpath d='M760,178 Q790,168 815,178' stroke='%23ffffff' stroke-opacity='0.35' stroke-width='4' fill='none' stroke-linecap='round'/%3E%3Cpath d='M620,150 L672,150 L735,168 L672,186 L620,186 Q594,186 594,168 Q594,150 620,150 Z' fill='%23ffffff'/%3E%3Cpath d='M636,150 L636,126 L656,150 Z' fill='%23ffffff'/%3E%3Cpath d='M636,150 L636,126 L656,150 Z' fill='%2300AB84' opacity='0.85'/%3E%3Ccircle cx='656' cy='168' r='6' fill='%23E7242E'/%3E%3C/svg%3E");
  background-size: cover;
  background-position: center;
}

.hero h1 {
  position: relative;
  color: #ffffff;
  font-size: 1.9rem;
  margin: 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.notice {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.notice a {
  color: var(--brand-blue);
}

/* 「結果を見る」「選手で検索」の上部モードタブ */
.mode-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}

.mode-tab {
  border: none;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.6rem 0.25rem;
  margin-bottom: -2px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.mode-tab.active {
  color: var(--brand-blue);
  border-bottom-color: var(--brand-blue);
}

/* レース場・日付・選手名などの入力欄をまとめたカード */
.controls {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  padding: 1.25rem 1.5rem;
  display: flex;
  gap: 1.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.controls label {
  display: flex;
  flex-direction: column;
  font-size: 0.78rem;
  color: var(--muted);
  gap: 0.35rem;
}

.controls select,
.controls input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
}

#fetchBtn {
  background: var(--brand-blue);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.75rem;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}

#fetchBtn:hover {
  background: var(--brand-blue-dark);
}

#status {
  font-size: 0.85rem;
  color: var(--brand-green);
  font-weight: 700;
  min-height: 1.2em;
  margin-bottom: 0.75rem;
}

/* レースごとのタブ(1R, 2R...) */
.race-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.race-tab {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.race-tab:hover {
  background: #eef3f8;
}

.race-tab.active {
  background: var(--brand-blue);
  color: #fff;
  border-color: var(--brand-blue);
}

/* 結果テーブル・払戻金テーブル共通のカード風スタイル */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card-bg);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* 選手検索テーブルは列数が多いため、はみ出す場合は横スクロールさせる */
.table-scroll {
  overflow-x: auto;
  border-radius: 16px;
}

.table-scroll table {
  box-shadow: none;
}

thead th {
  background: var(--brand-blue);
  color: #fff;
  font-weight: 700;
  padding: 0.75rem 0.6rem;
  text-align: left;
  font-size: 0.8rem;
}

tbody td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #f7fafc;
}

/* 1着の行を緑色・太字で強調する */
.place-first {
  color: var(--brand-green);
  font-weight: 700;
}

/* レース名・グレード表示 */
.race-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.75rem;
}

/* 決まり手バッジ(例: まくり) */
.technique-badge {
  display: inline-block;
  background: #eaf7f3;
  color: var(--brand-green);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
}

/* グレードバッジ(SG/PG1/G1/G2/G3/一般) */
.grade-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  background: var(--muted);
}

.grade-SG { background: var(--brand-red); }
.grade-PG1 { background: #b8860b; }
.grade-G1 { background: var(--brand-blue); }
.grade-G2 { background: #6b8fc7; }
.grade-G3 { background: #9aa5b1; }
.grade-一般 { background: var(--muted); }

/* 「表形式」「グラフ形式」の切り替えタブ(race-tabと同じ見た目) */
.view-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.view-tab {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.view-tab:hover {
  background: #eef3f8;
}

.view-tab.active {
  background: var(--brand-blue);
  color: #fff;
  border-color: var(--brand-blue);
}

.graph-caption {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

/* 着順推移グラフ: 横スクロールするSVGを収めるカード */
.graph-scroll {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  padding: 1rem 0.5rem;
  overflow-x: auto;
}

.graph-scroll svg {
  display: block;
}

/* 着順の目盛線(1着〜6着)。控えめな破線 */
.graph-gridline {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.graph-axis-label {
  fill: var(--muted);
  font-size: 10px;
  font-family: inherit;
}

/* 着順を結ぶ折れ線 */
.graph-line {
  fill: none;
  stroke: var(--brand-blue);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* 各レースの着順ドット(1着だけ緑で強調、表形式のplace-firstと合わせる) */
.graph-dot {
  fill: var(--brand-blue);
  stroke: var(--card-bg);
  stroke-width: 1.5;
}

.graph-dot.graph-dot-first {
  fill: var(--brand-green);
}

/* ドット本体より一回り大きい透明な当たり判定(ホバーしやすくするため) */
.graph-dot-hit {
  fill: transparent;
  cursor: pointer;
}

/* ホバー時に表示するツールチップ(clientX/clientY基準なのでfixed配置) */
.graph-tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 0.5rem 0.7rem;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 10;
}

.graph-tooltip.visible {
  opacity: 1;
}

/* 得点率(選手検索の集計結果) */
.score-rate {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--brand-blue);
  margin: 0 0 0.75rem;
}

/* 得点・グレード計算がベストエフォート推定であることを示す注記 */
.estimate-note {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.5rem;
  line-height: 1.5;
}

.section-title {
  color: var(--brand-blue);
  font-size: 1.05rem;
  margin: 1.5rem 0 0.75rem;
}

/* スタート隊形(簡易模式図)のカード */
.start-slit {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.slit-caption {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

/* コースごとの1行(進入コース番号 + トラック + STタイミング) */
.slit-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.3rem 0;
}

.slit-course {
  width: 4.2rem;
  flex-shrink: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* 艇のバッジ(slit-marker)を位置指定で乗せるための土台 */
.slit-track {
  position: relative;
  flex: 1;
  height: 1.8rem;
  background: #f4f7fa;
  border-radius: 999px;
}

/* スタート信号(0.00秒)の基準線。右端に固定表示する */
.slit-line {
  position: absolute;
  right: 0;
  top: -4px;
  bottom: -4px;
  width: 2px;
  background: var(--brand-red);
}

/* STタイミングの値に応じてJSからstyle="left:◯%"が設定される艇アイコン */
.slit-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
}

/* スタート隊形のボート形アイコン(SVG) */
.boat-icon {
  display: block;
  width: 2.4rem;
  height: 1.3rem;
}

.slit-st {
  width: 2.8rem;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.78rem;
  color: var(--muted);
}

/* 艇番バッジの共通スタイル */
.boat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
}

/* 艇番ごとの色分け(競艇の慣習色: 1=白,2=黒,3=赤,4=青,5=黄,6=緑) */
.boat-1 { background: #ffffff; color: #1a1a1a; border: 2px solid #1a1a1a; }
.boat-2 { background: #1a1a1a; color: #ffffff; }
.boat-3 { background: #E2231A; color: #ffffff; }
.boat-4 { background: #0068B7; color: #ffffff; }
.boat-5 { background: #FFF100; color: #1a1a1a; }
.boat-6 { background: #009944; color: #ffffff; }

/* ==========================================================================
   スマートフォンサイズ(画面幅640px以下)向けの調整
   ========================================================================== */
@media (max-width: 640px) {
  body {
    padding: 1.25rem 1rem 3rem;
  }

  .hero {
    padding: 1.5rem 1.25rem;
    border-radius: 14px;
  }

  .hero h1 {
    font-size: 1.35rem;
  }

  /* 入力欄をカードいっぱいに縦積みにして、指でも押しやすくする */
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.9rem;
    padding: 1rem 1.1rem;
  }

  /* flexアイテムはデフォルトでmin-width:autoのため、中身(特にネイティブの
     日付入力部品)の実寸が幅を決めてしまい、100%指定してもはみ出すことがある。
     min-width:0で明示的に縮小を許可する */
  .controls label {
    min-width: 0;
  }

  .controls select,
  .controls input,
  #fetchBtn,
  #searchBtn {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  /* iOS Safariの<input type="date">はネイティブ部品の都合でwidth指定を
     無視して右にはみ出すことがあるため、標準の見た目を解除して確実に幅を守らせる */
  .controls input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
  }

  #fetchBtn,
  #searchBtn {
    padding: 0.75rem 1.5rem;
  }

  /* テーブルは横スクロールに任せつつ、文字サイズを少し詰めて見切れを減らす */
  thead th {
    padding: 0.6rem 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  tbody td {
    padding: 0.5rem;
    font-size: 0.82rem;
    white-space: nowrap;
  }

  /* スタート隊形: コース名・STタイミングの幅を詰めてトラック部分を広く確保する */
  .slit-course {
    width: 3.2rem;
    font-size: 0.7rem;
  }

  .slit-st {
    width: 2.2rem;
    font-size: 0.7rem;
  }

  .boat-icon {
    width: 2rem;
    height: 1.1rem;
  }

  .race-tabs,
  .view-tabs,
  .mode-tabs {
    gap: 0.4rem;
  }

  .race-tab,
  .view-tab {
    padding: 0.35rem 0.8rem;
    font-size: 0.8rem;
  }
}
