/* 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;
  --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;
    --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;
  --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 { 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); } }
