:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --text: #1a1a1a;
  --text-sub: #666;
  --border: #e3e6ea;
  --accent: #c8102e;
  --today: #fff8e1;
  --today-border: #f5b500;

  --pl: #3d195b;
  --elc: #0e7c86;
  --pd: #ee8707;
  --bl1: #d20515;
  --sa: #008fd7;
  --fl1: #1c2c5b;
  --ded: #ee5c1d;
  --cl: #00306e;

  --cl-promo: #d4f5d4;     /* 昇格・CL圏 */
  --cl-uel: #fff3c2;       /* EL圏 */
  --cl-relegate: #ffd6d6;  /* 降格圏 */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

header {
  padding: 16px 16px 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.updated {
  margin: 0;
  font-size: 12px;
  color: var(--text-sub);
}

.period {
  margin: 2px 0 10px;
  font-size: 12px;
  color: var(--text-sub);
}

.view-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 0 -16px;
  padding: 0 16px;
  overflow-x: auto;
}

.view-tab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}

.view-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.filters {
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.filters.hidden { display: none; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.toggle input { cursor: pointer; }

.league-filter { font-size: 14px; }

.league-filter summary {
  cursor: pointer;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.league-filter > div {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.league-filter label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.view.hidden { display: none; }

.loading, .empty {
  text-align: center;
  color: var(--text-sub);
  padding: 40px 0;
}

.date-heading {
  margin: 24px 0 8px;
  padding: 4px 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-sub);
  border-bottom: 2px solid var(--border);
}

.date-heading.today {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.match {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.match.today {
  background: var(--today);
  border-color: var(--today-border);
}

.match.finished { opacity: 0.78; }

.match-top {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.kickoff {
  font-size: 16px;
  font-weight: 700;
  font-feature-settings: "tnum";
  min-width: 56px;
  text-align: center;
}

.kickoff small {
  display: block;
  font-size: 11px;
  font-weight: normal;
  color: var(--text-sub);
}

.teams {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.team-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.team-crest {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  object-fit: contain;
}

.team-mid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
}

.team-name { flex-shrink: 0; }

.team-jp {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  background: #fff0f0;
  color: var(--accent);
  border: 1px solid #f4c0c0;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 500;
}

.team-score {
  font-weight: 700;
  font-feature-settings: "tnum";
  min-width: 22px;
  text-align: right;
}

.team-row.winner .team-name,
.team-row.winner .team-score { font-weight: 700; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  margin-top: 8px;
}

.league-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  color: white;
  font-weight: 600;
  font-size: 11px;
  white-space: nowrap;
}

.league-tag.cat-league-39 { background: var(--pl); }
.league-tag.cat-league-40 { background: var(--elc); }
.league-tag.cat-league-140 { background: var(--pd); }
.league-tag.cat-league-78 { background: var(--bl1); }
.league-tag.cat-league-135 { background: var(--sa); }
.league-tag.cat-league-61 { background: var(--fl1); }
.league-tag.cat-league-88 { background: var(--ded); }
.league-tag.cat-league-2 { background: var(--cl); }

.bc-tag {
  background: #f0f7f1;
  color: #156d3a;
  border: 1px solid #c8e0cf;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

a.bc-tag:hover {
  background: #d8eedc;
}

.status-tag {
  background: #eee;
  color: var(--text-sub);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

.status-live {
  background: #ffe5e5;
  color: var(--accent);
  font-weight: 600;
}

/* ===== Calendar ===== */

.cal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.cal-nav button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.cal-nav button:hover { background: var(--bg); }

#calMonthLabel {
  font-size: 16px;
  font-weight: 700;
  margin: 0 8px;
  flex: 1;
  text-align: center;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--border);
  border: 1px solid var(--border);
  gap: 1px;
  border-radius: 6px;
  overflow: hidden;
}

.cal-cell {
  background: var(--card);
  min-height: 80px;
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cal-cell.head {
  min-height: 0;
  text-align: center;
  font-weight: 700;
  background: var(--bg);
  padding: 6px 0;
  cursor: default;
  font-size: 12px;
}

.cal-cell.head.sun { color: #c8102e; }
.cal-cell.head.sat { color: #1858a8; }

.cal-cell.other-month { background: #fafbfc; color: #bbb; }
.cal-cell.out-of-range {
  background: #f0f1f3;
  color: #c0c2c5;
  cursor: not-allowed;
}
.cal-cell.out-of-range .cal-date { color: #c0c2c5; }
.cal-cell.today { background: var(--today); }
.cal-cell.today.out-of-range { background: var(--today); color: var(--text); cursor: pointer; }
.cal-cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; }

.cal-date { font-weight: 600; }
.cal-cell.sun .cal-date { color: #c8102e; }
.cal-cell.sat .cal-date { color: #1858a8; }

.cal-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 2px;
}

.cal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.cal-count {
  font-size: 10px;
  color: var(--text-sub);
}

.cal-day-detail { margin-top: 16px; }
.cal-day-detail h3 { margin: 0 0 8px; font-size: 15px; }

/* ===== Ranking ===== */

.rank-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  font-size: 14px;
}

.rank-controls select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  font-size: 14px;
}

.sort-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}

.sort-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.rank-section-title {
  font-size: 16px;
  margin: 24px 0 8px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 4px;
}

.standings-table, .scorers-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}

.standings-table th, .standings-table td,
.scorers-table th, .scorers-table td {
  padding: 6px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.standings-table th, .scorers-table th {
  background: var(--bg);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  white-space: nowrap;
}

.standings-table td.team-cell, .scorers-table td.player-cell {
  text-align: left;
  font-weight: 500;
}

.standings-table td.num,
.scorers-table td.num {
  font-feature-settings: "tnum";
  font-weight: 500;
}

.standings-table td.points {
  font-weight: 700;
  font-size: 14px;
}

.row-crest {
  width: 18px;
  height: 18px;
  vertical-align: middle;
  margin-right: 4px;
  object-fit: contain;
}

.standings-table tr.zone-cl td.position { box-shadow: inset 4px 0 0 #1858a8; }
.standings-table tr.zone-uel td.position { box-shadow: inset 4px 0 0 #f5b500; }
.standings-table tr.zone-relegate td.position { box-shadow: inset 4px 0 0 #c8102e; }

.standings-table tr.has-jp {
  background: #fff0f0;
}

.scorers-table tr.is-jp {
  background: #fff0f0;
  font-weight: 600;
}

.scorers-table tr.jp-club:not(.is-jp) {
  background: #fff8f8;
}

.standings-table tr.has-jp .team-jp,
.scorers-table tr.jp-club .team-jp {
  font-size: 11px;
  margin-left: 4px;
  background: transparent;
  border: none;
  padding: 0;
}

.zone-legend {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 6px;
  flex-wrap: wrap;
}

.zone-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 3px;
}

footer {
  text-align: center;
  padding: 32px 16px;
  font-size: 11px;
  color: var(--text-sub);
}

footer a { color: var(--text-sub); }

@media (max-width: 480px) {
  .cal-cell { min-height: 56px; font-size: 11px; }
  .cal-cell.head { font-size: 11px; }
  .cal-dot { width: 6px; height: 6px; }
  .standings-table, .scorers-table { font-size: 12px; }
  .standings-table th, .standings-table td,
  .scorers-table th, .scorers-table td { padding: 4px 4px; }
}
