:root {
  --brm-navy: #0d2b55;
  --brm-navy-light: #16407e;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #1b2733;
  --text-sub: #6b7787;
  --border: #e2e7ee;
  --win: #2e9c5a;
  --lose: #d64545;
  --today: #ffb300;
  --shadow: 0 2px 8px rgba(13, 43, 85, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ===== ヘッダー ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(135deg, var(--brm-navy), var(--brm-navy-light));
  color: #fff;
  padding: 14px 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}
.app-header__inner {
  display: flex;
  align-items: center;
  gap: 14px;
}
.app-header__titles { display: flex; flex-direction: column; }
.app-header__title { margin: 0; font-size: 1.35rem; letter-spacing: 0.02em; }
.app-header__subtitle { margin: 2px 0 0; font-size: 0.8rem; opacity: 0.85; }
.app-header__logo { display: inline-flex; flex-shrink: 0; }

/* チーム選択セレクタ */
.team-selector {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}
.team-selector[hidden] { display: none; }
.team-selector__label { opacity: 0.85; }
.team-selector select {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  font-size: 0.85rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  font-size: 0.78rem;
  opacity: 0.95;
}
.legend__item { display: inline-flex; align-items: center; gap: 5px; }

/* ===== チームロゴ ===== */
/* <img>（ロゴ画像）と .team-badge--text（略称フォールバック）の両方に適用される。 */
.team-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  object-fit: contain;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}
/* ロゴが無い場合のテキストバッジ（略称）。 */
.team-badge--text {
  background: var(--brm-navy);
  color: #fff;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}
.team-badge--sm { width: 30px; height: 30px; }
.team-badge--sm.team-badge--text { font-size: 0.62rem; }
.team-badge--lg { width: 64px; height: 64px; }
.team-badge--lg.team-badge--text { font-size: 1rem; }

/* ===== カレンダー ===== */
.calendar {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}
.calendar__loading,
.calendar__error {
  text-align: center;
  color: var(--text-sub);
  padding: 40px 0;
}
.calendar__error { color: var(--lose); }

.month {
  margin-bottom: 34px;
  scroll-margin-top: 120px;
}
.month__title {
  font-size: 1.05rem;
  margin: 0 0 10px;
  padding-left: 10px;
  border-left: 4px solid var(--brm-navy);
}
.month__title--current { color: var(--brm-navy); }
.month__title small { color: var(--text-sub); font-weight: normal; font-size: 0.78rem; margin-left: 8px; }

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.weekdays span {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-sub);
  padding: 2px 0;
}
.weekdays span:first-child { color: var(--lose); }   /* 日 */
.weekdays span:last-child { color: #2f7dd1; }         /* 土 */

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day {
  min-height: 76px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.day--empty { background: transparent; border: none; }
.day--today { border-color: var(--today); box-shadow: 0 0 0 2px rgba(255, 179, 0, 0.4); }
.day__num { font-size: 0.72rem; color: var(--text-sub); margin-bottom: 1px; }
.day--today .day__num { color: #b37700; font-weight: 700; }

/* ===== 試合カード（1試合1行 / 左=ホーム・右=アウェイ） ===== */
.match {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 6px;
  transition: background 0.15s;
  font-family: inherit;
}
.match:hover { background: #eef2f8; }
.match:focus-visible { outline: 2px solid var(--brm-navy); outline-offset: 1px; }
/* 同じ日に複数試合がある場合、2件目以降は区切り線で縦に並べる。 */
.match + .match { border-top: 1px solid var(--border); margin-top: 1px; padding-top: 4px; }

.match__side { flex-shrink: 0; }
.match__center {
  flex: 1;
  min-width: 18px;
  text-align: center;
}

.result-mark { font-weight: 700; font-size: 0.85rem; line-height: 1; }
.result-mark--win { color: var(--win); }
.result-mark--lose { color: var(--lose); }
.result-mark--scheduled { color: var(--text-sub); font-size: 0.62rem; font-weight: normal; }

/* 終了試合のスコア表示（左=ホーム - 右=アウェイ）。勝敗で色分け。 */
/* 配色は「勝ち=赤 / 負け=緑」。--lose(#d64545=赤) を勝ち、--win(#2e9c5a=緑) を負けに割当。 */
.match__score {
  font-weight: 700;
  font-size: 0.72rem;
  line-height: 1;
  white-space: nowrap;
  color: var(--text);
}
.match__score--win { color: var(--lose); }  /* 勝ち=赤 */
.match__score--lose { color: var(--win); }  /* 負け=緑 */

/* ===== モーダル ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal__overlay { position: absolute; inset: 0; background: rgba(13, 43, 85, 0.55); }
.modal__card {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  width: min(440px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  animation: pop 0.15s ease-out;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal__close {
  position: absolute; top: 8px; right: 12px;
  border: none; background: none; font-size: 1.8rem; line-height: 1;
  color: var(--text-sub); cursor: pointer;
}
.modal__close:hover { color: var(--text); }
.modal__body { padding: 24px; }

.md-status {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.md-status--finished { background: #eef6f0; color: var(--win); }
.md-status--scheduled { background: #eef2f8; color: var(--brm-navy); }

.md-teams {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 0 16px;
}
.md-team { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1; }
.md-team__name { font-size: 0.8rem; text-align: center; }
.md-score { font-size: 2.4rem; font-weight: 700; min-width: 48px; text-align: center; }
/* スコアは「勝ち=赤 / 負け=緑」で統一（カレンダーの .match__score と同配色）。 */
.md-score--win { color: var(--lose); }   /* 勝ち=赤 */
.md-score--lose { color: var(--win); }   /* 負け=緑 */
.md-vs { color: var(--text-sub); font-weight: 700; }

.md-meta { border-top: 1px solid var(--border); padding-top: 12px; font-size: 0.85rem; }
.md-meta__row { display: flex; justify-content: space-between; padding: 4px 0; }
.md-meta__row dt { color: var(--text-sub); }
.md-meta__row dd { margin: 0; font-weight: 600; }

.md-quarters { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 0.8rem; }
.md-quarters th, .md-quarters td { border: 1px solid var(--border); padding: 5px 8px; text-align: center; }
.md-quarters th { background: #f4f6fa; color: var(--text-sub); font-weight: 600; }
.md-quarters td:first-child { text-align: left; font-weight: 600; }

/* ===== レスポンシブ ===== */
@media (max-width: 640px) {
  .day { min-height: 64px; }
  .match__name { font-size: 0.58rem; }
  .app-header__title { font-size: 1.1rem; }
  .team-badge { width: 34px; height: 34px; }
}
