/* 北里POG — バーガンディ基調 */
:root {
  --bg: #f6f1ef;
  --surface: #ffffff;
  --surface-2: #f4ecea;
  --text: #241519;
  --muted: #84707a;
  --line: #ecdfdc;
  --accent: #7b1e3a;
  --accent-2: #a3324f;
  --accent-soft: #f7e6ec;
  --head-1: #8a2343;
  --head-2: #561025;
  --gold: #a87b2b;
  --gold-soft: #f8edd5;
  --silver: #6b7480;
  --silver-soft: #eceef1;
  --bronze: #9c5634;
  --bronze-soft: #f5e6dc;
  --danger: #b4232f;
  --danger-soft: #fbe4e4;
  --shadow: 0 1px 2px rgba(60, 10, 25, .04), 0 6px 18px rgba(60, 10, 25, .05);
  --radius: 16px;
  --font: "Zen Kaku Gothic New", system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  --font-title: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-num: "Inter", "Zen Kaku Gothic New", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #140b0e; --surface: #1e1216; --surface-2: #2a1a20; --text: #f3e9ec; --muted: #ad959d; --line: #36242b;
    --accent: #e58aa3; --accent-2: #f2a9bc; --accent-soft: #3d1b27; --head-1: #5e1529; --head-2: #2e0913;
    --gold: #e9c46a; --gold-soft: #3a2e15; --silver: #c0c7d0; --silver-soft: #272b31; --bronze: #e3a17a; --bronze-soft: #3b2519;
    --danger: #f58b8b; --danger-soft: #3d1a1c; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #140b0e; --surface: #1e1216; --surface-2: #2a1a20; --text: #f3e9ec; --muted: #ad959d; --line: #36242b;
  --accent: #e58aa3; --accent-2: #f2a9bc; --accent-soft: #3d1b27; --head-1: #5e1529; --head-2: #2e0913;
  --gold: #e9c46a; --gold-soft: #3a2e15; --silver: #c0c7d0; --silver-soft: #272b31; --bronze: #e3a17a; --bronze-soft: #3b2519;
  --danger: #f58b8b; --danger-soft: #3d1a1c; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.55; letter-spacing: .01em;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "palt" 1;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 10; color: #fff; padding-top: env(safe-area-inset-top);
  background: linear-gradient(135deg, var(--head-1), var(--head-2));
  box-shadow: 0 2px 12px rgba(40, 5, 15, .18);
}
.top-inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 9px; box-shadow: 0 0 0 1px rgba(255,255,255,.18); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.logo { font-family: var(--font-title); font-weight: 800; font-size: 20px; letter-spacing: .08em; }
.season { font-size: 10.5px; opacity: .72; letter-spacing: .12em; font-family: var(--font-num); text-transform: uppercase; }
.top-right { display: flex; align-items: center; gap: 4px; }
.synced { font-size: 11px; opacity: .7; font-family: var(--font-num); }
.icon-btn { background: none; border: 0; padding: 7px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:active { background: rgba(255,255,255,.15); }

.main { max-width: 760px; margin: 0 auto; padding: 16px 16px 28px; }
.loading, .empty { color: var(--muted); text-align: center; padding: 36px 16px; font-size: 14px; }
.empty small { display: block; margin-top: 4px; font-size: 12px; }
h2.sec {
  font-family: var(--font-title); font-size: 15px; font-weight: 700; color: var(--text);
  margin: 26px 2px 10px; letter-spacing: .08em; display: flex; align-items: center; gap: 8px;
}
h2.sec::before { content: ""; width: 3px; height: 14px; border-radius: 2px; background: var(--accent); }
h2.sec:first-child { margin-top: 2px; }
h2.sec .sub { margin-left: auto; font-family: var(--font-num); font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: 0; }

/* タブ */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; background: none; border: 0; padding: 8px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 500; cursor: pointer; position: relative; letter-spacing: .04em; }
.tabs svg { width: 22px; height: 22px; }
.tabs button.on { color: var(--accent); font-weight: 700; }
.tabs button.on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 2.5px; border-radius: 0 0 3px 3px; background: var(--accent); }

/* カード */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }

/* メンバーのイニシャル */
.av {
  --c: #888; width: 24px; height: 24px; border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  background: var(--c); color: #fff; font-size: 12.5px; font-weight: 700; line-height: 1;
  box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.28);
}
.av.sm { width: 19px; height: 19px; font-size: 10.5px; }
.av.lg { width: 32px; height: 32px; font-size: 16px; }

/* 順位 */
.standing { padding: 14px 16px 13px; display: grid; grid-template-columns: 30px 1fr auto; gap: 6px 12px; align-items: center; cursor: pointer; }
.standing + .standing { border-top: 1px solid var(--line); }
.rank-no { font-family: var(--font-title); font-size: 24px; font-weight: 800; text-align: center; color: var(--muted); line-height: 1; }
.rank-no.r1 { color: var(--gold); } .rank-no.r2 { color: var(--silver); } .rank-no.r3 { color: var(--bronze); }
.member { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; }
.prize-big { font-weight: 700; font-size: 20px; text-align: right; white-space: nowrap; }
.prize-big small { font-size: 11px; font-weight: 600; color: var(--muted); margin-left: 2px; font-family: var(--font); }
.substats { grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 3px 12px; font-size: 12px; color: var(--muted); }
.bar { grid-column: 2 / 4; height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }
.standing-horses { grid-column: 1 / 4; margin-top: 8px; }
.hero { padding: 18px 18px 16px; background: linear-gradient(135deg, var(--head-1), var(--head-2)); color: #fff; border: 0; }
.hero .label { font-size: 11px; letter-spacing: .14em; opacity: .75; }
.hero .who { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-family: var(--font-title); font-size: 22px; font-weight: 800; letter-spacing: .06em; }
.hero .amt { font-family: var(--font-num); font-size: 30px; font-weight: 700; margin-top: 2px; letter-spacing: -.01em; }
.hero .amt small { font-size: 13px; font-family: var(--font); opacity: .8; margin-left: 2px; }
.hero .gap { font-size: 12px; opacity: .78; }

/* 馬の行 */
.horse-row { display: grid; grid-template-columns: 1fr auto; gap: 1px 10px; padding: 12px 15px; cursor: pointer; align-items: center; }
.horse-row:active, .standing:active, .race-horse:active, .res-row:active { background: var(--surface-2); }
.hname { font-weight: 700; display: flex; align-items: center; gap: 6px; min-width: 0; }
.hname span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsub { font-size: 12px; color: var(--muted); grid-column: 1 / 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hright { text-align: right; grid-row: 1 / 3; grid-column: 2; }
.hprize { font-weight: 700; white-space: nowrap; }
.hrec { font-size: 12px; color: var(--muted); }
.nk {
  display: inline-flex; align-items: center; gap: 2px; font-size: 10.5px; font-weight: 700; color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 6px; padding: 0 6px; text-decoration: none; flex: none; line-height: 1.6;
}
.unnamed { color: var(--muted); font-weight: 600; }

/* バッジ */
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; white-space: nowrap; background: var(--surface-2); color: var(--muted); letter-spacing: .02em; }
.badge.ok { background: var(--accent); color: #fff; }
.badge.reg { background: transparent; color: var(--muted); border: 1px dashed color-mix(in srgb, var(--muted) 60%, transparent); }
.badge.ng { background: var(--danger-soft); color: var(--danger); }
.badge.g { color: #fff; font-family: var(--font-num); background: #8a7a80; }
.badge.g1 { background: #1d4ed8; } .badge.g2 { background: #c0262d; } .badge.g3 { background: #15803d; }
.badge.honmei { background: var(--gold-soft); color: var(--gold); }
.badge.mul { background: var(--accent-soft); color: var(--accent); font-family: var(--font-num); }
:root[data-theme="dark"] .badge.ok { color: #1e1216; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.ok { color: #1e1216; } }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 9px 2px 2px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.fin { display: inline-grid; place-items: center; min-width: 38px; font-weight: 700; padding: 2px 7px; border-radius: 9px; background: var(--surface-2); white-space: nowrap; font-size: 14px; }
.fin.plain { background: none; color: var(--text); font-weight: 500; padding: 2px 0; min-width: 0; }
.fin.f1 { background: var(--gold-soft); color: var(--gold); } .fin.f2 { background: var(--silver-soft); color: var(--silver); } .fin.f3 { background: var(--bronze-soft); color: var(--bronze); }

/* 出走 */
.day { margin-top: 18px; }
.day-h { display: flex; align-items: baseline; gap: 8px; margin: 0 2px 8px; }
.day-h b { font-family: var(--font-title); font-size: 18px; letter-spacing: .04em; }
.day-h span { color: var(--muted); font-size: 12px; }
.race { padding: 13px 15px; }
.race + .race { border-top: 1px solid var(--line); }
.race-h { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.race-h .time { font-family: var(--font-num); font-weight: 700; color: var(--accent); }
.race-h .rn { font-weight: 700; }
.race-h .cond { color: var(--muted); font-size: 12px; }
.race-horse { margin-top: 9px; display: grid; grid-template-columns: auto 1fr auto; gap: 2px 11px; align-items: center; cursor: pointer; border-radius: 12px; padding: 9px 11px; background: var(--surface-2); }
.umaban { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-family: var(--font-num); font-weight: 700; font-size: 15px; border: 1px solid var(--line); background: var(--surface); }
.w1 { background: #fff; color: #222; border-color: #bbb; } .w2 { background: #222; color: #fff; } .w3 { background: #d63031; color: #fff; } .w4 { background: #2d6cdf; color: #fff; }
.w5 { background: #f4c20d; color: #222; } .w6 { background: #2e9e4f; color: #fff; } .w7 { background: #f08a24; color: #fff; } .w8 { background: #f5a3c0; color: #222; }
.rh-main { min-width: 0; }
.rh-sub { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.note { font-size: 12px; color: var(--muted); margin: 10px 2px; }

/* フィルタ */
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 13px 4px 5px;
  font-size: 13px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; min-height: 32px;
}
.filters button.text { padding: 4px 13px; }
.filters button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
:root[data-theme="dark"] .filters button.on { color: #1e1216; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .filters button.on { color: #1e1216; } }
.filters.months button { font-family: var(--font-num); font-weight: 600; }
.filters.months button.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.member-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 2px 9px; }
.member-head b { font-size: 16px; display: flex; align-items: center; gap: 9px; }

/* 結果 */
.res-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 2px 11px; padding: 11px 15px; align-items: center; cursor: pointer; }
.res-date { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.25; }
.res-date b { display: block; color: var(--text); font-size: 15px; font-family: var(--font-num); }

/* シート */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(30, 5, 12, .45); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.sheet-panel::before { content: ""; display: block; width: 40px; height: 4px; background: var(--line); border-radius: 2px; margin: 0 auto 12px; }
.d-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.d-title h3 { margin: 0; font-family: var(--font-title); font-size: 24px; letter-spacing: .04em; }
.d-meta { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.d-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.d-stats > div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 8px; text-align: center; }
.d-stats b { display: block; font-size: 17px; }
.d-stats span { font-size: 11px; color: var(--muted); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 11px; padding: 9px 15px; font-weight: 700; cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px; }
.btn.primary, .btn.nkbtn { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary, :root[data-theme="dark"] .btn.nkbtn { color: #1e1216; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary, :root:not([data-theme="light"]) .btn.nkbtn { color: #1e1216; } }
.btn.small { padding: 5px 11px; font-size: 12px; border-radius: 9px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* 管理 */
.form { padding: 15px; display: grid; gap: 11px; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 700; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 9px 11px; width: 100%; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type=radio], input[type=checkbox] { accent-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.radio { display: flex; gap: 8px; flex-wrap: wrap; }
.radio label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); font-weight: 500; border: 1px solid var(--line); border-radius: 11px; padding: 8px 12px; background: var(--surface); }
.radio input { width: auto; }
.admin-pick { padding: 11px 15px; display: grid; grid-template-columns: 1fr auto; gap: 7px 10px; align-items: center; }
.swap-form { grid-column: 1 / 3; display: grid; gap: 8px; background: var(--surface-2); padding: 11px; border-radius: 12px; }
.flags { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.flags label { display: flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 700; border: 1px solid var(--line); border-radius: 9px; padding: 5px 10px; background: var(--surface); }
.flags input { width: auto; }
.flags select { width: auto; padding: 5px 8px; font-size: 13px; border-radius: 9px; }
.err { color: var(--danger); font-size: 12px; }
.log { font-family: ui-monospace, Consolas, monospace; font-size: 11px; white-space: pre-wrap; color: var(--muted); padding: 10px 14px; max-height: 260px; overflow: auto; background: var(--surface-2); border-radius: 10px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 13px; z-index: 40; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
