:root {
  --bg: #f3f5f1;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --ink: #17201a;
  --ink-2: #4a564d;
  --ink-3: #7a857c;
  --line: #d9e0d8;
  --brand: #166534;
  --brand-ink: #ffffff;
  --brand-soft: #dcfce7;
  --accent: #b45309;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --info-soft: #dbeafe;
  --info-ink: #1e40af;
  --under: #fde2e1;   /* パー未満 */
  --under-ink: #b91c1c;
  --bogey: #e0ecff;
  --bogey-ink: #1d4ed8;
  --double: #bfd5fb;
  --double-ink: #1e3a8a;
  --c-cur: #e11d48;   /* 今回 */
  --c-p0: #2563eb;    /* 前回 */
  --c-p1: #d97706;    /* 前々回 */
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1511;
    --surface: #18211b;
    --surface-2: #212c24;
    --ink: #e8eee9;
    --ink-2: #b4c0b7;
    --ink-3: #87938a;
    --line: #2e3a31;
    --brand: #22a355;
    --brand-ink: #06210f;
    --brand-soft: #173a24;
    --accent: #f59e0b;
    --danger: #f87171;
    --danger-soft: #3b1717;
    --info-soft: #172744;
    --info-ink: #93c5fd;
    --under: #4a1d1d;
    --under-ink: #fca5a5;
    --bogey: #1b2b4a;
    --bogey-ink: #93c5fd;
    --double: #22396b;
    --double-ink: #bfdbfe;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom));
}
body.no-tabs .view { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.loading { text-align: center; color: var(--ink-3); padding: 48px 0; }

/* ---------- 下部タブ ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
body.no-tabs .tabs { display: none; }
.tabs a {
  flex: 1; max-width: 140px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-3); font-size: .75rem;
}
.tabs a span { font-size: 1.35rem; line-height: 1; }
.tabs a.on { color: var(--brand); font-weight: 700; }

/* ---------- 共通部品 ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.topbar h1 { font-size: 1.3rem; flex: 1; }
.topbar h2 { flex: 1; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; background: var(--brand-soft); color: var(--brand); white-space: nowrap;
}
.badge.warn { background: var(--danger-soft); color: var(--danger); }
.badge.live { background: var(--info-soft); color: var(--info-ink); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin: 0 0 14px;
}
.card > h3 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.card > h3 .more { margin-left: auto; font-size: .85rem; font-weight: 400; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.hint { font-size: .8rem; color: var(--ink-3); margin: 6px 0 0; }
.empty { color: var(--ink-3); font-size: .9rem; padding: 6px 0; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
  text-decoration: none; color: var(--ink);
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 60px; font-size: 1.1rem; border-radius: 16px; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 1.2rem; display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}

[hidden] { display: none !important; }
.field { display: block; margin-bottom: 12px; }
.field > span:first-child { display: block; font-size: .85rem; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
details.card > summary { cursor: pointer; padding: 2px 0; }
details.card[open] > summary { margin-bottom: 10px; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; word-break: break-all; }
input[type=text], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
textarea { min-height: 80px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; min-height: 44px; border: 0; background: var(--surface); font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand); color: var(--brand-ink); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: .85rem; font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.chip:not(.on) .dot { opacity: .35; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list a.item, .list .item {
  display: flex; align-items: center; gap: 12px; padding: 10px 2px; color: inherit; text-decoration: none;
}
.item .main { flex: 1; min-width: 0; }
.item .t1 { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .t2 { font-size: .8rem; color: var(--ink-3); }
.item .score { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.item .score small { font-size: .75rem; font-weight: 600; color: var(--ink-3); margin-left: 2px; }

/* ---------- ホーム ---------- */
.resume {
  display: block; text-decoration: none; color: var(--ink);
  background: var(--brand-soft); border: 1.5px solid var(--brand); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 12px;
}
.resume b { color: var(--brand); }
.start-btn { margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.kpi .k { font-size: .78rem; color: var(--ink-2); }
.kpi .v { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .v small { font-size: .8rem; font-weight: 600; color: var(--ink-3); margin-left: 2px; }

.tasks li { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.tasks li input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.tasks li.done span { text-decoration: line-through; color: var(--ink-3); }
.tasks li span { flex: 1; }
.tasks li button { border: 0; background: none; color: var(--ink-3); font-size: 1.1rem; width: 36px; height: 36px; }
.add-row { display: flex; gap: 8px; margin-top: 8px; }
.add-row input { flex: 1; }

/* ---------- 前2回プレビュー ---------- */
.prev-sum { display: grid; gap: 8px; }
.prev-sum .p { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.prev-sum .p .main { flex: 1; font-size: .85rem; }
.prev-sum .p b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 6px; color: #fff; white-space: nowrap; }
.tag.cur { background: var(--c-cur); }
.tag.p0 { background: var(--c-p0); }
.tag.p1 { background: var(--c-p1); }

/* ---------- プレー画面 ---------- */
.play-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.play-head .ttl { flex: 1; min-width: 0; text-align: center; }
.play-head .c { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play-head .s { font-size: .78rem; color: var(--ink-3); }

.hole-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.hole-nav .icon-btn { width: 52px; height: 52px; font-size: 1.6rem; }
.hole-nav .mid { flex: 1; text-align: center; }
.hole-nav .hn { font-size: 2.2rem; font-weight: 900; line-height: 1; }
.hole-nav .hn small { font-size: 1rem; font-weight: 700; margin-left: 2px; }
.hole-nav .par { display: inline-flex; align-items: center; gap: 4px; font-size: .9rem; color: var(--ink-2); margin-top: 2px; }
.hole-nav .par select { width: auto; min-height: 32px; padding: 2px 8px; font-weight: 700; }

.memo-banner {
  background: #fff7e6; color: #7c4a03; border: 1px solid #f5d38a; border-radius: 12px;
  padding: 8px 12px; margin-bottom: 10px; font-size: .9rem; white-space: pre-wrap;
}
@media (prefers-color-scheme: dark) { .memo-banner { background: #33260b; color: #fcd68a; border-color: #5c4513; } }

.score-box { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.score-big { font-size: 3.4rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.score-big small { font-size: 1rem; font-weight: 700; margin-left: 2px; }
.score-side { flex: 1; }
.rel { display: inline-block; font-weight: 800; padding: 1px 10px; border-radius: 8px; font-size: .95rem; background: var(--surface-2); }
.rel.under { background: var(--under); color: var(--under-ink); }
.rel.bogey { background: var(--bogey); color: var(--bogey-ink); }
.rel.double { background: var(--double); color: var(--double-ink); }
.score-break { font-size: .82rem; color: var(--ink-2); margin-top: 4px; }

.live {
  display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
  margin-bottom: 10px; font-size: .85rem; color: var(--ink-2);
}
.live b { font-size: 1.25rem; color: var(--ink); font-variant-numeric: tabular-nums; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.actions button {
  min-height: 64px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface);
  font-size: 1.05rem; font-weight: 800; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2;
}
.actions button small { font-size: .72rem; font-weight: 600; opacity: .85; margin-top: 3px; }
.actions .b-shot { grid-column: 1 / -1; min-height: 84px; font-size: 1.35rem; background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.actions .b-putt { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.actions .b-pen { color: var(--danger); }
.actions .b-undo { grid-column: 1 / -1; min-height: 44px; font-size: .9rem; font-weight: 600; color: var(--ink-2); }
.actions button:active { transform: scale(.98); }

.shot-list { list-style: none; margin: 0; padding: 0; }
.shot-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); }
.shot-list li:first-child { border-top: 0; }
.sn {
  flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--c-cur); color: #fff;
  font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: .9rem; margin-top: 4px;
}
.sn.putt { background: var(--brand); }
.sn.pen { background: var(--danger); }
.si { flex: 1; min-width: 0; }
.si .sel { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.si select { min-height: 38px; padding: 4px 8px; font-size: 15px; }
.si .meta { font-size: .78rem; color: var(--ink-3); margin-top: 3px; }
.si .meta b { color: var(--ink); }
.shot-list .del { flex: none; border: 0; background: none; color: var(--ink-3); width: 36px; height: 36px; font-size: 1.1rem; margin-top: 2px; }

.map-card { padding: 10px; }
.map-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.map { height: 340px; border-radius: 10px; overflow: hidden; background: var(--surface-2); position: relative; z-index: 0; }
.map.tapping { outline: 3px solid var(--accent); outline-offset: -3px; }
.map-tools2 { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.map-fallback { width: 100%; height: 100%; display: block; }
.map-note { position: absolute; left: 8px; right: 8px; bottom: 8px; font-size: .75rem; color: var(--ink-2); background: var(--surface); border-radius: 8px; padding: 4px 8px; opacity: .92; }

.pin {
  width: 28px; height: 28px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5); font-family: system-ui, sans-serif;
}
.pin.small { width: 22px; height: 22px; font-size: 11px; }
.pin.flag { background: #fff; color: #166534; border-color: #166534; font-size: 15px; }

.prev-hole { display: grid; gap: 10px; }
.prev-hole .ph { border-left: 4px solid var(--line); padding: 2px 0 2px 10px; }
.prev-hole .ph.p0 { border-color: var(--c-p0); }
.prev-hole .ph.p1 { border-color: var(--c-p1); }
.prev-hole .ph .h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem; }
.prev-hole .ph .h b { font-size: 1.3rem; }
.prev-hole .ph .route { font-size: .8rem; color: var(--ink-2); margin-top: 2px; }

.play-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
.play-foot .inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1.2fr 1.4fr; gap: 8px; }
.play-foot .btn { min-height: 56px; }

/* ---------- スコアカード ---------- */
.sc-wrap { overflow-x: auto; margin: 0 -4px; }
table.sc { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9rem; }
table.sc th, table.sc td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: center; white-space: nowrap; }
table.sc thead th { font-size: .78rem; color: var(--ink-2); font-weight: 600; vertical-align: bottom; }
table.sc thead th .tag { margin-bottom: 2px; }
table.sc tbody tr.hole { cursor: pointer; }
table.sc tbody tr.hole:active { background: var(--surface-2); }
table.sc td.h { font-weight: 800; text-align: left; padding-left: 6px; }
table.sc td.h small { font-weight: 600; color: var(--ink-3); margin-left: 4px; }
table.sc .cell { display: inline-flex; align-items: baseline; justify-content: center; min-width: 40px; padding: 2px 6px; border-radius: 8px; font-weight: 800; font-size: 1.05rem; }
table.sc .cell small { font-size: .7rem; font-weight: 600; color: var(--ink-3); margin-left: 2px; }
table.sc .cell.under { background: var(--under); color: var(--under-ink); }
table.sc .cell.bogey { background: var(--bogey); color: var(--bogey-ink); }
table.sc .cell.double { background: var(--double); color: var(--double-ink); }
table.sc tr.sum td { background: var(--surface-2); font-weight: 800; }
table.sc tr.sum.total td { font-size: 1.05rem; }
table.sc col.cur { background: color-mix(in srgb, var(--c-cur) 6%, transparent); }

details.shots { border-top: 1px solid var(--line); padding: 8px 0; }
details.shots summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
details.shots table { width: 100%; border-collapse: collapse; font-size: .78rem; margin-top: 6px; }
details.shots th, details.shots td { border-bottom: 1px solid var(--line); padding: 4px 3px; text-align: left; }
details.shots th { color: var(--ink-3); font-weight: 600; }

/* ---------- 分析 ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--brand); stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart .hit:hover + .dot, .chart .hit:focus + .dot { r: 6.5px; fill: var(--accent); }
.chart .lbl { fill: var(--ink-2); font-size: 12px; font-weight: 700; }
table.mini { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.mini th, table.mini td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: center; }
table.mini th { font-size: .8rem; color: var(--ink-3); font-weight: 600; }
.chart-tip { font-size: .85rem; color: var(--ink-2); min-height: 1.4em; margin-top: 4px; }
table.clubs { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.clubs th, table.clubs td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
table.clubs th:first-child, table.clubs td:first-child { text-align: left; }
table.clubs th { font-size: .8rem; color: var(--ink-3); font-weight: 600; }

/* ---------- 設定・プラン ---------- */
.plan-box { display: grid; gap: 10px; }
.plan {
  border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  display: flex; align-items: center; gap: 12px; background: var(--surface);
}
.plan.best { border-color: var(--brand); }
.plan .main { flex: 1; }
.plan .price { font-size: 1.5rem; font-weight: 900; }
.plan .price small { font-size: .8rem; font-weight: 600; color: var(--ink-3); }
.legal-note { font-size: .78rem; color: var(--ink-2); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 10px 0 0; }
.legal-note ul { margin: 4px 0 0; padding-left: 1.2em; }

.par-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.par-grid label { display: flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 700; }
.par-grid select { min-height: 38px; padding: 4px 6px; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: .9rem; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 2000; max-width: calc(100% - 32px); text-align: center;
}
body.no-tabs .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.leaflet-container { font-family: inherit; }
