:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #ecebe7;
  --line: #dddcd6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --team-a: #2a78d6;
  --team-b: #e34948;
  --good: #117a3c;
  --bad: #c0322f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 5%);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262624;
    --line: #34332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #4b8fe8;
    --accent-ink: #0b0b0b;
    --team-a: #3987e5;
    --team-b: #e66767;
    --good: #4cc27a;
    --bad: #ef7b78;
    --series-1: #3987e5;
    --series-2: #d95926;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--accent); color: var(--accent-ink);
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 18px; text-decoration: none; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
h1 { font-size: 24px; margin: 4px 0 12px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 24px 0 8px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 10px; font-size: 12px; text-decoration: none; color: var(--text-2);
}
.tabbar a .ico { font-size: 20px; line-height: 1.2; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.primary .ico {
  background: var(--accent); color: var(--accent-ink); border-radius: 999px;
  width: 30px; height: 30px; display: grid; place-items: center; font-weight: 700;
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
}
.stack > * + * { margin-top: 12px; }

.seg {
  display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px;
  overflow-x: auto;
}
.seg button {
  flex: 1; border: 0; background: transparent; padding: 9px 10px; border-radius: 9px;
  font-weight: 600; color: var(--text-2); white-space: nowrap; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 11px 16px; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 46px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { color: var(--bad); }
.row-btns { display: flex; gap: 10px; }
.row-btns > * { flex: 1; }

/* ranking */
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li a {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px;
  padding: 11px 4px; border-bottom: 1px solid var(--line); text-decoration: none;
}
.rank-list li:last-child a { border-bottom: 0; }
.rank-no { font-weight: 700; color: var(--text-2); text-align: center; font-variant-numeric: tabular-nums; }
.rank-list li:nth-child(1) .rank-no { color: #c99400; }
.rank-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-sub { font-size: 13px; color: var(--muted); }
.rank-pts { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; text-align: right; }
.rank-pts small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); vertical-align: 2px; margin-left: 4px;
}
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }

details.explain { margin-top: 16px; color: var(--text-2); font-size: 14px; }
details.explain summary { cursor: pointer; font-weight: 600; }

/* new match */
.team { border-left: 5px solid var(--team-a); }
.team.b { border-left-color: var(--team-b); }
.team-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.team-title { font-weight: 700; }
.team.a .team-title { color: var(--team-a); }
.team.b .team-title { color: var(--team-b); }
.slot {
  display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px; margin-top: 8px;
}
.slot-label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.pick {
  text-align: left; border: 1px dashed var(--line); background: var(--surface-2);
  border-radius: 10px; padding: 12px; min-height: 48px; cursor: pointer; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pick.filled { border-style: solid; background: var(--surface); }
.pick.empty-slot { color: var(--muted); font-weight: 400; }
.swap { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px; }

.winner-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.winner-btns button {
  border: 2px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px;
  font-weight: 700; cursor: pointer; min-height: 54px;
}
.winner-btns button.a[aria-pressed="true"] { border-color: var(--team-a); background: var(--team-a); color: #fff; }
.winner-btns button.b[aria-pressed="true"] { border-color: var(--team-b); background: var(--team-b); color: #fff; }
.goal-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.goal-grid button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  min-height: 48px; font-size: 18px; font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums;
}
.goal-grid button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.scoreline { text-align: center; font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.scoreline .a { color: var(--team-a); }
.scoreline .b { color: var(--team-b); }

.predict { font-size: 14px; color: var(--text-2); }
.predict-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; margin: 8px 0 4px; gap: 2px; }
.predict-bar .a { background: var(--team-a); }
.predict-bar .b { background: var(--team-b); }
.predict-legend { display: flex; justify-content: space-between; font-weight: 600; color: var(--text); }

/* match cards */
.match { padding: 12px 14px; }
.match.deleted { opacity: .55; }
.match.deleted .match-body { text-decoration: line-through; }
.match-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.match-body { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.match-side { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.match-side.b { text-align: right; align-items: flex-end; }
.match-side a { text-decoration: none; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.match-side.win a { color: var(--text); }
.match-side.lose a { color: var(--text-2); font-weight: 500; }
.pos { font-size: 11px; color: var(--muted); margin: 0 3px; }
.delta { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; margin-left: 4px; }
.match-side.b .delta { margin: 0 4px 0 0; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.match-score { font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.match-score .a { color: var(--team-a); }
.match-score .b { color: var(--team-b); }
.match-actions { margin-top: 8px; display: flex; justify-content: flex-end; gap: 8px; font-size: 13px; }
.linkbtn { border: 0; background: none; color: var(--text-2); cursor: pointer; padding: 4px 6px; text-decoration: underline; }
.deleted-note { font-size: 12px; color: var(--bad); margin-top: 4px; }

/* result */
.result-list { list-style: none; padding: 0; margin: 0; }
.result-list li { display: flex; justify-content: space-between; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.result-list li:last-child { border-bottom: 0; }

/* profile */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { padding: 12px; }
.tile-label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.tile-value { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile-sub { font-size: 12px; color: var(--muted); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fact { padding: 12px; }
.fact b { display: block; font-size: 17px; }
.fact span { font-size: 13px; color: var(--text-2); }

.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart-legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 6px; flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.axis text { fill: var(--muted); font-size: 11px; }
.grid line { stroke: var(--line); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap;
  transform: translate(-50%, -100%); top: 0;
}
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }

/* sheet (modal) */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 45%);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-panel {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 88vh;
  border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-head { padding: 14px 16px 8px; display: flex; gap: 10px; align-items: center; }
.sheet-head h3 { margin: 0; font-size: 17px; flex: 1; }
.sheet-body { padding: 4px 16px 16px; overflow-y: auto; }
.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 17px;
}
.pick-list { list-style: none; margin: 8px 0 0; padding: 0; }
.pick-list button {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none;
  padding: 13px 4px; font-size: 17px; cursor: pointer; display: flex; justify-content: space-between;
}
.pick-list button:disabled { color: var(--muted); cursor: default; }
.pick-list .new { color: var(--accent); font-weight: 600; }
.pick-list small { color: var(--muted); font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30;
  max-width: calc(100% - 32px); font-size: 14px;
}
.notice { font-size: 13px; color: var(--muted); text-align: center; margin-top: 8px; }
.notice-card { background: var(--surface-2); box-shadow: none; font-size: 15px; }
