/* ========= リセット・ベース ========= */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ========= カラー変数 ========= */
:root {
  --bg:         #F7F4EF;
  --card:       #FFFFFF;
  --border:     #D9D4CA;
  --text:       #3D3B38;
  --text-sub:   #7A7570;
  --text-muted: #B0AAA3;
  --accent:     #5C8A5A;
  --accent-bg:  #EBF1EA;
  --gold:       #A08C5B;
  --silver:     #8A8883;
  --bronze:     #9E7B5A;
  --live:       #C0392B;
  --live-bg:    #FDF0EE;
  --radius:     2px;
}

/* ========= カバーエリア（site-header） ========= */
.site-header {
  background: #2D4F2C;
  padding: 32px 40px 28px;
}
.site-header-inner {
  max-width: 1170px;
  margin: 0 auto;
}
.site-header-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  color: rgba(255,255,255,0.5);
  margin-bottom: 8px;
  font-weight: 400;
}
.cover-tournament-name {
  font-size: 22px;
  font-weight: 300;
  color: #fff;
  letter-spacing: 0.05em;
}
.cover-meta {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  margin-top: 6px;
  letter-spacing: 0.03em;
}

/* ========= ページ本体 ========= */
.notion-page {
  max-width: 1170px;
  margin: 0 auto;
  padding: 40px 32px 100px;
}

/* ========= 大会タイトル ========= */
h1.page-title {
  font-size: 28px;
  font-weight: 300;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  padding-top: 20px;
  color: var(--text);
}
.page-meta {
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 28px;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

/* ========= バッジ ========= */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-live {
  background: #C0392B;
  color: #fff;
  animation: badge-pulse 1.4s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(192, 57, 43, 0.35);
}
@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.72; }
}
.badge-done {
  background: var(--accent);
  color: #fff;
}
.badge-upcoming {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ========= ビュー切替タブ ========= */
.view-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.view-tab {
  padding: 14px 28px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
  user-select: none;
  letter-spacing: 0.02em;
}
.view-tab:hover { color: var(--text); }
.view-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.view-content { display: none; }
.view-content.active { display: block; }

/* ========= フィルタバー ========= */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-bar label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.05em;
}
.filter-select {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--card);
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.2s ease;
}
.filter-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.filter-search {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  width: 180px;
  color: var(--text);
  font-family: inherit;
  background: var(--card);
  transition: border-color 0.2s ease;
}
.filter-search:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.filter-search::placeholder { color: var(--text-muted); }
.filter-reset {
  padding: 5px 12px;
  border: none;
  background: none;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-sub);
  font-family: inherit;
  transition: color 0.2s ease;
}
.filter-reset:hover { color: var(--text); }
.filter-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ========= トグル（種目ブロック） ========= */
.toggle {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--card);
  transition: border-color 0.2s ease;
}
.toggle.open {
  border-left: 3px solid var(--accent);
}
.toggle-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s ease;
  gap: 10px;
}
.toggle-header:hover { background: #FAF8F4; }
.toggle-arrow {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  width: 16px;
}
.toggle.open .toggle-arrow { transform: rotate(90deg); }
.toggle-title {
  font-weight: 400;
  font-size: 15px;
  flex: 1;
  color: var(--text);
}
.toggle-code {
  font-size: 11px;
  color: var(--text-muted);
  background: #F0EDE7;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-family: monospace;
  letter-spacing: 0.03em;
}
.toggle-count { font-size: 12px; color: var(--text-muted); }
.toggle-body { display: none; padding: 0 16px 16px; }
.toggle.open .toggle-body { display: block; }

/* ========= レース結果テーブル ========= */
.race-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  margin-top: 14px;
  padding: 8px 12px;
  background: #FAF8F4;
  border-radius: var(--radius);
}
.race-label {
  font-weight: 400;
  font-size: 14px;
  color: var(--text);
}
.race-info { font-size: 12px; color: var(--text-sub); }

.result-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.result-table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 8px;
}
.result-table th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: #FAF8F4;
  white-space: nowrap;
}
.result-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #F0EDE7;
  color: var(--text);
  white-space: nowrap;
}
.result-table tr:hover td { background: #FAF8F4; }

/* 1位行: 左に gold の 3px ボーダー */
.rank-1 td:first-child {
  color: var(--gold);
  font-weight: 600;
  border-left: 3px solid var(--gold);
  padding-left: 7px;
}
.rank-2 td:first-child { color: var(--silver); }
.rank-3 td:first-child { color: var(--bronze); }

.crew-name { font-weight: 400; color: var(--text); white-space: nowrap; }
.affiliation-cell { white-space: nowrap; }
.time-main {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--text);
}
.time-split {
  font-variant-numeric: tabular-nums;
  color: var(--text-sub);
  font-size: 12px;
}
.time-half { font-size: 11px; color: var(--text-muted); }

/* 結果なし */
.no-result {
  color: var(--text-muted);
  font-size: 13px;
  padding: 14px 0;
}

/* ========= 全レーステーブル（DBビュー） ========= */
.db-table-wrapper { overflow-x: auto; }
.db-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.db-table th {
  padding: 9px 10px;
  text-align: left;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: #FAF8F4;
  position: sticky;
  top: 0;
  cursor: pointer;
  white-space: nowrap;
}
.db-table th:hover { background: #F0EDE7; }
.db-table th .sort-icon { font-size: 10px; margin-left: 2px; color: var(--text-muted); }
.db-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #F0EDE7;
  white-space: nowrap;
  color: var(--text);
}
.db-table tr:hover td { background: #FAF8F4; }
.db-code {
  font-family: monospace;
  background: var(--accent-bg);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: var(--radius);
  font-size: 11px;
}
.db-round {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: var(--radius);
}
.db-round-fa { background: var(--live-bg); color: var(--live); }
.db-round-h { background: var(--accent-bg); color: var(--accent); }
.db-round-rk { background: #F0EDE7; color: var(--text-sub); }

/* ========= ステータスバー ========= */
.update-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #3D3B38;
  color: #fff;
  padding: 0 24px;
  height: 44px;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  gap: 8px;
}
.update-bar-left {
  display: flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}
.update-bar-center {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  text-align: center;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}
.hide-mobile-flex { display: flex; justify-content: center; }
.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 6px;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1}50%{opacity:0.4} }

/* ========= YouTube埋め込み ========= */
.youtube-wrapper {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  margin-bottom: 28px;
  border-radius: var(--radius);
  background: #000;
  border: 1px solid var(--border);
}
.youtube-wrapper iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: 0;
}

/* ========= ローディング ========= */
.loading {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 14px;
}
.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========= レスポンシブ ========= */
@media (max-width: 768px) {
  .site-header { padding: 24px 20px 20px; }
  .notion-page { padding: 20px 14px 80px; }
  h1.page-title { font-size: 22px; }
  .filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 10px 10px;
    gap: 8px;
    overflow-x: visible;
  }
  .filter-bar label { display: none; }
  .filter-search {
    grid-column: 1 / -1; /* 検索ボックスはフル幅 */
    font-size: 16px; /* iOS自動ズーム防止（16px未満だとピンチイン） */
    padding: 10px 12px;
    min-height: 44px;
    width: 100%;
    box-sizing: border-box;
  }
  .filter-select {
    font-size: 14px;
    padding: 10px 8px;
    min-height: 44px;
    width: 100%;
    box-sizing: border-box;
  }
  .filter-reset {
    font-size: 14px;
    padding: 10px 12px;
    min-height: 44px;
  }
  .filter-count {
    grid-column: 1 / -1;
    margin-left: 0;
    text-align: center;
  }
  .toggle-title { font-size: 13px; }
  .toggle-code { display: none; }
  .crew-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .result-table th:first-child,
  .result-table td:first-child { width: 28px; padding: 6px 4px; }
  .result-table th:nth-child(2),
  .result-table td:nth-child(2) { width: 22px; padding: 6px 4px; }
  .db-table { font-size: 12px; } /* 11px → 12px */
  .hide-mobile { display: none !important; }
  .update-bar { font-size: 11px; padding: 0 10px; }
  .hide-mobile-flex { display: none !important; }
  .schedule-table { font-size: 13px; } /* 12px → 13px */
  .sc-event-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
  .sc-winner { display: none; }
}

/* ========= スケルトンローディング ========= */
.skeleton {
  background: linear-gradient(90deg, #EDE9E3 25%, #E5E0D9 50%, #EDE9E3 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
@keyframes shimmer {
  0%  { background-position: 200% 0; }
  100%{ background-position: -200% 0; }
}
.skeleton-toggle {
  height: 44px;
  margin-bottom: 8px;
}
.skeleton-row td { padding: 10px 8px; }
.skeleton-cell {
  display: inline-block;
  height: 12px;
  border-radius: var(--radius);
}

/* ========= トースト通知 ========= */
#toast-container {
  position: fixed;
  bottom: 56px; /* ステータスバー(44px) + 余白 */
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
@media (max-width: 640px) {
  #toast-container {
    bottom: 52px;
    right: 12px;
    left: 12px;
  }
  .toast { max-width: 100%; }
}
.toast {
  background: #3D3B38;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: auto;
  max-width: 280px;
}
.toast.toast-show {
  opacity: 1;
  transform: translateY(0);
}
.toast.toast-hide {
  opacity: 0;
  transform: translateY(-6px);
}

/* ========= レースアンカーハイライト ========= */
.toggle.highlighted {
  border-color: var(--accent);
  border-left: 3px solid var(--accent);
}

/* ========= ステータスバー：手動更新ボタン ========= */
.refresh-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.85);
  padding: 6px 12px;
  min-height: 32px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s ease;
  margin-left: 10px;
  font-family: inherit;
}
.refresh-btn:hover { background: rgba(255,255,255,0.12); }
.refresh-btn:disabled { opacity: 0.4; cursor: default; }

/* ========= スケジュールビュー ========= */
.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.schedule-table th {
  padding: 9px 12px;
  text-align: left;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: #FAF8F4;
  white-space: nowrap;
}
.schedule-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #F0EDE7;
  color: var(--text);
}
.schedule-table tr:hover td { background: #FAF8F4; }

/* 日付セパレーター行 */
.schedule-date-sep td {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  font-weight: 400;
  padding: 6px;
  letter-spacing: 0.1em;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* 次のレース行のハイライト */
.schedule-next-race td {
  background: var(--accent-bg) !important;
}
.schedule-next-race .sc-time {
  font-weight: 600;
  color: var(--accent);
}

/* 列幅 */
.sc-time  { width: 52px; white-space: nowrap; }
.sc-no    { width: 60px; white-space: nowrap; font-size: 12px; color: var(--text-sub); }
.sc-event { }
.sc-event-name {
  display: block;
  white-space: nowrap;
  font-weight: 400;
}
.sc-round { width: 72px; font-size: 12px; color: var(--text-sub); white-space: nowrap; }
.sc-status { width: 72px; white-space: nowrap; }
.sc-winner { min-width: 180px; }
.sc-winner-name {
  display: block;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-sub);
}

/* ========= テーブルソートアイコン ========= */
.db-table th.sort-asc  .sort-icon::after { content: ' ↑'; color: var(--accent); }
.db-table th.sort-desc .sort-icon::after { content: ' ↓'; color: var(--accent); }
.db-table th .sort-icon { color: var(--text-muted); }

/* ========= ランク表示（絵文字廃止・シンプル数字） ========= */
.rank {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
}
.rank-1 { color: var(--gold); }
.rank-2 { color: var(--silver); }
.rank-3 { color: var(--bronze); }

/* ========= スケジュールビュー追加スタイル ========= */
/* 未実施レース行を薄く表示 */
.schedule-row-pending td {
  color: var(--text-muted);
}
/* 全レース確定時のフッターメッセージ */
.schedule-all-done {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 16px 0;
  letter-spacing: 0.05em;
}

/* ========= エラーカード ========= */
.error-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 360px;
  margin: 48px auto;
  text-align: center;
}
.error-icon {
  font-size: 32px;
  color: var(--text-muted);
  line-height: 1;
}
.error-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}
.error-body {
  font-size: 13px;
  color: var(--text-sub);
}
.error-card button {
  margin-top: 12px;
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.error-card button:hover { background: var(--accent-bg); }

/* ========= アーカイブバッジ ========= */
#archive-badge {
  display: none;
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--text-muted);
  border-radius: var(--radius);
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

/* ========= 年齢区分 中央揃え ========= */
.age-group { text-align: center; display: inline-block; min-width: 24px; }
td.age-group-cell { text-align: center; }

/* ========= スマホ専用UI（max-width: 640px） ========= */
@media (max-width: 640px) {
  /* ヘッダー */
  .site-header { padding: 20px 16px 18px; }
  .cover-tournament-name { font-size: 17px; }

  /* ページ本体 */
  .notion-page { padding: 20px 12px 88px; }
  h1.page-title { font-size: 20px; }

  /* タブ: 小さく */
  .view-tab { padding: 8px 10px; font-size: 12px; }

  /* フィルタ: 2列グリッドに */
  .filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .filter-search { grid-column: 1 / -1; width: 100%; }
  .filter-count  { grid-column: 1 / -1; }
  .filter-bar label { display: none; } /* "フィルタ:" ラベル非表示 */

  /* トグルヘッダー: 2行構成 */
  .toggle-header { flex-wrap: wrap; gap: 4px; }
  .toggle-code   { font-size: 10px; }
  .toggle-count  { font-size: 11px; }

  /* 結果テーブル: フォントさらに小さく */
  .result-table { font-size: 12px; }
  .result-table th { font-size: 10px; padding: 5px 4px; }
  .result-table td { padding: 6px 4px; }
  .time-main { font-size: 13px; }

  /* テーブルビュー: 横スクロール + フォント縮小 */
  .db-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .db-table { font-size: 11px; min-width: 600px; }

  /* スケジュールビュー: コンパクト */
  .schedule-table { font-size: 12px; }
  .sc-event-name { max-width: 90px; }

  /* ステータスバー */
  .update-bar { padding: 6px 12px; font-size: 11px; }
  .update-bar-center { display: none; } /* 次のレース情報は非表示 */
  #status-summary { font-size: 10px; }

  /* SP専用非表示クラス */
  .hide-sp { display: none !important; }
}

/* ========= 印刷用スタイル ========= */
@media print {
  .filter-bar, .view-tabs, .update-bar, .toggle-arrow, #toast-container { display: none !important; }
  body { background: #fff; }
  .toggle { border: 1px solid #ddd; }
  .toggle-body { display: block !important; }
  h1.page-title { font-size: 20px; }
  .site-header { display: none; }
  .notion-page { padding: 0; max-width: 100%; }
  .schedule-next-race td { background: none !important; }
}

/* 棄権・途中棄権 */
.row-retired td { color: var(--text-muted); }
.rank-dns, .rank-dnf { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.status-dns, .status-dnf { font-size: 12px; color: var(--text-muted); letter-spacing: 0.05em; }
/* エントリー個別の年齢区分（混合レース用） */
.entry-age-group { display: inline-block; margin-left: 5px; font-size: 10px; color: #555; background: #f0f0f0; border: 1px solid #ccc; border-radius: 3px; padding: 0 4px; vertical-align: middle; }

/* 日別タブ */
.day-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.day-tab {
  padding: 12px 20px;
  min-height: 48px;
  border: none;
  background: none;
  color: var(--text-sub);
  font-size: 14px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  margin-bottom: -1px;
}
.day-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.day-tab:hover:not(.active) {
  color: var(--text);
}
