:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e3e3e3;
  --accent: #1f5fbf;
  --mark: #fff3c4;
  --mark-fg: #4d3a00;
  --up: #1a7f37;
  --down: #c62828;
  --pct: #b85c00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #ececec;
    --muted: #9a9a9a;
    --line: #2c2c2c;
    --accent: #7fb0ff;
    --mark: #3a3110;
    --mark-fg: #ffe28a;
    --up: #5fd17a;
    --down: #ff7b72;
    --pct: #ffb357;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header.top {
  border-bottom: 1px solid var(--line);
}
header.top .in {
  max-width: 860px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  gap: 16px;
  align-items: baseline;
  flex-wrap: wrap;
}
header.top .brand { font-weight: 700; color: var(--fg); }
/* 1 段目に名前と検索、2 段目に競技の並び（T41。国の一覧を足して、日本語の広い画面で 3 段に折れたため） */
header.top nav { order: 3; flex-basis: 100%; }
header.top nav a { margin-right: 12px; white-space: nowrap; display: inline-block; }
main {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
}
h1 { font-size: 1.4rem; margin: 8px 0 16px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
.sub { color: var(--muted); font-size: 0.9rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 0.85rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.team { white-space: normal; }
tr.mark td { background: var(--mark); color: var(--mark-fg); }
tr.mark td a { color: inherit; font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: block;
  color: var(--fg);
  font-weight: 600;
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.stats { display: flex; gap: 24px; flex-wrap: wrap; margin: 8px 0 16px; }
.stat .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: 0.85rem; }
footer {
  max-width: 860px;
  margin: 32px auto 0;
  padding: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}
footer a { margin-right: 12px; }
.about p, .about li { max-width: 70ch; }
.about table th, .about table td { white-space: normal; }
@media (max-width: 420px) {
  th, td { padding: 8px 4px; }
  body { font-size: 15px; }
}

/* 旗 */
img.flag { width: 20px; height: 15px; vertical-align: -2px; margin-right: 6px; border: 1px solid var(--line); }
h1 img.flag { width: 32px; height: 24px; vertical-align: -3px; margin-right: 10px; }
h1 a.country { color: inherit; }

/* 競技のアイコン（判断記録 0015）。色付きの Noto Emoji。文字の大きさに合わせる。旗と同じく名前の左に置く */
img.ic { width: 1.15em; height: 1.15em; vertical-align: -0.2em; margin-right: 0.35em; flex: none; }
h1 img.ic { width: 1.3em; height: 1.3em; margin-right: 0.4em; }
header.top nav a img.ic { width: 1em; height: 1em; vertical-align: -0.15em; margin-right: 0.25em; }
/* 狭い画面では競技の並びを 1 行にして横に動かす（T42）。画面の端まで広げ、スクロールバーは出さず、端を薄くして続きがあると見せる */
@media (max-width: 600px) {
  header.top .in { row-gap: 6px; }
  header.top nav {
    display: flex; overflow-x: auto; flex-basis: calc(100% + 32px); margin: 0 -16px; padding: 2px 24px 2px 16px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 24px), transparent);
  }
  header.top nav::-webkit-scrollbar { display: none; }
  header.top nav a { flex: none; }
}

/* 検索 */
.search { position: relative; margin-left: auto; }
.search input {
  width: 160px; max-width: 45vw; padding: 6px 10px; font: inherit; font-size: 0.95rem;
  color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.search input:focus { outline: none; border-color: var(--accent); }
.search ul {
  position: absolute; right: 0; top: 100%; z-index: 10; margin: 4px 0 0; padding: 4px 0; list-style: none;
  min-width: 240px; max-width: calc(100vw - 32px); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.search li a { display: block; padding: 6px 12px; color: var(--fg); white-space: nowrap; }
.search li a:hover, .search li[aria-selected="true"] a { background: var(--mark); text-decoration: none; }
.search li a .sport { color: var(--muted); font-size: 0.85rem; margin-left: 8px; }
.search li a .sport img.ic { margin-right: 0.25em; }
.search li a { display: flex; align-items: center; }
.search li a .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.search li a .sport, .search li a .rank, .search li a .flag { flex-shrink: 0; }
.search li a .rank { color: var(--muted); font-size: 0.85rem; margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.search ul[hidden] { display: none; }

/* 言語の切り替え（T45）。検索欄の右。いまの言語は太字、もう一方は同じページの別言語版へ */
header.top .lang { white-space: nowrap; font-size: 0.9rem; }
header.top .lang b { font-weight: 700; }
header.top .lang .sep { margin: 0 6px; color: var(--muted); }
header.top .lang img.ic, header.top .lang .short { display: none; }
@media (max-width: 420px) {
  header.top .in { column-gap: 12px; }
}
/* 幅 360px までは「EN | 日本語」が 1 段目に入る。それより狭いときだけ縮める */
@media (max-width: 359px) {
  header.top .lang b, header.top .lang .sep, header.top .lang .long { display: none; }
  header.top .lang img.ic { display: inline; width: 1em; height: 1em; vertical-align: -0.15em; margin-right: 0.2em; }
  header.top .lang .short { display: inline; }
}

/* 推移 */
.trend { width: 100%; max-width: 480px; height: auto; display: block; margin: 4px 0 16px; }
.trend .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.trend .dot { fill: var(--accent); }
.trend .axis { stroke: var(--line); stroke-width: 1; }
.trend text { fill: var(--muted); font-size: 11px; }
.trend.pct { margin-top: -8px; }
.trend.pct .line { stroke: var(--pct); stroke-dasharray: 5 3; }
.trend.pct .dot, .trend.pct .pt { fill: var(--pct); }

/* 並べ替えのできる表（競技の表） */
/* 見出し行を固定するため、表の枠の中で縦にも動かす（横に動く枠の中では sticky の top が画面に効かない） */
.scroll { overflow: auto; max-height: 100vh; max-height: 100dvh; -webkit-overflow-scrolling: touch; }
table.sortable thead th { position: sticky; top: 0; z-index: 2; background: var(--bg); box-shadow: inset 0 -1px 0 var(--line); }
table.sortable thead th.team { z-index: 3; }
table.sortable th button {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; white-space: nowrap;
}
table.sortable th[aria-sort] { color: var(--fg); }
table.sortable th[aria-sort="ascending"] button::after { content: "▲"; font-size: 0.7em; margin-left: 2px; }
table.sortable th[aria-sort="descending"] button::after { content: "▼"; font-size: 0.7em; margin-left: 2px; }
table.sortable .team { position: sticky; left: 0; z-index: 1; background: var(--bg); min-width: 9em; }
td.up { color: var(--up); }
td.down { color: var(--down); }
@media (max-width: 600px) {
  table.sortable .team { min-width: 7.5em; max-width: 9em; }
}

/* 同じ位置の帯（T29） */
.band { margin: 8px 0 24px; }
.band .bar { position: relative; height: 18px; border: 1px solid var(--line); border-radius: 9px; background: linear-gradient(90deg, var(--line), transparent); }
.band .bar i { position: absolute; top: 2px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--accent); opacity: 0.5; }
.band .bar i.own { opacity: 1; background: var(--mark-fg); }
/* 自分の点は競技のアイコン。一覧の自分の行と同じ色の丸に載せる */
.band .bar i.own:has(img) { top: -3px; width: 22px; height: 22px; margin-left: -11px; padding: 2px; background: var(--mark); border: 1px solid var(--mark-fg); }
.band .bar i.own img.ic { display: block; width: 16px; height: 16px; margin: 0; }
/* 国のページの点: 競技のアイコン。押すとその競技のチームのページへ。近い点は --row で下の段へ（bar は段の数だけ高くなる） */
.band .bar { height: calc(var(--rows, 1) * 18px); }
.band .bar a.pin {
  position: absolute; top: calc(var(--row, 0) * 18px - 1px); width: 18px; height: 18px; margin-left: -9px; padding: 1px;
  border-radius: 50%; background: var(--bg); border: 1px solid var(--accent); display: block;
}
.band .bar a.pin:hover { background: var(--mark); }
.band .bar a.pin img.ic { display: block; width: 14px; height: 14px; margin: 0; }
.band .ax { position: relative; height: 16px; margin-top: 2px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.band .ax span { position: absolute; transform: translateX(-50%); }
.band .ax span:first-child { transform: none; }
.band .ax span:last-child { transform: translateX(-100%); }
.band .drop { height: 10px; margin-left: calc(var(--p) - 1px); border-left: 2px solid var(--accent); }
.band ul { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--accent); }
.band li { display: flex; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.band li.own { background: var(--mark); color: var(--mark-fg); font-weight: 700; }
.band li.own a:not(.sp) { color: inherit; }
.band li .sp { flex: none; width: 8.6em; color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.band li > a:not(.sp), .band li .name { overflow: hidden; text-overflow: ellipsis; }
.band li .rk { margin-left: auto; padding-left: 8px; color: var(--muted); font-size: 0.85rem; font-weight: 400; font-variant-numeric: tabular-nums; }
@media (max-width: 420px) {
  .band li .sp { width: 8em; }
}

/* 直近の試合（T31） */
table.recent { table-layout: fixed; }
table.recent th:nth-child(1), table.recent td:nth-child(1) { width: 6.2em; }
table.recent th:nth-child(3), table.recent td:nth-child(3) { width: 3.4em; }
table.recent th:nth-child(4), table.recent td:nth-child(4) { width: 3.2em; }
table.recent td.date { color: var(--muted); font-size: 0.85rem; text-align: left; }
table.recent td.team { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.recent td.team .comp { display: block; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 0.75rem; }

/* トップの競技のカード（T32） */
.card .title { display: block; margin-bottom: 6px; }
.card ul { list-style: none; margin: 0; padding: 0; font-weight: 400; font-size: 0.9rem; }
.card ul.moves { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.card li { display: flex; align-items: center; padding: 2px 0; white-space: nowrap; }
.card li .name { overflow: hidden; text-overflow: ellipsis; }
.card li .v { margin-left: auto; padding-left: 8px; font-variant-numeric: tabular-nums; }
.card li .v.up { color: var(--up); }
.card li .v.down { color: var(--down); }
.card .date { display: block; margin-top: 6px; color: var(--muted); font-size: 0.8rem; font-weight: 400; }

/* 国の一覧（T41、T47、判断記録 0016）。# と国のあとに競技ごとの順位の列。国の名前は入りきらなければ省略（…）。
   順位はセルいっぱいのリンクにして、狭い画面でも押し分けられるようにする */
table.countries { table-layout: fixed; }
table.countries th:first-child { width: 2.6em; }
table.countries th.sp { width: 3.5em; text-align: center; padding-left: 0; padding-right: 0; }
table.countries th.sp a { display: inline-block; padding: 2px; }
table.countries th.sp img.ic { display: block; width: 20px; height: 20px; margin: 0; }
table.countries td.team { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.countries td.rk { padding: 0; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }
table.countries td.rk a { display: block; padding: 8px 0; }
@media (max-width: 420px) {
  table.countries th:first-child { width: 2.2em; }
  table.countries th.sp { width: 28px; }
  table.countries th.sp img.ic { width: 18px; height: 18px; }
  table.countries td.rk { font-size: 0.8rem; }
}

/* 国のページの表（T44）。アイコンは枠付きの別のリンク（競技の表へ）、名前はチームのページへ */
table.country a.sp {
  display: inline-block; width: 30px; height: 30px; padding: 5px; margin: -6px 8px -6px 0; vertical-align: middle;
  border: 1px solid var(--line); border-radius: 8px;
}
table.country a.sp:hover { border-color: var(--accent); }
table.country a.sp img.ic { display: block; width: 18px; height: 18px; margin: 0; }

/* いる場所の印（T46）。上の帯の今いる競技・国の一覧に下線。印の幅は項目（アイコンと名前）の幅 */
header.top nav a[aria-current] { color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent); }
header.top nav a[aria-current]:hover { text-decoration: none; }
/* パンくず（チームのページと国のページの大見出しの上）: 1 つ上のページ › 今のページ */
nav.crumbs { margin: 8px 0 0; color: var(--muted); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
nav.crumbs .sep { margin: 0 6px; }
nav.crumbs span:last-child { color: var(--fg); }
