:root {
  --bg: #121214;
  --panel: #1c1c20;
  --panel2: #26262b;
  --line: #34343b;
  --text: #f2f2f4;
  --sub: #9a9aa3;
  --accent: #ff5a36;
  --accent-dim: #4a2219;
  --good: #3ccf7a;
  --good-dim: #173a26;
  --bad: #ff6b6b;
  --bad-dim: #3d1d1f;
  --radius: 14px;
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
[hidden] { display: none !important; }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: linear-gradient(var(--bg) 80%, transparent);
}
.top h1 { font-size: 20px; margin: 0; letter-spacing: .02em; }
.me-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; background: var(--panel2);
  font-weight: 700; max-width: 60%;
}
.me-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-chip::after { content: "▾"; color: var(--sub); font-size: 12px; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #f5b83d; flex: none; }

/* 下のタブ */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: rgba(18, 18, 20, .96); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  backdrop-filter: blur(8px);
}
.nav-in { display: flex; width: 100%; max-width: 560px; }
.nav button {
  flex: 1; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--sub); font-size: 12px; font-weight: 600;
}
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--accent); }

/* 共通パーツ */
.card { background: var(--panel); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 14px; color: var(--sub); margin: 0 0 10px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.muted { color: var(--sub); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

.seg { display: flex; background: var(--panel); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 9px 4px; border-radius: 9px; font-weight: 700; color: var(--sub); font-size: 14px; }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.datebar { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.datebar .label { flex: 1; text-align: center; font-weight: 700; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; background: var(--panel);
  display: grid; place-items: center; font-size: 18px; color: var(--sub);
}
.pill { padding: 8px 12px; border-radius: 10px; background: var(--panel); font-weight: 700; font-size: 13px; }
.pill.accent { background: var(--accent-dim); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 16px; border-radius: 12px; background: var(--panel2); font-weight: 700;
  white-space: nowrap; flex: none;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; }

input[type=text], input[type=number], input[type=password], input[type=date] {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line); outline: none;
}
input:focus { border-color: var(--accent); }

/* 今日カード */
.today { display: grid; grid-template-columns: 1.2fr 1fr; gap: 10px; align-items: center; }
.today .big { font-size: 40px; font-weight: 800; line-height: 1.05; }
.today .big small { font-size: 18px; font-weight: 700; color: var(--sub); }
.delta { font-size: 13px; font-weight: 700; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.minis { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mini { background: var(--panel2); border-radius: 10px; padding: 7px 9px; }
.mini .k { font-size: 11px; color: var(--sub); }
.mini .v { font-weight: 800; font-size: 16px; }
.mini .v small { font-size: 11px; color: var(--sub); font-weight: 600; margin-left: 3px; }

/* コート */
.court { width: 100%; display: block; user-select: none; }
.court .lines { fill: none; stroke: #5b5b63; stroke-width: 2; }
.court .rim { fill: none; stroke: var(--accent); stroke-width: 3; }
.court .spot circle { stroke: #4a4a52; stroke-width: 1.5; transition: r .15s; }
.court .spot text { fill: var(--text); font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.court .spot.sel circle { stroke: var(--accent); stroke-width: 4; }
.court .spot.cur circle { stroke: var(--accent); stroke-width: 4; animation: pulse 1.2s ease-in-out infinite; }
.court .spot.done text { fill: #fff; }
.court .spot.tap { cursor: pointer; }
.court .spot.off { opacity: .25; }
@keyframes pulse { 50% { stroke-opacity: .35; } }
.ft-btn {
  display: flex; justify-content: space-between; align-items: center;
  width: 70%; margin: 8px auto 0; padding: 10px 14px; border-radius: 12px;
  background: var(--panel2); border: 2px solid transparent; font-weight: 700;
}
.ft-btn.sel { border-color: var(--accent); }

/* 記録ボタン */
.spot-head { display: flex; justify-content: space-between; align-items: baseline; margin: 4px 2px 10px; }
.spot-head .name { font-size: 20px; font-weight: 800; }
.spot-head .tag { font-size: 12px; color: var(--sub); font-weight: 700; margin-right: 6px; }
.hit-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hit {
  height: 92px; border-radius: 16px; font-size: 22px; font-weight: 800;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .06s;
}
.hit:active { transform: scale(.97); }
.hit .mark { font-size: 30px; line-height: 1; }
.hit.make { background: var(--good-dim); color: var(--good); }
.hit.miss { background: var(--bad-dim); color: var(--bad); }

details.bulk { margin-top: 12px; }
details.bulk summary { color: var(--sub); font-size: 14px; font-weight: 600; cursor: pointer; padding: 4px 0; }
.bulk-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 8px; align-items: end; }
.bulk-grid label { font-size: 12px; color: var(--sub); }

/* 履歴 */
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.hist li:first-child { border-top: 0; }
.hist .res { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; flex: none; font-size: 13px; }
.hist .res.m { background: var(--good-dim); color: var(--good); }
.hist .res.x { background: var(--bad-dim); color: var(--bad); }
.hist .res.n { background: var(--panel2); color: var(--text); font-size: 11px; width: auto; padding: 0 6px; }
.hist .what { flex: 1; min-width: 0; }
.hist .del { color: var(--sub); padding: 6px 8px; font-size: 13px; }
.pending { color: #f5b83d; font-size: 11px; margin-left: 4px; }

/* メニュー */
.menu-list { display: grid; gap: 8px; }
.menu-item { display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 14px; border-radius: 12px; background: var(--panel2); width: 100%; }
.menu-item b { display: block; }
.menu-item .go { color: var(--accent); font-weight: 800; }
.progress { height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.counter { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 6px 0 12px; }
.counter .made { font-size: 48px; font-weight: 800; color: var(--good); }
.counter .of { font-size: 20px; color: var(--sub); font-weight: 700; }
.dots { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-bottom: 12px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--panel2); }
.dots i.m { background: var(--good); }
.dots i.x { background: var(--bad); }
.tool-row { display: flex; gap: 8px; margin-top: 10px; }
.tool-row .btn { flex: 1; padding: 10px 6px; font-size: 13px; }
.numgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 10px; }
.numgrid button { padding: 12px 0; border-radius: 10px; background: var(--panel2); font-weight: 800; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 7px 12px; border-radius: 999px; background: var(--panel2); font-weight: 700; font-size: 13px; }
.chips button.on { background: var(--accent); color: #fff; }

/* 成績 */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--panel); border-radius: 12px; padding: 10px; }
.kpi .k { font-size: 12px; color: var(--sub); font-weight: 600; }
.kpi .v { font-size: 24px; font-weight: 800; line-height: 1.2; }
.kpi .s { font-size: 12px; color: var(--sub); }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 6.5em 1fr 5.2em; gap: 8px; align-items: center; font-size: 13px; }
.bar { height: 10px; background: var(--panel2); border-radius: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 5px; }
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); cursor: pointer; }
.rank li:first-child { border-top: 0; }
.rank .pos { font-weight: 800; color: var(--sub); text-align: center; }
.rank .who b { display: block; }
.rank .main { text-align: right; font-weight: 800; font-size: 18px; }
.rank .main small { display: block; font-size: 11px; color: var(--sub); font-weight: 600; }
.rank li.me .who b { color: var(--accent); }
.rank li.few { opacity: .55; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--sub); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.chart text { fill: var(--sub); font-size: 17px; }

/* その他 */
.form-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; padding: 10px 0; border-top: 1px solid var(--line); }
.form-row:first-of-type { border-top: 0; }
.form-row .lbl { font-weight: 700; margin-bottom: 4px; }
.form-row .lbl small { color: var(--sub); font-weight: 500; margin-left: 6px; }
.unit { display: flex; align-items: center; gap: 6px; }
.unit span { color: var(--sub); font-size: 13px; flex: none; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { color: var(--sub); font-weight: 600; font-size: 12px; text-align: right; padding: 4px 0; }
.tbl td { text-align: right; padding: 8px 0; border-top: 1px solid var(--line); }
.tbl th:first-child, .tbl td:first-child { text-align: left; }

/* 選手選択・合言葉 */
.center-screen { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px 16px; max-width: 480px; margin: 0 auto; }
.center-screen h1 { font-size: 24px; margin: 0 0 4px; }
.names { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 16px 0; }
.names button { padding: 14px 8px; border-radius: 12px; background: var(--panel); font-weight: 700; }
.names button.on { background: var(--accent); color: #fff; }

.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 85vh; overflow: auto; background: var(--panel); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet .names button { background: var(--panel2); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 14px;
  background: #f2f2f4; color: #121214; padding: 10px 10px 10px 16px; border-radius: 12px;
  font-weight: 700; font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  max-width: calc(100% - 32px);
}
.toast button { color: #d63a17; font-weight: 800; padding: 6px 8px; white-space: nowrap; flex: none; }
.err { color: var(--bad); font-size: 13px; margin-top: 6px; }
.empty { color: var(--sub); text-align: center; padding: 18px 0; font-size: 14px; }

/* おすすめメニュー */
.rec-card { background: var(--accent-dim); border: 1px solid #6b2e20; border-radius: 12px; padding: 12px; margin-bottom: 16px; }
.rec-list { list-style: none; margin: 8px 0 10px; padding: 0; }
.rec-list li { display: grid; grid-template-columns: 1fr auto 6.5em; gap: 8px; align-items: center; padding: 5px 0; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 14px; }
.rec-list li:first-child { border-top: 0; }
.rec-list li .num { text-align: right; }
