/* RUNCLUB — ธีมจากโลโก้: ป่าสนยามรุ่ง (พื้นเขียวถ่าน) · ถนนสีขาวนวล · ภูเขาสีทราย · ดวงอาทิตย์สีส้ม
   Layout: แอปมือถือ แถบบนติดโลโก้ + แท็บล่าง 5 ช่อง ปุ่ม "เริ่ม" กลางเป็นวงกลมสีอาทิตย์ */
:root {
  color-scheme: dark;
  --bg: #1d2521;          /* พื้นโลโก้ */
  --surface: #252e29;
  --surface-2: #2f3933;
  --line: #3a453e;
  --text: #f1ede6;        /* ถนนสีขาวนวล */
  --muted: #9ca79f;
  --sand: #cfbaa9;        /* ภูเขาสีทราย */
  --accent: #f4794d;      /* ดวงอาทิตย์ */
  --accent-ink: #1d2521;
  --ok: #7cc48f;
  --warn: #f2a65a;
  --danger: #ef6a5b;
  --blue: #7aa7e0;
  --radius: 16px;
  --shadow: none;
  --font: 'IBM Plex Sans Thai', system-ui, -apple-system, sans-serif;
  --display: 'Barlow Semi Condensed', 'IBM Plex Sans Thai', system-ui, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f2efe9; --surface: #ffffff; --surface-2: #e9e5dc; --line: #dcd6ca;
    --text: #1d2521; --muted: #5f6b63; --sand: #8a7461; --accent: #d9592c; --accent-ink: #ffffff;
    --ok: #2f8a4a; --warn: #b4630f; --danger: #c43d2f; --blue: #3f74c2;
    --shadow: 0 1px 2px rgba(29,37,33,.06), 0 6px 18px rgba(29,37,33,.05);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2efe9; --surface: #ffffff; --surface-2: #e9e5dc; --line: #dcd6ca;
  --text: #1d2521; --muted: #5f6b63; --sand: #8a7461; --accent: #d9592c; --accent-ink: #ffffff;
  --ok: #2f8a4a; --warn: #b4630f; --danger: #c43d2f; --blue: #3f74c2;
  --shadow: 0 1px 2px rgba(29,37,33,.06), 0 6px 18px rgba(29,37,33,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-size: 1.5rem; margin: 8px 0 14px; font-weight: 700; text-wrap: balance; }
h1 small { font-size: .9rem; color: var(--muted); font-weight: 500; margin-left: 6px; }
h2 { font-size: .78rem; margin: 26px 0 10px; color: var(--sand); font-weight: 600; text-transform: uppercase; letter-spacing: .14em; }

/* ---------- header */
.topbar { position: sticky; top: 0; z-index: 500; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand img { height: 30px; width: auto; border-radius: 6px; display: block; }
.wordmark { font-family: var(--display); font-weight: 500; font-size: .95rem; letter-spacing: .38em; position: relative; padding-bottom: 3px; }
.wordmark::after { content: ""; position: absolute; left: calc(50% - .19em); transform: translateX(-50%); bottom: -2px; width: 18px; height: 2px; background: var(--accent); border-radius: 2px; }
.rec-pill { margin-left: auto; display: none; align-items: center; gap: 6px; font-family: var(--display); font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 4px 12px; font-size: .9rem; }
.rec-pill.on { display: inline-flex; }
.rec-pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }

main { max-width: 760px; margin: 0 auto; padding-block: 12px calc(100px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* ---------- tab bar */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 600; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; color: var(--muted); font-size: .74rem; font-weight: 500; }
.tabs a span { font-size: 1.1rem; line-height: 1.2; }
.tabs a.active { color: var(--accent); }
.tabs a.go span { width: 52px; height: 52px; margin-top: -22px; border-radius: 50%; display: grid; place-items: center; font-size: 1.2rem;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 5px var(--surface); }
.tabs a.go { color: var(--text); }
body.recording .tabs { display: none !important; }

/* ---------- common */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card.hero { border-left: 4px solid var(--c, var(--accent)); }
.card.err { border-color: var(--danger); color: var(--danger); }
.card.note { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.row { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: color-mix(in srgb, var(--c) 20%, transparent); color: var(--c); }
.status-done { color: var(--ok); font-weight: 600; }
.status-skipped { color: var(--muted); text-decoration: line-through; }
.title { font-weight: 600; font-size: 1.05rem; margin: 6px 0 2px; }
.desc { color: var(--muted); font-size: .9rem; margin: 2px 0 10px; line-height: 1.5; }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; }

.btn { white-space: nowrap; appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; font-size: .9rem;
  padding: 9px 14px; border-radius: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.strava { background: #fc4c02; border-color: #fc4c02; color: #fff; margin: 4px 0 6px; }
code { font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.btn.sm { padding: 6px 11px; font-size: .82rem; }
.btn:disabled { opacity: .45; cursor: default; }

.list .item { display: flex; gap: 12px; align-items: center; padding: 11px 4px; border-bottom: 1px solid var(--line); color: var(--text); cursor: pointer; }
.list .item:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.date-col { width: 72px; flex: none; color: var(--muted); font-size: .85rem; }
.date-col.today { color: var(--accent); font-weight: 700; }
.km { font-family: var(--display); font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; font-size: 1.02rem; }

/* วงแหวนความคืบหน้าสัปดาห์ (แบบ Apple Fitness) */
.ring-card { display: flex; gap: 16px; align-items: center; }
.ring { width: 86px; height: 86px; flex: none; }
.ring .track { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.ring .val { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .6s; }
.ring text { fill: var(--text); font-family: var(--display); font-weight: 600; font-size: 20px; text-anchor: middle; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-family: var(--display); font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat span { font-size: .76rem; color: var(--muted); }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 130px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; position: relative; }
.bars .bar i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar em { position: absolute; width: 100%; border-top: 2px dashed var(--sand); opacity: .7; }
.bars-x { display: flex; gap: 4px; font-size: .68rem; color: var(--muted); margin-top: 4px; }
.bars-x span { flex: 1; text-align: center; }

.week { margin-bottom: 16px; }
.week-head { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); font-weight: 600; padding: 0 4px 6px; }

#map { height: 340px; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 12px; z-index: 0; overflow: hidden; background: var(--surface-2); }
.route-svg { width: 100%; height: 100%; display: block; }
.route-line { fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linejoin: round; stroke-linecap: round; }
.route-start { fill: var(--ok); stroke: var(--surface); stroke-width: 2.5; }
.route-end { fill: var(--danger); stroke: var(--surface); stroke-width: 2.5; }
.elev { width: 100%; height: 120px; display: block; }
.elev-fill { fill: color-mix(in srgb, var(--sand) 30%, transparent); }
.elev-line { fill: none; stroke: var(--sand); stroke-width: 2; vector-effect: non-scaling-stroke; }
.tbl { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9rem; }
th, td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }

.upload { display: block; border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; cursor: pointer; color: var(--muted); }
.upload:hover { border-color: var(--accent); color: var(--text); }
.upload input { display: none; }

dialog { border: 0; border-radius: 20px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
dialog::backdrop { background: rgba(10,14,12,.55); }
#modal-body { padding: 18px; max-height: 85vh; overflow: auto; }
label.f { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; margin: 10px 0 4px; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
textarea { min-height: 80px; resize: vertical; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.days label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .8rem; padding: 6px 0; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.days input { width: auto; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg label { text-align: center; padding: 10px 0; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; font-weight: 600; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.switch { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.switch:last-child { border-bottom: 0; }
.switch input { width: auto; transform: scale(1.3); accent-color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 2000; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.login { max-width: 360px; margin: 8vh auto 0; text-align: center; }
.login img { width: 140px; border-radius: 20px; margin-bottom: 8px; }
.login form { text-align: left; }
.steps { padding-left: 20px; line-height: 1.7; }

/* ---------- หน้าบันทึกกิจกรรม (แบบ Apple Fitness) */
.rec { display: flex; flex-direction: column; gap: 14px; }
.rec-status { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; font-weight: 600; }
.rec-state { display: inline-flex; align-items: center; gap: 8px; text-transform: uppercase; letter-spacing: .12em; color: var(--sand); }
.rec-state i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.rec-state.live i { background: var(--accent); animation: blink 1.2s infinite; }
.rec-state.paused i { background: var(--warn); }
.gps { font-variant-numeric: tabular-nums; color: var(--muted); }
.gps.good { color: var(--ok); } .gps.fair { color: var(--warn); } .gps.bad { color: var(--danger); }
.big-time { font-family: var(--display); font-weight: 600; font-variant-numeric: tabular-nums; font-size: clamp(4rem, 22vw, 7.5rem); line-height: .95; letter-spacing: -.01em; color: var(--accent); }
.big-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; margin-top: 4px; }
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
.metric b { display: block; font-family: var(--display); font-weight: 600; font-size: clamp(2rem, 11vw, 3rem); line-height: 1; font-variant-numeric: tabular-nums; }
.metric b small { font-size: .45em; font-weight: 500; color: var(--muted); margin-left: 4px; }
.metric > span { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.live-map { height: 180px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: .85rem; }
.split-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.split-chips span { flex: none; font-family: var(--display); font-variant-numeric: tabular-nums; font-size: .95rem; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }
.split-chips span em { font-style: normal; color: var(--muted); margin-right: 4px; }
.rec-controls { display: flex; justify-content: center; gap: 22px; padding: 6px 0 calc(8px + env(safe-area-inset-bottom, 0px)); }
.circle { width: 84px; height: 84px; border-radius: 50%; border: 0; display: grid; place-items: center; font: 600 .95rem var(--font); cursor: pointer; position: relative; overflow: hidden; color: var(--accent-ink); touch-action: none; user-select: none; -webkit-user-select: none; }
.circle.start { width: 120px; height: 120px; background: var(--accent); font-size: 1.25rem; font-family: var(--display); letter-spacing: .12em; }
.circle.pause { background: var(--warn); }
.circle.resume { background: var(--ok); }
.circle.finish { background: var(--surface-2); color: var(--text); border: 2px solid var(--danger); }
.circle.finish .fill { position: absolute; inset: auto 0 0 0; height: 0; background: var(--danger); opacity: .35; }
.circle span { position: relative; }
.hint { text-align: center; font-size: .78rem; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .rec-pill i, .rec-state.live i { animation: none; } }
@media (max-width: 400px) { .stats:not(.three) { grid-template-columns: repeat(2, 1fr); } }

/* ---------- คลับ */
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.empty { color: var(--muted); text-align: center; padding: 22px 16px; }
.av { --size: 40px; width: var(--size); height: var(--size); flex: none; border-radius: 50%; display: inline-grid; place-items: center;
  background: color-mix(in srgb, var(--c) 85%, var(--bg)); color: #fff; font-weight: 700; font-size: calc(var(--size) * .42); line-height: 1;
  box-shadow: 0 0 0 2px var(--surface); }
.av.xs { --size: 20px; } .av.sm { --size: 30px; } .av.lg { --size: 52px; } .av.xl { --size: 76px; }
.subtabs { display: flex; gap: 4px; overflow-x: auto; margin: -4px 0 14px; padding-bottom: 2px; }
.subtabs a { flex: none; padding: 7px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: .9rem; border: 1px solid var(--line); }
.subtabs a.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg.mini { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; grid-template-columns: none; }
.seg.mini button { appearance: none; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .85rem; padding: 7px 12px; cursor: pointer; }
.seg.mini button.on { background: var(--accent); color: var(--accent-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--sand) 18%, transparent); color: var(--text); border: 1px solid color-mix(in srgb, var(--sand) 30%, transparent); }
.btn-chip { cursor: pointer; font: inherit; font-size: .8rem; }
.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: color-mix(in srgb, var(--c, var(--accent)) 20%, transparent); color: var(--c, var(--accent)); }
.pill.active { --c: var(--ok); } .pill.upcoming { --c: var(--blue); } .pill.ended { --c: var(--muted); }

.feed-item header { margin-bottom: 8px; }
.feed-item .who { color: var(--text); font-weight: 600; }
.feed-body { display: block; color: var(--text); }
.feed-body .title { margin-top: 0; }
.feed-stats { display: flex; gap: 18px; margin: 8px 0 10px; flex-wrap: wrap; }
.feed-stats div { display: flex; flex-direction: column; }
.feed-stats b { font-family: var(--display); font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.feed-stats span { font-size: .72rem; color: var(--muted); }
.mini-map { height: 150px; border-radius: 12px; overflow: hidden; background: var(--surface-2); margin-bottom: 8px; }
.feed-item footer { gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.kudos { appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 6px 14px;
  font: inherit; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; transition: transform .15s; }
.kudos.on { background: color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); color: var(--accent); }
.kudos:active { transform: scale(1.12); }
.who-row { gap: 10px; color: var(--text); margin: 10px 0 -4px; }
.comments { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.comment { display: flex; gap: 10px; align-items: flex-start; }
.comment .grow div:last-child { line-height: 1.45; }

.podium { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 8px; margin: 18px 0 12px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text); text-align: center; min-width: 0; }
.pod b { font-size: .9rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .num { font-family: var(--display); font-weight: 600; color: var(--accent); }
.pod .step { width: 100%; border-radius: 10px 10px 0 0; background: var(--surface-2); border: 1px solid var(--line); border-bottom: 0;
  display: grid; place-items: center; font-family: var(--display); font-size: 1.4rem; font-weight: 600; color: var(--sand); }
.pod.p1 { grid-column: 2; grid-row: 1; } .pod.p2 { grid-column: 1; grid-row: 1; } .pod.p3 { grid-column: 3; grid-row: 1; }
.pod.p1 .step { height: 74px; background: color-mix(in srgb, var(--accent) 22%, var(--surface)); color: var(--accent); }
.pod.p2 .step { height: 52px; } .pod.p3 .step { height: 38px; }
.board .rank { width: 22px; text-align: center; font-family: var(--display); font-weight: 600; color: var(--muted); }

.challenge .team { margin: 10px 0 4px; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.prog { display: flex; flex-direction: column; gap: 9px; margin: 12px 0 6px; }
.prow { display: flex; gap: 10px; align-items: center; }
.bar-line { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.team .bar-line { background: var(--bg); height: 10px; }
.bar-line > div { height: 100%; border-radius: 99px; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 70%, var(--sand)), var(--accent)); }
.challenge.ended { opacity: .75; }

.date-block { width: 58px; flex: none; text-align: center; border-radius: 12px; background: var(--surface-2); padding: 6px 0; display: flex; flex-direction: column; }
.date-block b { font-family: var(--display); font-size: 1.5rem; line-height: 1; }
.date-block span { font-size: .72rem; color: var(--muted); }
.date-block em { font-style: normal; font-size: .78rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.run .going { gap: 4px; margin: 10px 0; }
.run .going .av { margin-right: -8px; }
.run .going .small { margin-left: 12px; }
.run.past { opacity: .7; }
.rsvp { margin-right: 8px; }
.run-mini { display: flex; gap: 12px; align-items: center; color: var(--text); }

.heat { height: 420px; border-radius: var(--radius); overflow: hidden; background: #111613; border: 1px solid var(--line); margin: 12px 0 8px; display: grid; place-items: center; }
.heat .route-svg { background: #111613; }
.legend { gap: 12px; }
.legend .row { gap: 6px; }

.profile { display: flex; gap: 16px; align-items: center; margin: 6px 0 14px; }
.stats.four { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 480px) { .stats.four { grid-template-columns: repeat(2, 1fr); } }
.pr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.pr { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; color: var(--text); }
.pr span { font-size: .78rem; font-weight: 700; color: var(--sand); letter-spacing: .08em; }
.pr b { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.pr em { font-style: normal; font-size: .78rem; color: var(--muted); }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin-bottom: 8px; }
.bdg { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 12px 6px; border-radius: 14px;
  background: radial-gradient(circle at 50% 0%, color-mix(in srgb, var(--accent) 18%, var(--surface)) 0%, var(--surface) 70%); border: 1px solid var(--line); }
.bdg span { font-size: 1.9rem; line-height: 1.2; }
.bdg b { font-size: .8rem; }
.bdg em { font-style: normal; font-size: .68rem; color: var(--muted); line-height: 1.3; }
.bdg.locked { background: var(--surface); opacity: .5; }
.bdg.locked span { filter: grayscale(1); }

.form-card .form-row { gap: 12px; align-items: center; margin-top: 6px; }
.gauge { width: 150px; flex: none; }
.needle { stroke: var(--text); stroke-width: 3; stroke-linecap: round; }
.needle-dot { fill: var(--text); }
.g-val { fill: var(--text); font-family: var(--display); font-weight: 600; font-size: 20px; text-anchor: middle; }
.spark { display: flex; align-items: flex-end; gap: 5px; height: 46px; margin-top: 12px; }
.spark i { flex: 1; background: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); border-radius: 4px 4px 0 0; }
.spark i:last-child { background: var(--accent); }
@media (max-width: 400px) { .gauge { width: 120px; } }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 10px; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); background: var(--c); cursor: pointer; box-shadow: 0 0 0 1px var(--line); }
.sw.on { box-shadow: 0 0 0 2px var(--text); }
details summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: 100%; z-index: 50; display: flex; flex-direction: column; gap: 6px; padding: 8px; min-width: 170px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.invite { margin: 10px 0; padding: 10px; border-radius: 12px; background: var(--surface-2); }

/* แผนที่ความร้อน: กลับสี OSM เป็นโทนมืด */
.dark-tiles { filter: invert(100%) hue-rotate(180deg) brightness(92%) contrast(88%) saturate(60%); }

.pending { margin: 10px 0; padding: 8px 10px; border-radius: 12px; background: color-mix(in srgb, var(--warn) 12%, var(--surface-2)); }
.pending .item { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.reg-settings { margin: 6px 0 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }

/* ---------- รูปโปรไฟล์ */
img.av { display: inline-block; object-fit: cover; background: var(--surface-2); padding: 0; }
.av-upload { position: relative; cursor: pointer; flex: none; border-radius: 50%; }
.av-upload input { position: absolute; inset: 0; opacity: 0; width: 1px; height: 1px; }
.av-upload:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.av-cam { position: absolute; right: -2px; bottom: -2px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); font-size: .8rem; box-shadow: 0 0 0 2px var(--surface); }

/* ---------- เกม */
.medal { image-rendering: pixelated; image-rendering: crisp-edges; object-fit: contain; flex: none; display: inline-grid; place-items: center; }
.medal.md { width: 64px; height: 64px; } .medal.lg { width: 76px; height: 76px; } .medal.xl { width: 128px; height: 128px; }
.medal-empty { font-size: 2.2rem; background: var(--surface-2); border-radius: 50%; }
.medal.xl.medal-empty { font-size: 4rem; }
.game-card { display: flex; gap: 14px; align-items: center; color: var(--text); text-decoration: none; }
.game-card:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.game-card .medal { filter: drop-shadow(0 4px 8px rgba(0,0,0,.35)); }
.game-meta { gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.game-meta .row { gap: 5px; }
.me-rank { color: var(--accent); font-weight: 700; }
.game-hero { display: flex; gap: 16px; align-items: center; margin: 12px 0 14px; }
.medal-stage { position: relative; padding: 10px; border-radius: 24px; flex: none;
  background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 70%); }
.medal-stage .medal { animation: medal-float 3.6s ease-in-out infinite; filter: drop-shadow(0 10px 14px rgba(0,0,0,.4)); }
@keyframes medal-float { 50% { transform: translateY(-6px) rotate(-2deg); } }
@media (prefers-reduced-motion: reduce) { .medal-stage .medal { animation: none; } }
@media (max-width: 420px) { .game-hero { flex-direction: column; align-items: flex-start; } }
.rules { color: var(--muted); line-height: 1.55; }
.my-game { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.rank-big { font-family: var(--display); font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.big-num { font-family: var(--display); font-size: 2rem; font-weight: 600; }
.gspark { width: 100%; height: 90px; margin-top: 10px; display: block; }
.gs-line { fill: none; stroke: var(--sand); stroke-width: 2; stroke-linejoin: round; }
.gs-dot { fill: var(--surface); stroke: var(--sand); stroke-width: 2; }
.gs-pb { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }
.timeline .tl { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0 10px 14px; border-left: 2px solid var(--line); margin-left: 8px; position: relative; }
.timeline .tl::before { content: ""; position: absolute; left: -6px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.timeline .tl.now::before { background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
select#g-act { flex: 1; min-width: 0; }

/* ---------- คลังเหรียญ */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin-bottom: 8px; }
.shelf-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 14px 8px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none; min-width: 0; }
.shelf-item b { font-size: .82rem; line-height: 1.25; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.shelf-item em { font-style: normal; font-size: .72rem; color: var(--muted); }
.shelf-item.champ { border-color: color-mix(in srgb, #f7c948 60%, var(--line)); background: linear-gradient(180deg, color-mix(in srgb, #f7c948 14%, var(--surface)), var(--surface)); }
.shelf-item .crown { position: absolute; top: 4px; right: 8px; font-size: 1.1rem; }

/* ---------- ตัววาดเหรียญ pixel */
.px-editor { margin-top: 10px; }
.px-tools { gap: 6px; margin-bottom: 8px; }
.tool { appearance: none; min-width: 40px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer; padding: 0 8px; }
.tool.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--surface-2)); }
.tool.mirror { gap: 4px; display: inline-flex; align-items: center; }
.tool.mirror input { width: auto; margin: 0; }
.px-tools select { width: auto; height: 38px; }
.px-canvas { width: 100%; max-width: 420px; aspect-ratio: 1; display: block; margin: 0 auto; border-radius: 10px; border: 1px solid var(--line);
  image-rendering: pixelated; touch-action: none; cursor: crosshair; }
.px-palette { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; justify-content: center; }
.px-palette .sw { width: 28px; height: 28px; border-radius: 8px; }
.px-palette .sw.custom { position: relative; overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.px-palette .sw.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.px-tpl { gap: 6px; align-items: center; }
.btn-chip { cursor: pointer; border: 1px solid var(--line); font: inherit; font-size: .8rem; }
.px-preview { gap: 12px; align-items: center; margin-top: 10px; }
.px-preview canvas { image-rendering: pixelated; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 8px 8px; border-radius: 6px; }

.recent-list.clamped .item:nth-child(n+7) { display: none; }
.recent-list .more { width: 100%; margin-top: 6px; }

/* ---------- กติกา & กระดานอันดับเกม */
.rule-line { margin-top: 4px; color: var(--muted); }
.ok-t { color: var(--ok); } .warn-t { color: var(--warn); font-weight: 600; }
.rule-card { border-color: color-mix(in srgb, #f7c948 45%, var(--line)); background: linear-gradient(135deg, color-mix(in srgb, #f7c948 10%, var(--surface)), var(--surface)); }
.rule-card .row { gap: 12px; align-items: center; }
.rule-ic { font-size: 1.8rem; }
.rule-count { text-align: right; white-space: nowrap; } .rule-count b { font-family: var(--display); font-size: 1.5rem; }
.rule-preview { margin: 8px 0 4px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); line-height: 1.5; }
.rule-preview:empty { display: none; }
.gboard .item { display: flex; align-items: center; gap: 10px; }
.gboard .rank { width: 28px; flex: none; text-align: center; font-family: var(--display); font-weight: 600; color: var(--muted); }
.gboard .is-me .nm { color: var(--accent); }
.top3 { display: grid; gap: 8px; margin-bottom: 10px; }
.top3 .item { --m: #f7c948; padding: 14px 12px; border-radius: var(--radius); border: 1px solid color-mix(in srgb, var(--m) 55%, var(--line));
  background: linear-gradient(100deg, color-mix(in srgb, var(--m) 24%, var(--surface)) 0%, var(--surface) 75%); }
.top3 .top1 { padding: 18px 12px; box-shadow: 0 6px 22px color-mix(in srgb, var(--m) 22%, transparent); }
.top3 .top2 { --m: #c9d1dc; } .top3 .top3 { --m: #d08a4e; }
.top3 .rank { position: relative; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 1.15rem; font-weight: 700;
  color: #1d2521; background: var(--m); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.top3 .top1 .rank { width: 40px; height: 40px; font-size: 1.35rem; }
.crown-sm { position: absolute; top: -15px; left: 50%; transform: translateX(-50%); font-style: normal; font-size: .95rem; }
.top3 .nm { font-weight: 700; font-size: 1.02rem; }
.top3 .top1 .km { font-size: 1.45rem; color: color-mix(in srgb, #f7c948 65%, var(--text)); }
.top3 .km { font-size: 1.2rem; }
.gboard .rest { margin-bottom: 8px; }

/* ---------- สถิติที่ดีที่สุด (หน้าฉัน) */
.bests { margin-bottom: 16px; }
.best-hero { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-radius: var(--radius); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  background: radial-gradient(circle at 90% 20%, color-mix(in srgb, var(--accent) 35%, transparent), transparent 55%), linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, var(--surface)), var(--surface)); }
.best-hero b { display: block; font-family: var(--display); font-size: 2.6rem; font-weight: 600; line-height: 1.05; }
.best-hero em, .best-tile em { font-style: normal; font-size: .78rem; color: var(--muted); }
.best-hero .trophy { font-size: 2.6rem; filter: drop-shadow(0 6px 10px rgba(0,0,0,.3)); }
.bt-l { font-size: .74rem; font-weight: 700; letter-spacing: .06em; color: var(--sand); }
.pr-strip { display: flex; gap: 8px; overflow-x: auto; margin: 10px 0; padding-bottom: 2px; scrollbar-width: none; }
.pr-strip .pr { flex: 1 0 96px; padding: 10px 12px; }
.pr-strip .pr b { font-size: 1.3rem; }
.pr-strip .pr.on { border-color: var(--accent); }
.best-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.best-tile { position: relative; display: flex; flex-direction: column; gap: 1px; padding: 12px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); color: var(--text); min-width: 0; }
a.best-tile:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.best-tile b { font-family: var(--display); font-size: 1.5rem; font-weight: 600; line-height: 1.15; }
.best-tile b small { font-size: .8rem; color: var(--muted); font-weight: 500; }
.bt-ic { position: absolute; top: 10px; right: 10px; font-size: 1.15rem; opacity: .9; }

/* ---------- Dashboard เกม */
.gdash { border-color: color-mix(in srgb, #f7c948 40%, var(--line)); }
.gd-top { gap: 14px; align-items: center; }
.gdash .ring { width: 86px; height: 86px; flex: none; }
.gdash .ring text { font-size: 15px; }
.gd-big { font-size: 1rem; } .gd-big b { font-family: var(--display); font-size: 2rem; font-weight: 600; }
.crown-c { color: color-mix(in srgb, #f7c948 70%, var(--text)); }
.gd-stats { margin-top: 12px; } .gd-stats .stat { background: var(--surface-2); padding: 8px 10px; } .gd-stats .stat b { font-size: 1.3rem; }
.medal.sm { width: 40px; height: 40px; } .medal.sm.medal-empty { font-size: 1.3rem; }
.medal-strip { display: flex; gap: 8px; overflow-x: auto; margin-top: 12px; padding: 4px 2px; scrollbar-width: none; }
.medal-strip a { position: relative; flex: none; padding: 6px; border-radius: 12px; background: var(--surface-2); }
.medal-strip a.champ { background: color-mix(in srgb, #f7c948 22%, var(--surface-2)); }
.medal-strip i { position: absolute; top: -6px; right: -4px; font-style: normal; font-size: .8rem; }
.collectors { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.collectors summary { cursor: pointer; padding: 4px 0; }
.collectors .item { display: flex; align-items: center; gap: 10px; padding: 8px 2px; color: var(--text); }
.collectors .rank { width: 18px; text-align: center; color: var(--muted); font-family: var(--display); font-weight: 600; }
.collectors b.num { font-family: var(--display); min-width: 42px; text-align: right; }
.stats.four.gd-stats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
.gd-stats .stat { text-align: center; padding: 8px 4px; } .gd-stats .stat span { font-size: .7rem; white-space: nowrap; }
.gdash .ring .val { stroke: #f7c948; }

/* ---------- Dashboard คะแนนรวมคลับ */
.cdash { border-color: color-mix(in srgb, #f7c948 40%, var(--line));
  background: linear-gradient(160deg, color-mix(in srgb, #f7c948 9%, var(--surface)), var(--surface)); }
.cd-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.cd-tile { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 10px 4px; border-radius: 12px; background: var(--surface-2); min-width: 0; }
.cd-tile span { font-size: 1.1rem; }
.cd-tile b { font-family: var(--display); font-size: 1.7rem; font-weight: 600; line-height: 1.1; }
.cd-tile em { font-style: normal; font-size: .72rem; color: var(--muted); white-space: nowrap; }
.cd-tile small { font-size: .66rem; color: var(--ok); }
.mboard { padding-top: 4px; padding-bottom: 4px; }
.mrow { display: flex; align-items: flex-start; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.mrow:last-child { border-bottom: 0; }
.mrow .rank { width: 20px; flex: none; text-align: center; padding-top: 6px; font-family: var(--display); font-weight: 600; color: var(--muted); }
.mrow.lead .rank { color: color-mix(in srgb, #f7c948 70%, var(--text)); }
.mrow .nm { color: var(--text); font-weight: 600; }
.mrow.is-me .nm { color: var(--accent); }
.mthumbs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.mt { position: relative; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); }
.mt.champ { background: color-mix(in srgb, #f7c948 28%, var(--surface-2)); box-shadow: inset 0 0 0 1px color-mix(in srgb, #f7c948 60%, transparent); }
.mt.more { font-size: .72rem; color: var(--muted); font-weight: 700; }
.medal.xs { width: 24px; height: 24px; } .medal.xs.medal-empty { font-size: .9rem; background: none; }
.mscore { flex: none; display: flex; flex-direction: column; align-items: flex-end; min-width: 58px; }
.mscore b { font-family: var(--display); font-size: 1.7rem; font-weight: 600; line-height: 1; }
.mscore span { font-size: .7rem; color: var(--muted); }
.mscore em { font-style: normal; font-size: .8rem; font-weight: 700; margin-top: 2px; }

/* ---------- สถิติคลับรายระยะ */
.dist-chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.dchip { flex: none; appearance: none; font: inherit; font-family: var(--display); font-weight: 700; font-size: 1rem; padding: 8px 14px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding-left: 6px; padding-right: 6px; }
.dchip i { font-style: normal; font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.dchip.none { color: var(--muted); }
.dchip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.dchip.on i { background: rgba(0,0,0,.18); color: inherit; }
.rec-hero { border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%), var(--surface); }
.rh-main { gap: 12px; align-items: center; margin-top: 12px; }
.rh-name { font-size: 1.15rem; }
.rh-time { font-family: var(--display); font-size: 2.1rem; font-weight: 600; line-height: 1; }
.gboard a.item { color: var(--text); text-decoration: none; }
.gap { color: var(--warn); font-weight: 600; }
.missing .item { opacity: .65; }
