/* 高校野球 戦績DB — 白地・紺・縫い目の赤。読みやすさ優先 */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #e3e6eb;
  --line-strong: #cdd2da;
  --ink: #172033;
  --ink-soft: #626b7c;
  --seam: #d62839;
  --seam-soft: #fbe9eb;
  --hover: #f1f3f6;
  --radius: 12px;
  --measure: 1080px;
  font-family: "IBM Plex Sans JP", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "palt" 1;
}
* { box-sizing: border-box; }
body { margin: 0; padding: 0 24px; }
.masthead, .sheet-head, .tabs, main, .colophon { max-width: var(--measure); margin-left: auto; margin-right: auto; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 6px; }

/* ---- 題字 ---- */
.masthead { padding: 44px 0 26px; }
.masthead h1 { margin: 0; font-size: clamp(1.75rem, 4.5vw, 2.5rem); font-weight: 700; line-height: 1.2; letter-spacing: .01em; }
.masthead p { margin: 8px 0 0; color: var(--ink-soft); font-size: .95rem; }

/* ---- 絞り込み ---- */
.sheet-head { display: flex; flex-wrap: wrap; gap: 14px 36px; align-items: center; }
.field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.field-name { font-size: .85rem; font-weight: 500; color: var(--ink-soft); }
.period-note { font-size: .85rem; color: var(--ink-soft); }

/* セグメント（選択中は白いチップ） */
.marks { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: #e9ecf1; border-radius: 10px; }
.marks button {
  border: 0; background: none; cursor: pointer; border-radius: 8px;
  padding: 6px 14px; font-size: .92rem; font-weight: 500; color: var(--ink-soft);
  transition: background-color .15s, color .15s;
}
.marks button:hover { color: var(--ink); }
.marks button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 1px 2px rgba(23, 32, 51, .12); }

.recent { display: inline-flex; align-items: center; gap: 10px; font-size: .92rem; }
.recent[hidden] { display: none; }
.recent input { width: 160px; accent-color: var(--ink); }
.recent output { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 1.6em; text-align: right; }

/* ---- タブ（開いているタブの下に縫い目） ---- */
.tabs { display: flex; gap: 6px; margin-top: 28px; border-bottom: 1px solid var(--line-strong); overflow-x: auto; }
.tabs button {
  position: relative; border: 0; background: none; cursor: pointer; white-space: nowrap;
  padding: 10px 14px 14px; font-size: 1rem; font-weight: 500; color: var(--ink-soft);
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 700; }
.tabs button[aria-selected="true"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 7px;
  background:
    linear-gradient(135deg, transparent 42%, var(--seam) 42% 58%, transparent 58%) 0 0 / 8px 7px repeat-x,
    linear-gradient(45deg, transparent 42%, var(--seam) 42% 58%, transparent 58%) 4px 0 / 8px 7px repeat-x;
}

/* ---- 本文 ---- */
main { padding: 22px 0 48px; min-height: 50vh; }
.controls { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; margin-bottom: 16px; }
.controls label { font-size: .85rem; font-weight: 500; color: var(--ink-soft); display: inline-flex; gap: 10px; align-items: center; }
select, input[type="number"], input[list] {
  font: inherit; font-size: .95rem; color: var(--ink);
  padding: 7px 12px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px;
}
select:hover, input:hover { border-color: #aab1bd; }
input[type="number"] { width: 5em; text-align: right; }
#school-input { width: 22em; max-width: 78vw; }
.note { font-size: .88rem; color: var(--ink-soft); margin: 0 0 16px; max-width: 44em; }

/* 一覧の器（1画面に1つ） */
.ledger { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 24px; overflow: hidden; }
.ledger-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; padding: 22px 24px 6px; }
.ledger-title h2 { font-size: 1.45rem; font-weight: 700; margin: 0; line-height: 1.3; }
.ledger-title .aside { color: var(--ink-soft); font-size: .9rem; }
.ledger h3 { font-size: 1rem; font-weight: 700; margin: 0; padding: 26px 24px 8px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; font-variant-numeric: tabular-nums; }
th, td { padding: 12px 16px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
thead th { font-size: .8rem; font-weight: 500; color: var(--ink-soft); background: #fafbfc; position: sticky; top: 0; }
th:first-child, td:first-child { padding-left: 24px; }
th:last-child, td:last-child { padding-right: 24px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.active { color: var(--ink); font-weight: 700; }
th.active::after { content: ""; display: inline-block; margin-left: 6px; border: 4px solid transparent; border-top: 5px solid var(--seam); vertical-align: -1px; }
td.name, th.name { text-align: left; }
td.rank, th.rank { text-align: center; width: 3.5em; }
td.rank { font-weight: 700; color: var(--ink-soft); }
tbody tr:hover td { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
.link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--ink); font-weight: 700; text-align: left; }
.link:hover { color: var(--seam); }
.subtle { color: var(--ink-soft); font-size: .82rem; margin-left: 8px; font-weight: 400; }
.win { color: var(--seam); font-weight: 700; }
.lose { color: var(--ink); }
.circled { color: var(--seam); font-weight: 700; }
td .circled { display: inline-block; min-width: 1.9em; padding: 1px 7px; border-radius: 999px; background: var(--seam-soft); text-align: center; }
.result-runner { font-weight: 700; }
.result-plain { color: var(--ink-soft); }
.replay { font-size: .75rem; color: var(--ink-soft); margin-left: 8px; }

/* 対戦成績の大きな記録 */
.record { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 28px; padding: 8px 24px 22px; border-bottom: 1px solid var(--line); }
.record .big { font-size: clamp(2.6rem, 7vw, 3.6rem); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.record .big small { font-size: 1rem; font-weight: 500; color: var(--ink-soft); margin: 0 14px 0 4px; letter-spacing: 0; }
.record .big .w { color: var(--seam); }
.record .rate { color: var(--ink-soft); font-size: .95rem; }
.record .rate b { color: var(--ink); font-size: 1.35rem; margin-left: 8px; font-variant-numeric: tabular-nums; }

/* 学校の通算 */
.tally { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); margin: 14px 24px 4px; border: 1px solid var(--line); border-radius: 10px; }
.tally div { padding: 12px 16px 14px; border-right: 1px solid var(--line); }
.tally div:last-child { border-right: 0; }
.tally dt { font-size: .8rem; color: var(--ink-soft); }
.tally dd { margin: 4px 0 0; font-size: 1.6rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }

/* くじ番号の勝率バー（中央の線が5割） */
.bar { position: relative; display: inline-block; vertical-align: middle; width: 180px; height: 8px; border-radius: 999px; background: #eceff3; }
.bar span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--ink); }
.bar::after { content: ""; position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; background: var(--seam); opacity: .7; }

.empty { color: var(--ink-soft); padding: 36px 24px; margin: 0; }

.colophon { padding: 20px 0 40px; font-size: .8rem; color: var(--ink-soft); border-top: 1px solid var(--line); }
.colophon p { margin: 0 0 4px; max-width: 60em; }

@media (max-width: 640px) {
  body { padding: 0 14px; }
  .masthead { padding: 28px 0 18px; }
  .sheet-head { gap: 12px; flex-direction: column; align-items: flex-start; }
  .tabs { margin-top: 20px; }
  .tabs button { padding: 10px 10px 14px; }
  th, td { padding: 10px 10px; }
  th:first-child, td:first-child { padding-left: 14px; }
  th:last-child, td:last-child { padding-right: 14px; }
  .ledger-title, .record { padding-left: 16px; padding-right: 16px; }
  .ledger h3 { padding-left: 16px; }
  .tally { margin: 12px 16px 4px; grid-template-columns: repeat(4, 1fr); }
  .tally div:nth-child(4) { border-right: 0; }
  .tally div:nth-child(-n+4) { border-bottom: 1px solid var(--line); }
  .bar { width: 96px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
