:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --warn-bg: #7c2d12;
  --warn-fg: #fef3c7;
  --radius: 8px;
  /* Solid composites pre-computed against --surface / --surface-2. sticky columns
     must never reveal scrolled rows underneath, so every cell state needs an
     opaque background. */
  --cell-bg: #1e293b;
  --cell-bg-hover: #253344;
  --cell-bg-highlight: #24435c;
  --cell-bg-highlight-hover: #2a4e6a;
  --header-bg: #334155;
  --header-bg-highlight: #3c5e7f;
}

* {
  box-sizing: border-box;
}

/* home-layout: ヘッダーとフッターを固定し、中央の main だけ縦スクロールさせる */
body.home-layout {
  height: 100vh;
  /* iOSのアドレスバー等を考慮したフォールバック。dvhに対応していれば優先 */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.home-layout .site-header,
body.home-layout .warning-banner,
body.home-layout .site-footer {
  flex-shrink: 0;
}

body.home-layout .site-header {
  position: static;
}

body.home-layout main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.home-layout .site-footer {
  margin-top: 0;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

a {
  color: #bae6fd;
  text-decoration: none;
}

a:visited {
  color: #bae6fd;
}

a:hover,
a:focus {
  color: #ffffff;
  text-decoration: underline;
}

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

.site-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.site-brand {
  min-width: 0;
  flex: 1 1 auto;
}

.site-header h1 {
  margin: 0;
  font-size: 18px;
  color: var(--accent);
}

.site-header .tagline {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.year-selector {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.year-selector label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.year-selector select {
  background: var(--surface-2);
  color: var(--text);
  border: 0;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  min-width: 88px;
}

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

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.warning-banner {
  background: var(--warn-bg);
  color: var(--warn-fg);
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 2px solid #fbbf24;
}

.site-footer {
  padding: 16px;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  border-top: 1px solid var(--surface-2);
  margin-top: 32px;
}

.site-footer p {
  margin: 4px 0;
}

.site-header h1 a {
  color: inherit;
  text-decoration: none;
}

.page-nav {
  display: grid;
  /* ナビは常に2段構成。項目数に応じて列数を決め、項目内は改行させない */
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.nav-link {
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link.active {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* nav 内で使うカード本文のインラインリンクは固定幅ではなく自然な表示にする */
.card .nav-link {
  display: inline-block;
  white-space: normal;
}

.standings-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.standings-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  text-align: right;
}

.standings-table th,
.standings-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--surface-2);
  white-space: nowrap;
  background: var(--cell-bg);
}

.standings-table thead th {
  background: var(--header-bg);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-dim);
  position: sticky;
  top: 0;
  z-index: 2;
}

.standings-table th.team,
.standings-table td.team {
  text-align: left;
}

.standings-table th.rank,
.standings-table td.rank {
  text-align: center;
  width: 40px;
  min-width: 40px;
}

/* Sticky columns (rank + player name) — inherit opaque cell/header backgrounds */
.standings-table th.sticky-col,
.standings-table td.sticky-col {
  position: sticky;
  z-index: 1;
}

.standings-table thead th.sticky-col {
  z-index: 3;
}

.standings-table th.sticky-col-0,
.standings-table td.sticky-col-0 {
  left: 0;
  width: 40px;
  min-width: 40px;
}

.standings-table th.sticky-col-1,
.standings-table td.sticky-col-1 {
  left: 40px;
  min-width: 140px;
  border-right: 1px solid var(--surface-2);
}

/* Row hover (solid colour so sticky columns never show scrolled rows through them) */
.standings-table tbody tr:hover td {
  background: var(--cell-bg-hover);
}

/* Highlight the actively-sorted column */
.standings-table th.col-highlight,
.standings-table td.col-highlight {
  background: var(--cell-bg-highlight);
}

.standings-table thead th.col-highlight {
  background: var(--header-bg-highlight);
  color: var(--text);
}

.standings-table tbody tr:hover td.col-highlight {
  background: var(--cell-bg-highlight-hover);
}

.loading {
  color: var(--text-dim);
  font-size: 13px;
}

.error {
  color: #fca5a5;
  font-size: 13px;
}

.muted {
  color: var(--text-dim);
  font-size: 11px;
  text-align: right;
  margin-top: 8px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.control-group label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.toggle-group {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--radius);
  overflow: hidden;
}

.toggle-group button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.toggle-group button.active {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

select#sort-select,
select#metric-select {
  background: var(--surface-2);
  color: var(--text);
  border: 0;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}

.chart-wrap {
  position: relative;
  height: 360px;
  width: 100%;
  margin: 12px 0;
}

@media (max-width: 540px) {
  .chart-wrap {
    height: 280px;
  }
  .hide-sm {
    display: none;
  }
  .standings-table {
    font-size: 12px;
  }
  .standings-table th,
  .standings-table td {
    padding: 6px 4px;
  }
  .controls {
    gap: 8px;
  }
  .control-group {
    min-width: 0;
    flex: 1 1 auto;
  }
}

@media (min-width: 768px) {
  html, body {
    font-size: 16px;
  }
  .site-header h1 {
    font-size: 22px;
  }
}
