:root {
  --bg: #eef2ec;
  --card: #ffffff;
  --ink: #13211a;
  --muted: #5b6a61;
  --line: #d9e2da;
  --primary: #0b6b3a;
  --primary-dark: #084f2b;
  --primary-ink: #ffffff;
  --soft: #e1f0e6;
  --plus: #0a7a41;
  --minus: #c2362b;
  --under: #c2410c;
  --over: #2456c9;
  --gold: #d9a514;
  --silver: #8d98a3;
  --bronze: #b46a2a;
  --iron: #475260;
  --diamond: #1f9fd0;
  --p0: #2563eb;
  --p1: #dc2626;
  --p2: #d97706;
  --p3: #059669;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 40, 26, .06), 0 4px 14px rgba(16, 40, 26, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1612;
    --card: #18231d;
    --ink: #eaf2ec;
    --muted: #9baba1;
    --line: #2a3a31;
    --primary: #2fa565;
    --primary-dark: #258a53;
    --primary-ink: #06140c;
    --soft: #1d3327;
    --plus: #4fd08a;
    --minus: #ff8377;
    --under: #ffa15c;
    --over: #86a9ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .35; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.page {
  max-width: 540px;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.page.play { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

.muted { color: var(--muted); }
.small, small { font-size: .78rem; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.zero { color: var(--muted); }
.under { color: var(--under); }
.over { color: var(--over); }
.center { text-align: center; }

/* ホーム */
.hero {
  margin: 0 -16px;
  padding: calc(28px + env(safe-area-inset-top)) 20px 26px;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  border-radius: 0 0 24px 24px;
}
.hero h1 { margin: 2px 0 6px; font-size: 2.3rem; letter-spacing: .04em; line-height: 1.15; }
.hero-kicker { margin: 0; font-size: .82rem; opacity: .85; letter-spacing: .08em; }
.hero-sub { margin: 0; font-size: .9rem; opacity: .9; }

.sec { margin: 12px 4px 0; font-size: .86rem; color: var(--muted); font-weight: 700; letter-spacing: .04em; }
.empty { margin: 0 4px; color: var(--muted); font-size: .92rem; }
.hint { margin: 0; color: var(--muted); font-size: .82rem; }
.banner {
  margin: 0; padding: 12px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--minus) 12%, var(--card));
  color: var(--minus); font-size: .9rem; font-weight: 600;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.btn {
  min-height: 48px; padding: 10px 16px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); font-weight: 700;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.big { min-height: 56px; font-size: 1.06rem; box-shadow: var(--shadow); }
.btn.ghost { background: transparent; color: var(--primary); border-color: color-mix(in srgb, var(--primary) 40%, transparent); }
.btn.slim { min-height: 44px; font-size: .9rem; }
.btn.danger { background: transparent; border-color: transparent; color: var(--minus); font-weight: 600; }

.round-card { display: block; width: 100%; text-align: left; border: 0; }
.rc-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.rc-top strong { font-size: 1.02rem; overflow-wrap: anywhere; }
.rc-top span { font-size: .8rem; white-space: nowrap; }
.rc-games { font-size: .8rem; margin: 2px 0 10px; }
.rc-players { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; }
.rc-p { display: flex; justify-content: space-between; gap: 8px; font-size: .92rem; }
.rc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-pt { font-weight: 700; font-variant-numeric: tabular-nums; }

.list { padding: 4px 14px; }
.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row strong { font-variant-numeric: tabular-nums; font-size: 1.05rem; white-space: nowrap; }
.place {
  display: inline-grid; place-items: center; width: 24px; height: 24px; margin-right: 8px;
  border-radius: 50%; background: var(--soft); color: var(--primary);
  font-style: normal; font-size: .78rem; font-weight: 800;
}
.rank .list-row:first-child .place { background: var(--gold); color: #3a2a00; }

/* トップ画面のルール画像 */
.gallery-wrap { display: flex; flex-direction: column; gap: 8px; }
.gallery-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.gallery-arrows { display: flex; gap: 6px; }
.gallery-arrows button {
  width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid color-mix(in srgb, var(--primary) 45%, var(--line));
  background: var(--card); color: var(--primary); font-size: 1.5rem; line-height: 1;
}
.gallery {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity;
  margin: 0 -16px; padding: 2px 16px 10px; scrollbar-width: thin; scrollbar-color: var(--primary) transparent;
}
.gcard {
  flex: 0 0 46%; max-width: 210px; padding: 0; border: 0; border-radius: 14px; overflow: hidden;
  background: var(--card); box-shadow: var(--shadow); scroll-snap-align: start; scroll-margin-left: 16px;
}
.gcard img { display: block; width: 100%; height: auto; }
body.no-scroll { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: rgba(8, 14, 10, .94); }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px; color: #fff;
}
.viewer-close { width: 46px; height: 46px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .14); color: #fff; font-size: 1.6rem; line-height: 1; }
.viewer-body { flex: 1; overflow-y: auto; padding: 0 12px; display: flex; justify-content: center; align-items: flex-start; }
.viewer-body img { display: block; width: 100%; max-width: 520px; height: auto; border-radius: 12px; }
.viewer-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.viewer-nav .btn { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .25); color: #fff; }
.viewer button:focus-visible { outline-color: #fff; }

/* 上部バー */
.topbar {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 6px;
  padding-top: calc(8px + env(safe-area-inset-top));
  min-height: 52px;
}
.topbar h1 { margin: 0; font-size: 1.05rem; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  min-width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent;
  font-size: 1.7rem; line-height: 1; color: var(--primary);
}
.icon-btn.text { font-size: .88rem; font-weight: 700; padding: 0 8px; }
.icon-btn.spacer { visibility: hidden; }

/* フォーム */
.form { display: flex; flex-direction: column; gap: 4px; padding: 6px 14px; }
.field {
  display: grid; grid-template-columns: 5.2em 1fr; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.field:last-of-type { border-bottom: 0; }
.field > span { font-size: .88rem; color: var(--muted); font-weight: 600; }
.field input[type="text"], .field input[type="date"], .field input[type="number"] {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.field.num { grid-template-columns: 1fr 6.5em; }
.field.num input { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.field.check-field { grid-template-columns: 24px 1fr; }
.field.check-field input { width: 22px; height: 22px; accent-color: var(--primary); }

/* ゴルフ場検索 */
.form > .btn.slim { margin: 4px 0 8px; }
.search { display: flex; flex-direction: column; gap: 10px; padding: 10px 0 8px; border-bottom: 1px solid var(--line); }
.search .seg { align-self: flex-start; }
.search-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.search-form input {
  width: 100%; min-width: 0; min-height: 46px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.search-form .btn { min-height: 46px; }
.results { display: flex; flex-direction: column; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; }
.result { display: block; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.result:last-child { border-bottom: 0; }
.result:active { background: var(--soft); }
.result b { display: block; font-size: .96rem; overflow-wrap: anywhere; }
.result small { color: var(--muted); }
.credit { margin: 0; font-size: .7rem; text-align: right; }
.credit a { color: var(--muted); }
.hint.ok { color: var(--plus); font-weight: 600; margin-top: 6px; }
.hint.warn { color: var(--minus); font-weight: 600; margin-top: 6px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.seg button { min-height: 42px; min-width: 56px; padding: 6px 14px; border: 0; background: transparent; font-weight: 700; font-size: .9rem; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--primary); color: var(--primary-ink); }

.games { padding: 4px; display: flex; flex-direction: column; }
.game-row {
  display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start;
  padding: 11px 10px; border: 0; border-radius: 12px; background: transparent; text-align: left;
}
.game-row + .game-row { border-top: 1px solid var(--line); border-radius: 0; }
.game-row.on { background: var(--soft); border-radius: 12px; border-top-color: transparent; }
.game-row.on + .game-row { border-top-color: transparent; }
.check {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line);
  display: grid; place-items: center; font-weight: 900; font-size: .9rem; color: var(--primary-ink);
}
.game-row.on .check { background: var(--primary); border-color: var(--primary); }
.game-text b { display: block; font-size: .98rem; }
.game-text em {
  font-style: normal; font-size: .68rem; font-weight: 700; margin-left: 8px; padding: 2px 6px;
  border-radius: 6px; background: var(--card); color: var(--muted); border: 1px solid var(--line); vertical-align: 2px;
}
.game-text small { color: var(--muted); display: block; line-height: 1.45; }

.par-row { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; margin-top: 8px; }
.par-cell {
  display: flex; flex-direction: column; align-items: center; padding: 5px 0;
  min-height: 48px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg);
}
.par-cell small { color: var(--muted); font-size: .64rem; }
.par-cell b { font-size: 1.08rem; }

/* プレー画面 */
.sticky {
  position: sticky; top: 0; z-index: 5;
  margin: 0 -16px; padding: 0 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.hole-head { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 14px; padding: 2px 4px 8px; }
.hole-no { font-size: 1.1rem; font-weight: 800; color: var(--primary); }
.hole-no b { font-size: 2.1rem; line-height: 1; margin-right: 1px; }
.hole-par { display: flex; align-items: center; gap: 8px; font-size: .78rem; font-weight: 800; color: var(--muted); letter-spacing: .06em; }
.hole-pos { text-align: right; font-size: .78rem; }

.hstrip { position: relative; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.hstrip::-webkit-scrollbar { display: none; }
.htab {
  flex: 0 0 auto; min-width: 50px; min-height: 46px; padding: 3px 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 11px; background: var(--card); color: var(--muted);
}
.htab b { font-size: .88rem; }
.htab small { font-size: .64rem; }
.htab.done { color: var(--ink); border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.htab.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.pcard { display: flex; flex-direction: column; gap: 10px; }
.prow { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; }
.pname { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.04rem; min-width: 0; }
.pname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pnum {
  flex: 0 0 auto; display: inline-grid; place-items: center; width: 26px; height: 26px;
  border-radius: 50%; color: #fff; font-style: normal; font-size: .8rem; font-weight: 800;
}
.c0 { background: var(--p0); } .c1 { background: var(--p1); } .c2 { background: var(--p2); } .c3 { background: var(--p3); }
.stepper { display: flex; align-items: center; gap: 6px; grid-row: span 2; }
.step {
  width: 50px; height: 50px; border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--primary) 45%, var(--line));
  background: var(--card); color: var(--primary); font-size: 1.6rem; font-weight: 500; line-height: 1;
}
.step:active { background: var(--soft); }
.score {
  min-width: 52px; height: 50px; border: 0; background: transparent;
  font-size: 2.1rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1;
}
.score.unset { color: var(--line); }
.diff { font-size: .82rem; font-weight: 700; padding-left: 34px; color: var(--muted); }
.diff.under { color: var(--under); }
.diff.over { color: var(--over); }
.diff.even { color: var(--plus); }

.orow { display: flex; align-items: center; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.hole-opts .orow:first-child { padding-top: 0; border-top: 0; }
.hole-opts { display: flex; flex-direction: column; gap: 10px; }
.olabel { flex: 0 0 4.4em; font-size: .78rem; font-weight: 700; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 42px; padding: 6px 13px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--bg); font-size: .88rem; font-weight: 700; color: var(--muted);
}
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chips:has(.medal) { gap: 4px; }
.chip.medal { min-width: 34px; padding: 6px 5px; font-size: .84rem; white-space: nowrap; }
.chip.medal.none { padding: 6px 8px; }
.chip.medal.none.on { background: var(--muted); border-color: var(--muted); color: var(--card); }

.reach-x { display: inline-flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); }
.reach-x b { padding: 3px 10px; border-radius: 8px; background: var(--soft); color: var(--primary); font-size: .95rem; font-variant-numeric: tabular-nums; }
.reach-mode { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.reach-mode > span { font-size: .88rem; color: var(--muted); font-weight: 600; }
.reach-mode .seg { align-self: flex-start; max-width: 100%; }
.reach-mode .seg button { min-width: 0; padding: 6px 10px; font-size: .82rem; }

/* ゴルマーの役の内訳 */
.yaku { display: flex; align-items: flex-start; gap: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.yaku .olabel { padding-top: 4px; }
.yaku-list { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.yaku-tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 8px;
  background: var(--soft); color: var(--ink); font-size: .78rem; font-weight: 700;
}
.yaku-tag b { font-variant-numeric: tabular-nums; }
.yaku-tag.plus b { color: var(--plus); }
.yaku-tag.minus { background: color-mix(in srgb, var(--minus) 12%, var(--card)); }
.yaku-tag.minus b { color: var(--minus); }
.yaku-sum { font-size: .84rem; font-weight: 800; margin-left: 2px; }

/* 精算 */
.settle { display: flex; flex-direction: column; gap: 10px; }
.settle .field { border-bottom: 0; padding: 0; }
.settle h3 { margin: 4px 0 0; font-size: .82rem; color: var(--muted); }
.rate-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rate-label { font-size: .86rem; color: var(--muted); font-weight: 600; }
.rate-row .rate-pick { flex: 0 0 auto; }
.half-turn { border: 2px solid var(--gold); }
.half-turn h3 { margin: 0; font-size: .95rem; color: var(--ink); }
.rate-pick { display: flex; align-items: center; gap: 5px; }
.rate-pick select { min-width: 6.4em; }
.rate-row select {
  min-height: 46px; min-width: 0; max-width: 100%; padding: 8px 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink);
  font: inherit; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; text-align-last: right;
}
.rate-step {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid color-mix(in srgb, var(--primary) 45%, var(--line));
  background: var(--card); color: var(--primary); font-size: 1.4rem; line-height: 1;
}
.link { align-self: flex-start; min-height: 36px; padding: 4px 0; border: 0; background: transparent; color: var(--primary); font-size: .84rem; font-weight: 700; text-decoration: underline; }
.list.flat { padding: 0; border-top: 1px solid var(--line); }
.moves { display: flex; flex-direction: column; gap: 6px; }
.move {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 12px; background: var(--soft);
}
.move-names { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; flex-wrap: wrap; }
.move-names i { font-style: normal; color: var(--primary); font-weight: 900; }
.move strong { font-size: 1.08rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.medal.gold { border-color: var(--gold); }
.chip.medal.silver { border-color: var(--silver); }
.chip.medal.bronze { border-color: var(--bronze); }
.chip.medal.iron { border-color: var(--iron); }
.chip.medal.diamond { border-color: var(--diamond); }
.chip.medal.gold.on { background: var(--gold); color: #3a2a00; }
.chip.medal.silver.on { background: var(--silver); color: #fff; }
.chip.medal.bronze.on { background: var(--bronze); color: #fff; }
.chip.medal.iron.on { background: var(--iron); color: #fff; }
.chip.medal.diamond.on { background: var(--diamond); color: #fff; }

.counter { display: inline-flex; align-items: center; gap: 4px; }
.counter button {
  width: 42px; height: 42px; border-radius: 50%; border: 1.5px solid var(--line);
  background: var(--bg); font-size: 1.3rem; line-height: 1; color: var(--primary);
}
.counter b { min-width: 30px; text-align: center; font-size: 1.2rem; font-variant-numeric: tabular-nums; }

/* 表 */
.pts { padding: 12px 10px; }
.pts h3 { margin: 0 4px 8px; font-size: .86rem; color: var(--muted); }
.pts .hint { margin: 10px 4px 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 4px; text-align: center; border-bottom: 1px solid var(--line); font-size: .95rem; }
td { font-weight: 700; }
tbody th, tfoot th { text-align: left; font-size: .82rem; font-weight: 700; padding-left: 4px; }
thead th { font-size: .78rem; color: var(--muted); font-weight: 700; max-width: 5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
thead th.col { background: transparent; }
thead th.c0 { color: var(--p0); } thead th.c1 { color: var(--p1); } thead th.c2 { color: var(--p2); } thead th.c3 { color: var(--p3); }
th small, td small { display: block; font-weight: 500; color: var(--muted); font-size: .68rem; line-height: 1.3; }
td small.minus { color: var(--minus); }
tfoot th, tfoot td { border-bottom: 0; border-top: 2px solid var(--line); font-size: 1rem; }
.scorecard th, .scorecard td { padding: 6px 4px; font-size: .9rem; }
.scorecard tbody th { text-align: center; color: var(--muted); }
.scorecard tr.sum th, .scorecard tr.sum td { background: var(--soft); font-weight: 800; color: var(--ink); }
.board-meta { margin: -6px 0 0; text-align: center; font-size: .84rem; }

/* 下部ナビ */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px;
  max-width: 540px; margin: 0 auto;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.bottom .btn { min-height: 52px; padding: 8px 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--bg);
  font-size: .9rem; font-weight: 700; z-index: 20;
}

@media (max-width: 360px) {
  .step { width: 44px; height: 44px; }
  .score { min-width: 44px; font-size: 1.8rem; }
  .olabel { flex-basis: 3.8em; }
}
