:root {
  --bg: #f1f2f5;
  --panel: #ffffff;
  --line: #dcdfe4;
  --text: #22252b;
  --muted: #8a9099;
  --badge: #3b4250;
  --accent: #2563c9;
  --win-bg: #eef4ff;
  --cc: #d9f8f8;
  --top8: #fde8d6;
  --qualified: #fffbd0;
  --fresh: #e2f5e1;
  --border-line: #e0464b;
  --gold: #f2c230;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 16px 20px 32px;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic UI', Meiryo, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button {
  font: inherit;
}

.title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 4px;
}

.page-head h1 {
  margin: 0;
  font-size: 20px;
}

/* 言語切り替え: 見た目は「地球アイコン Language ▾」のボタンで、上に透明なプルダウンを重ねる */
.lang-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: 1px solid #b9bec7;
  border-radius: 16px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.lang-switch:hover {
  background: #f0f3f8;
}

.lang-switch:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.lang-switch .globe {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.lang-switch .caret {
  color: var(--muted);
  font-size: 11px;
}

.lang-switch select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
}

.page-head p {
  margin: 0 0 16px;
  color: #555b65;
}

.layout {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

.bracket-panel {
  flex: 0 1 auto;
  max-width: 100%;
}

.ranking-panel {
  flex: 1 1 660px;
}

/* --- セクション見出し --- */

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 17px;
}

.section-head .state {
  margin-left: 0;
}

.clear-btn {
  padding: 3px 12px;
  border: 1px solid #b9bec7;
  border-radius: 4px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
}

.clear-btn:hover:not(:disabled) {
  background: #f0f3f8;
}

.clear-btn:disabled {
  color: #b0b5bd;
  cursor: default;
}

.section-lead {
  margin: 6px 0 12px;
  color: #555b65;
  font-size: 12px;
}

.section-lead p {
  margin: 0;
}

.section-lead details + p {
  margin-top: 6px;
}

/* 576通りの計算方法（トグル） */

details.calc {
  border: 1px solid #dfe3ea;
  border-radius: 6px;
  background: #fafbfc;
}

details.calc summary {
  padding: 5px 10px;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

details.calc[open] summary {
  border-bottom: 1px solid #dfe3ea;
}

.calc-body {
  padding: 8px 14px 10px;
  color: var(--text);
  font-size: 12.5px;
}

.calc-body p {
  margin: 0 0 6px;
}

.calc-body ol {
  margin: 0;
  padding-left: 20px;
}

.calc-body li {
  margin: 6px 0;
}

.calc-table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 12px;
}

.calc-table th,
.calc-table td {
  padding: 3px 8px;
  border: 1px solid #dcdfe4;
  text-align: left;
}

.calc-table th {
  background: #f1f2f5;
}

.calc-table td:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.calc-body .calc-note {
  margin: 8px 0 0;
  color: var(--muted);
}

/* --- ブラケット --- */

.bracket-scroll {
  overflow-x: auto;
  padding: 12px 8px 4px;
  border-radius: 6px;
  background: #f7f7f9;
}

.section + .section {
  margin-top: 24px;
}

.heads {
  position: relative;
  height: 34px;
}

.col-head {
  position: absolute;
  top: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid #cfd3d9;
  font-weight: 700;
  font-size: 13px;
}

.body {
  position: relative;
  margin-top: 12px;
}

.lines {
  position: absolute;
  inset: 0;
  overflow: visible;
}

.lines path {
  fill: none;
  stroke: #cfd3d9;
  stroke-width: 1.5;
}

.lines path.dash {
  stroke: #c3c7ce;
  stroke-width: 3;
  stroke-dasharray: 4 3;
}

.pill {
  position: absolute;
  left: 0;
  width: 52px;
  transform: translateY(-50%);
  border: 1px solid #c3c7ce;
  border-radius: 10px;
  background: #fff;
  color: #6b717b;
  font-size: 10px;
  text-align: center;
}

.match {
  position: absolute;
  border: 2px solid #e2e4e8;
  background: #fff;
}

.badge {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: -13px;
  transform: translateY(-50%);
  padding: 1px 9px 1px 5px;
  border-radius: 3px;
  background: var(--badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  clip-path: polygon(0 0, 78% 0, 100% 50%, 78% 100%, 0 100%);
}

.slot {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: 24px;
  padding: 0 6px 0 12px;
  border: 0;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}

.slot + .slot {
  border-top: 1px solid #e2e4e8;
}

button.slot {
  cursor: pointer;
}

button.slot:hover:not(:disabled) {
  background: #f3f6fb;
}

button.slot:disabled {
  cursor: default;
}

.slot.tbd {
  color: var(--muted);
  font-style: italic;
}

.slot .seed,
.slot .team {
  color: #9097a1;
  font-size: 11px;
}

.slot .name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot.win {
  background: var(--win-bg);
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 700;
}

.slot.win:hover {
  background: #e3edff !important;
}

.slot.lose .name {
  color: #a3a8b0;
}

.slot .tag {
  flex: none;
  margin-left: auto;
  padding: 0 5px;
  border-radius: 3px;
  background: #e6e8ec;
  color: #555b65;
  font-size: 11px;
  font-weight: 600;
}

.match.tentative {
  border-style: dashed;
  border-color: #c3cde0;
}

.match.tentative .slot.win {
  background: #f6f8fc;
  box-shadow: inset 3px 0 0 #a9bde3;
  font-weight: 600;
}

.match.tentative .slot .tag {
  opacity: 0.7;
}

.slot .tag.gold {
  background: var(--gold);
  color: #3a2c00;
}

/* --- 最終順位 --- */

/* パネル幅をブラケットの幅に合わせる（説明文や最終順位の段組みで横に広がらないようにする） */
.bracket-panel .section-lead,
.standings-box,
.outcomes-box {
  contain: inline-size;
}

.standings-box h3 {
  margin: 16px 0 6px;
  font-size: 15px;
}

.standings {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.standings li {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid #eceef1;
}

.st-place {
  flex: none;
  min-width: 52px;
  white-space: nowrap;
  font-weight: 700;
}

.st-name {
  flex: 1;
}

.st-pt {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* --- CC 権利の行方 --- */

.outcomes-box {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

table.outcomes {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.outcomes th {
  padding: 4px 8px;
  border-bottom: 1px solid #cfd3d9;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
}

.outcomes td {
  padding: 6px 8px;
  border-bottom: 1px solid #eceef1;
}

tr.outcome {
  cursor: pointer;
}

tr.outcome:hover {
  background: #f5f8fd;
}

tr.outcome:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

tr.outcome.active {
  background: var(--win-bg);
  box-shadow: inset 3px 0 0 var(--accent);
}

.outcomes .count {
  width: 120px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.outcomes .count b {
  font-size: 15px;
}

.outcomes .count small {
  margin-left: 6px;
  color: var(--muted);
}

.chip-gain,
.chip-loss {
  display: inline-block;
  margin: 1px 4px 1px 0;
  padding: 0 6px;
  border-radius: 3px;
  font-weight: 600;
  white-space: nowrap;
}

.chip-gain {
  background: #e2f5e1;
  color: #1d7a34;
}

.chip-loss {
  background: #fde4e4;
  color: #c2353a;
}

.outcomes .none {
  color: var(--muted);
}

tr.outcome.gone {
  cursor: default;
  opacity: 0.45;
}

tr.outcome.gone:hover {
  background: none;
}

tr.outcome-detail td {
  padding: 8px 8px 10px 14px;
  background: var(--win-bg);
  box-shadow: inset 3px 0 0 var(--accent);
}

tr.outcome-detail label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-weight: 600;
  white-space: nowrap;
}

tr.outcome-detail select {
  flex: 1;
  min-width: 0;
  padding: 3px 4px;
  border: 1px solid #b9bec7;
  border-radius: 4px;
  background: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 400;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.stepper button {
  padding: 1px 10px;
  border: 1px solid #b9bec7;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

/* --- CC 権利獲得パターン --- */

.cc-panel {
  flex: 1 1 400px;
}

.cc-list h3 {
  margin: 14px 0 4px;
  font-size: 14px;
}

.cc-row {
  display: grid;
  grid-template-columns: minmax(150px, 200px) minmax(80px, 1fr) 92px minmax(150px, 230px);
  align-items: center;
  gap: 10px;
  padding: 5px 4px;
  border-bottom: 1px solid #eceef1;
}

.cc-row.cc-head {
  padding-top: 0;
  padding-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
}

.cc-name {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
}

/* 割合: バーと % の数値 */
.cc-share {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cc-bar {
  flex: 1;
  min-width: 0;
  height: 8px;
  border-radius: 4px;
  background: #e8eaee;
  overflow: hidden;
}

.cc-pct {
  flex: none;
  min-width: 3.4em;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.cc-bar i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: #2fb3b3;
}

.cc-count {
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cc-count b {
  font-size: 14px;
}

.cc-row select {
  width: 100%;
  min-width: 0;
  padding: 3px 4px;
  border: 1px solid #b9bec7;
  border-radius: 4px;
  background: #fff;
  font: inherit;
  font-size: 12px;
}

.cc-row select.no-cc {
  color: var(--muted);
}

.cc-row select.no-cc option,
.cc-row select.no-cc optgroup {
  color: var(--text);
}

.cc-fixed {
  color: #1d7a34;
  font-size: 12px;
  font-weight: 600;
}

.cc-fixed.none {
  color: var(--muted);
  font-weight: 400;
}

.cc-pname {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 表示中の結果で CC 権利を得る選手 */
.cc-badge {
  flex: none;
  padding: 0 5px;
  border-radius: 3px;
  background: #e2f5e1;
  color: #1d7a34;
  font-size: 11px;
  font-weight: 600;
}

/* --- ランキング --- */

.state {
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eef0f3;
  color: #555b65;
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}

.summary {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: #f5f8fd;
}

.summary p {
  margin: 2px 0;
}

.summary .pending {
  color: #555b65;
}

.gain {
  color: #1d7a34;
  font-weight: 600;
}

.loss {
  color: #c2353a;
  font-weight: 600;
}

.table-scroll {
  overflow-x: auto;
}

table.ranking {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
  white-space: nowrap;
}

.ranking th,
.ranking td {
  padding: 4px 6px;
  border: 1px solid #dcdcdc;
}

.ranking th {
  background: #f3f4f6;
  text-align: left;
}

.ranking th small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.ranking th.event {
  background: #eaf6e9;
}

.ranking .num {
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ranking .rank {
  width: 64px;
}

.ranking .rank.cc {
  background: var(--cc);
}

.pname {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ranking .player.top8 {
  background: var(--top8);
}

.chip {
  padding: 0 5px;
  border-radius: 3px;
  background: #fff;
  border: 1px solid #e3b48d;
  color: #8a4b17;
  font-size: 11px;
  font-weight: 600;
}

.tie {
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 3px;
  background: #ffe7c2;
  color: #8a5a00;
  font-size: 11px;
}

.ranking tr.qualified .rank,
.ranking tr.qualified .qual,
.ranking tr.qualified .num {
  background: var(--qualified);
}

.st-sure {
  color: #1d7a34;
  font-weight: 600;
}

.st-maybe {
  color: #a15c00;
  font-weight: 600;
}

.st-gone {
  color: #9aa0a8;
  text-decoration: line-through;
}

.standings-box h3 .state {
  font-size: 11px;
}

.ranking td.fresh {
  background: var(--fresh);
  font-weight: 700;
}

.gain-pt {
  margin-left: 4px;
  color: #1d7a34;
  font-size: 11px;
  font-weight: 600;
}

.ranking .up {
  color: #1d7a34;
}

/* 最低獲得ポイント（まだ順位が決まっていない選手） */
.ranking td.fresh.at-least {
  background: #f0f9ef;
  color: #3d6b45;
  font-weight: 600;
}

/* CC 権利の可能性がない選手の行 */
.ranking tr.gone td,
.ranking tr.gone td.player.top8,
.ranking tr.gone td.fresh {
  background: #eceef1;
}

.ranking tr.border td {
  border-bottom: 3px solid var(--border-line);
}

.ties {
  margin: 10px 0 0;
  padding-left: 20px;
  font-size: 13px;
}

.ties:empty {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  color: #555b65;
  font-size: 12px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.swatch.cc {
  background: var(--cc);
}

.swatch.top8 {
  background: var(--top8);
}

.swatch.qualified {
  background: var(--qualified);
}

.swatch.border {
  height: 0;
  border: 0;
  border-top: 3px solid var(--border-line);
}

.note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 600px) {
  .standings {
    grid-template-columns: 1fr;
  }

  .cc-row {
    grid-template-columns: 1fr auto auto;
  }

  .cc-row .cc-bar,
  .cc-row.cc-head {
    display: none;
  }

  .cc-row select,
  .cc-row .cc-fixed {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  body {
    padding: 12px 12px 24px;
  }

  .panel {
    padding: 12px;
  }
}

/* --- スマホ向け（幅 760px 以下） --- */

.match-list,
.cols-toggle-wrap,
.section-lead .m-only-block,
.outcomes .m-only,
.outcomes .m-label,
.outcomes .m-lost {
  display: none;
}

.match-list h3 {
  margin: 16px 0 2px;
  font-size: 15px;
}

.ml-lead {
  margin: 0 0 8px;
  color: #555b65;
  font-size: 12px;
}

.ml-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ml-match {
  padding: 8px 0;
  border-bottom: 1px solid #eceef1;
}

.ml-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: #555b65;
  font-size: 12px;
  font-weight: 600;
}

.ml-id {
  padding: 1px 7px;
  border-radius: 3px;
  background: var(--badge);
  color: #fff;
  font-size: 11px;
}

.ml-state {
  margin-left: auto;
  padding: 0 6px;
  border-radius: 3px;
  background: #e2f5e1;
  color: #1d7a34;
  font-size: 11px;
}

.ml-state.tentative {
  background: #eef0f3;
  color: var(--muted);
}

.ml-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ml-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid #c9ced6;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.ml-btn.win {
  border-color: var(--accent);
  background: var(--win-bg);
  box-shadow: inset 0 0 0 1px var(--accent);
  font-weight: 700;
}

.ml-btn.lose {
  color: #a3a8b0;
}

.ml-match.tentative .ml-btn {
  border-style: dashed;
}

.ml-match.tentative .ml-btn.win {
  box-shadow: none;
  font-weight: 600;
}

.ml-btn.tbd,
.ml-btn:disabled {
  color: var(--muted);
  cursor: default;
}

.ml-btn.tbd {
  font-style: italic;
  font-size: 12px;
}

.ml-btn .tag {
  padding: 0 5px;
  border-radius: 3px;
  background: #e6e8ec;
  color: #555b65;
  font-size: 11px;
  font-weight: 600;
}

.ml-btn .tag.gold {
  background: var(--gold);
  color: #3a2c00;
}

.cols-toggle {
  margin-bottom: 6px;
  padding: 6px 12px;
  border: 1px solid #b9bec7;
  border-radius: 4px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
}

@media (max-width: 760px) {
  /* トーナメント図は表示専用にして、試合一覧から操作する */
  .bracket .slot {
    pointer-events: none;
  }

  .match-list,
  .cols-toggle-wrap {
    display: block;
  }

  .section-lead .m-only-block {
    display: block;
    margin-top: 4px;
    color: var(--accent);
  }

  /* CC 権利の行方: 獲得と喪失を1つのセルに2行で並べる */
  .outcomes th.lost,
  .outcomes td.lost,
  .outcomes .d-only {
    display: none;
  }

  .outcomes .m-only {
    display: inline;
  }

  .outcomes .m-label {
    display: inline-block;
    min-width: 30px;
    margin-right: 4px;
    color: var(--muted);
    font-size: 11px;
  }

  .outcomes .m-lost {
    display: block;
    margin-top: 3px;
  }

  .outcomes .count {
    width: 76px;
  }

  .outcomes .count small {
    display: block;
    margin-left: 0;
  }

  /* ランキング: #1〜#7 は切り替えで表示し、累計と CC権利は折り返す */
  .ranking:not(.show-all) .hist {
    display: none;
  }

  .ranking td.total .gain-pt {
    display: block;
    margin-left: 0;
  }

  .ranking td.qual {
    white-space: normal;
  }

  .ranking th,
  .ranking td {
    padding: 4px 5px;
  }

  .ranking .pname {
    flex-wrap: wrap;
    gap: 2px 6px;
  }

  .ranking .num {
    min-width: 0;
  }

  .ranking .rank {
    width: auto;
  }

  /* 最終順位のプルダウンを幅 100% にして、長い選択肢でセルが広がらないようにする */
  tr.outcome-detail select {
    width: 100%;
  }
}
