/* Run Challenge — mobile-first, รองรับ dark/light ตามระบบ */

:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --text: #1a1d2b;
  --muted: #676b7e;
  --line: #e2e4ee;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --gold: #d4a017;
  --silver: #8f9bb3;
  --bronze: #b5722a;
  --danger-bg: #fdecec;
  --danger: #b3261e;
  --warn-bg: #fff6de;
  --warn: #7a5a00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 50, 0.06), 0 6px 20px -8px rgba(20, 24, 50, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1118;
    --surface: #181b26;
    --surface-2: #222634;
    --text: #eceef6;
    --muted: #9a9fb3;
    --line: #2b3040;
    --danger-bg: #3a1a1a;
    --danger: #ff8a80;
    --warn-bg: #33290f;
    --warn: #ffd66b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px -8px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1rem; font-weight: 600; margin-bottom: 10px; }
button { font: inherit; cursor: pointer; }
.wrap { max-width: 900px; margin: 0 auto; padding: 0 14px; }

/* ── hero ─────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 60%, #d0367a 130%);
  color: #fff;
  padding: 22px 0 18px;
}
.hero-kicker { margin: 0; font-size: 0.8rem; opacity: 0.85; letter-spacing: 0.04em; }
.hero h1 { font-size: 1.6rem; font-weight: 700; }
.hero-range { margin: 2px 0 12px; opacity: 0.9; font-size: 0.9rem; }
.progress-bar {
  height: 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.25); overflow: hidden;
}
.progress-bar span { display: block; height: 100%; background: #fff; border-radius: 999px; transition: width 0.4s; }
.progress-meta { display: flex; justify-content: space-between; font-size: 0.82rem; margin-top: 6px; opacity: 0.95; }
.updated { margin: 12px 0 0; font-size: 0.8rem; opacity: 0.9; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn-refresh {
  background: rgba(255, 255, 255, 0.18); color: #fff; border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px; padding: 4px 12px; font-size: 0.8rem;
}
.btn-refresh:hover { background: rgba(255, 255, 255, 0.3); }
.btn-refresh[disabled] { opacity: 0.6; cursor: wait; }

/* ── alerts ───────────────────────────────────────── */
.alert { background: var(--danger-bg); color: var(--danger); padding: 12px 14px; border-radius: var(--radius); margin: 14px 0; }
.warn { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: var(--radius); margin: 14px 0; font-size: 0.88rem; }
.warn summary { cursor: pointer; font-weight: 500; }
.warn ul { margin: 8px 0 0; padding-left: 18px; }

/* ── tabs ─────────────────────────────────────────── */
.tabs {
  display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px;
  margin: 14px 0; position: sticky; top: 8px; z-index: 5; box-shadow: var(--shadow);
}
.tab {
  flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px 6px;
  border-radius: 999px; font-weight: 500; font-size: 0.92rem; white-space: nowrap;
}
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 14px; margin: 12px 0; box-shadow: var(--shadow);
}
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }

/* ── leaderboard ──────────────────────────────────── */
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.team-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; display: grid; grid-template-columns: auto auto 1fr auto; gap: 12px; align-items: center;
  border-left: 5px solid var(--team, var(--accent));
  cursor: pointer; transition: transform 0.15s;
}
.team-card:active { transform: scale(0.99); }
.rank { font-size: 1.15rem; font-weight: 700; width: 28px; text-align: center; color: var(--muted); }
.rank.r1 { color: var(--gold); } .rank.r2 { color: var(--silver); } .rank.r3 { color: var(--bronze); }
.badge {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--team, var(--accent)); color: #fff; font-weight: 700; font-size: 1.1rem;
}
.team-name { font-weight: 600; }
.team-sub { font-size: 0.8rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.team-pts { text-align: right; }
.team-pts b { font-size: 1.45rem; font-weight: 700; display: block; line-height: 1.1; }
.team-pts small { color: var(--muted); font-size: 0.75rem; }
.team-fill { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.team-fill span { display: block; height: 100%; background: var(--team, var(--accent)); border-radius: 999px; }

.rules { margin: 0; padding-left: 20px; font-size: 0.9rem; color: var(--muted); }
.rules li { margin: 3px 0; }
.rules b { color: var(--text); font-weight: 600; }

/* ── tables ───────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
.table { border-collapse: collapse; width: 100%; font-size: 0.85rem; white-space: nowrap; }
.table th, .table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.table th:first-child, .table td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.table thead th { color: var(--muted); font-weight: 500; font-size: 0.78rem; }
.table tfoot td { font-weight: 600; }
.table .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.table .zero { color: var(--line); }
.table .full { color: var(--accent); font-weight: 600; }

/* ── team detail ──────────────────────────────────── */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 2px solid var(--team); background: transparent; color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-weight: 600;
}
.chip.is-active { background: var(--team); color: #fff; }

.team-head { display: flex; align-items: center; gap: 12px; }
.team-head .badge { width: 48px; height: 48px; font-size: 1.3rem; }
.team-head .pts { margin-left: auto; text-align: right; }
.team-head .pts b { display: block; font-size: 1.6rem; line-height: 1.1; }
.team-head .pts small { color: var(--muted); font-size: 0.75rem; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 1.05rem; }
.stat small { color: var(--muted); font-size: 0.72rem; }

.runners { list-style: none; margin: 0; padding: 0; }
.runner { display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.runner:last-child { border-bottom: 0; }
.runner .n { color: var(--muted); font-size: 0.85rem; text-align: center; }
.runner .name { font-weight: 600; }
.runner .detail { font-size: 0.78rem; color: var(--muted); }
.runner .pts { text-align: right; font-weight: 700; font-size: 1.1rem; }
.runner .pts small { display: block; font-weight: 400; font-size: 0.72rem; color: var(--muted); }
.runner .bar { grid-column: 2 / -1; height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.runner .bar span { display: block; height: 100%; background: var(--team); }

.log { list-style: none; margin: 0; padding: 0; font-size: 0.88rem; }
.log li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.log li:last-child { border-bottom: 0; }
.log .d { color: var(--muted); font-size: 0.78rem; min-width: 52px; }
.log .a { margin-left: auto; white-space: nowrap; }
.log .note { color: var(--muted); font-size: 0.78rem; }

/* ── entry form ───────────────────────────────────── */
.hero-compact { padding: 16px 0 14px; }
.hero .back, .hero .btn-entry {
  display: inline-block; color: #fff; text-decoration: none; font-size: 0.85rem; font-weight: 500;
  background: rgba(255, 255, 255, 0.18); border: 1px solid rgba(255, 255, 255, 0.4); border-radius: 999px; padding: 4px 12px;
}
.hero .back { margin-bottom: 8px; }
.hero .btn-entry { margin-left: auto; }
.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span, .field > label { font-weight: 600; font-size: 0.9rem; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
.field input, .field select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { color: var(--muted); font-size: 0.78rem; }
.pin-wrap { position: relative; }
.pin-wrap input { padding-right: 48px; }
.btn-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; font-size: 1.1rem; padding: 6px 10px; border-radius: 8px; opacity: 0.6;
}
.btn-eye:hover, .btn-eye[aria-pressed="true"] { opacity: 1; background: var(--line); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 10px;
  padding: 10px 4px; font-size: 0.85rem; white-space: nowrap;
}
.seg button.is-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary {
  border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 13px; font-weight: 600; font-size: 1rem;
}
.btn-primary[disabled] { opacity: 0.6; cursor: wait; }
code { font-size: 0.85em; background: rgba(0,0,0,0.08); padding: 1px 5px; border-radius: 4px; }
.btn-del {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 2px 8px; font-size: 0.9rem; line-height: 1.4;
}
.btn-del:hover { border-color: var(--danger); background: var(--danger-bg); }
.btn-del[disabled] { opacity: 0.5; cursor: wait; }
.log .empty { display: block; padding: 10px 0; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.foot { color: var(--muted); font-size: 0.78rem; padding: 20px 14px 32px; text-align: center; }
.foot-link { display: inline-block; margin-left: 10px; color: var(--muted); text-decoration: underline dotted; }
.foot-link:hover { color: var(--text); }

@media (min-width: 640px) {
  body { font-size: 16px; }
  .hero h1 { font-size: 2rem; }
  .chart-box { height: 300px; }
  .chart-box.tall { height: 380px; }
  .board { grid-template-columns: 1fr 1fr; }
  .team-card { grid-template-columns: auto auto 1fr auto; }
}

/* ── mobile fixes: ปุ่มไม่ล้น/ไม่เบี้ยว ─────────────── */
.hero-actions { display: flex; gap: 8px; margin-top: 10px; }
.hero-actions .btn-refresh, .hero-actions .btn-entry {
  flex: 1; text-align: center; padding: 9px 10px; font-size: 0.9rem; margin: 0; line-height: 1.4;
}
.seg button { display: grid; gap: 2px; justify-items: center; padding: 8px 2px; font-size: 0.8rem; line-height: 1.2; white-space: normal; }
.seg button .ic { font-size: 1.35rem; line-height: 1; }
@media (max-width: 420px) {
  .tab { font-size: 0.84rem; padding: 9px 2px; }
  .chip { padding: 6px 12px; font-size: 0.9rem; }
}
@media (min-width: 640px) { .hero-actions { max-width: 380px; } }

/* ── race track ───────────────────────────────────── */
.track-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.track-head small { color: var(--muted); font-size: 0.75rem; }
.track { --label-w: 74px; position: relative; padding: 2px 44px 18px 0; }
.lane { display: grid; grid-template-columns: var(--label-w) 1fr; align-items: center; height: 40px; }
.lane-label { display: flex; align-items: center; gap: 6px; }
.lane-label .dot-badge { width: 24px; height: 24px; border-radius: 7px; font-size: 0.75rem; box-shadow: none; }
.lane-pts { font-size: 0.8rem; font-weight: 600; }
.lane-run { position: relative; height: 100%; }
.lane-line {
  position: absolute; left: 0; right: 0; top: 50%; height: 2px; transform: translateY(-50%);
  background: repeating-linear-gradient(90deg, var(--line) 0 10px, transparent 10px 18px);
}
.runner-dot {
  position: absolute; top: 50%; transform: translate(-8%, -50%); z-index: 1;
  transition: left 1.2s cubic-bezier(0.22, 1, 0.36, 1); will-change: left;
}
.dot-badge {
  display: grid; place-items: center; background: var(--team); color: #fff; font-weight: 700;
}
.pace { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dashed var(--accent); opacity: 0.7; pointer-events: none; z-index: 0; }
.pace span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 0.68rem; color: var(--accent); white-space: nowrap; }
.finish {
  position: absolute; top: 0; bottom: 18px; right: 30px; width: 12px;
  background: repeating-conic-gradient(#222 0 25%, #fff 0 50%) 0 0 / 12px 12px;
  border-radius: 2px; opacity: 0.85;
}
.finish::after { content: "🏁"; position: absolute; left: 16px; top: -4px; font-size: 1.1rem; }


/* ── momentum tags ────────────────────────────────── */
.tags { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: -4px; }
.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.tag.hot { background: #fff1e6; color: #c2410c; }
.tag.up { background: #e6f7ee; color: #15803d; }
.tag.down { background: #fdecec; color: #b3261e; }
.tag.lead { background: #fff7d6; color: #9a6b00; }
@media (prefers-color-scheme: dark) {
  .tag.hot { background: #3a2415; color: #fdba74; }
  .tag.up { background: #10301c; color: #86efac; }
  .tag.down { background: #3a1a1a; color: #ff8a80; }
  .tag.lead { background: #3a2f0f; color: #fde68a; }
}


/* ── top runners ──────────────────────────────────── */
.top-runners { list-style: none; margin: 0; padding: 0; }
.top-runners li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.top-runners li:last-child { border-bottom: 0; }
.tr-medal { font-size: 1.2rem; }
.tr-name { flex: 1; font-weight: 600; }
.tr-name small { font-weight: 500; font-size: 0.75rem; margin-left: 4px; }
.top-runners b { font-size: 1.05rem; }

@media (prefers-reduced-motion: reduce) { .runner-dot { transition: none; } }

/* ── animated sprinter on the track ───────────────── */
.fig { width: 34px; height: 28px; display: block; animation: bob 0.4s ease-in-out infinite; }
.sprint { width: 100%; height: 100%; overflow: visible; stroke: var(--team); fill: none; stroke-width: 11; stroke-linecap: round; stroke-linejoin: round; }
.sprint .head { fill: var(--team); stroke: none; }
.sprint .speed path { stroke-width: 7; opacity: 0.55; }
.sprint .speed { animation: speed 0.4s linear infinite; }
.sprint .p1 { animation: frameA 0.4s steps(1) infinite; }
.sprint .p2 { animation: frameB 0.4s steps(1) infinite; }
@keyframes frameA { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes frameB { 0%, 49% { opacity: 0; } 50%, 100% { opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
@keyframes speed { 0% { transform: translateX(6px); opacity: 0.2; } 50% { opacity: 0.7; } 100% { transform: translateX(-8px); opacity: 0.1; } }
@media (prefers-reduced-motion: reduce) {
  .fig, .sprint .speed, .sprint .p1, .sprint .p2, .runner-dot { animation: none; transition: none; }
  .sprint .p2 { display: none; }
}
@media (min-width: 640px) { .track { --label-w: 90px; } .lane { height: 44px; } .fig { width: 40px; height: 33px; } }

/* ── daily: summary tiles + stage wins ────────────── */
.day-summary { margin-top: 0; }
.day-summary .stat b { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 1.6em; }
.day-summary .stat small.up { color: #15803d; display: block; }
.day-summary .stat small.down { color: var(--danger); display: block; }
.day-summary .dim { color: var(--muted); font-weight: 400; font-size: 0.8em; }
.dot-badge.mini { width: 20px; height: 20px; border-radius: 6px; font-size: 0.7rem; }
.table td.win { font-weight: 700; }
.table .star-cell { text-align: left; }
.table .star-cell small { color: var(--muted); }
@media (max-width: 480px) { .day-summary { grid-template-columns: 1fr 1fr; } }

/* ── runner expand ────────────────────────────────── */
.runner.is-clickable { cursor: pointer; }
.runner.is-clickable .name::after { content: "›"; color: var(--muted); font-weight: 400; transition: transform 0.2s; display: inline-block; margin-left: 8px; }
.runner.is-open .name::after { transform: rotate(90deg); }
.runner-log { grid-column: 1 / -1; background: var(--surface-2); border-radius: 10px; padding: 4px 12px; margin-top: 4px; }
.runner-log .log li { border-color: var(--line); font-size: 0.84rem; }
.runner-log .a b { font-weight: 700; }
.runner-log .a small { color: var(--muted); font-size: 0.72rem; }

/* ── compact hero + collapsible rules ─────────────── */
.hero { padding: 14px 0 12px; }
.hero-kicker { display: none; }
.hero h1 { font-size: 1.35rem; }
.hero-range { margin: 0 0 8px; font-size: 0.82rem; }
.progress-bar { height: 8px; }
.progress-meta { margin-top: 4px; font-size: 0.78rem; }
.updated { margin: 4px 0 0; font-size: 0.72rem; opacity: 0.8; }
.hero-actions { margin-top: 8px; }
.hero-actions .btn-refresh, .hero-actions .btn-entry { padding: 7px 10px; font-size: 0.85rem; }
@media (min-width: 640px) { .hero { padding: 22px 0 18px; } .hero h1 { font-size: 2rem; } .hero-kicker { display: block; } }
.rules-card { padding: 0; }
.rules-card summary { list-style: none; cursor: pointer; padding: 14px; display: flex; align-items: center; justify-content: space-between; }
.rules-card summary::-webkit-details-marker { display: none; }
.rules-card summary h2 { margin: 0; }
.rules-card summary::after { content: "▸"; color: var(--muted); transition: transform 0.2s; }
.rules-card[open] summary::after { transform: rotate(90deg); }
.rules-card .rules { padding: 0 14px 14px 34px; margin: 0; }

/* ── lane rank marks ──────────────────────────────── */
.track { --label-w: 96px; }
.lane-rank { width: 20px; text-align: center; font-size: 0.95rem; flex: 0 0 auto; }
.lane-rank-n { color: var(--muted); font-weight: 700; font-size: 0.85rem; }
.lane.is-leader .lane-run .lane-line { background: repeating-linear-gradient(90deg, var(--gold) 0 10px, transparent 10px 18px); opacity: 0.6; }
.lane.is-leader .lane-pts { color: var(--gold); }
@media (min-width: 640px) { .track { --label-w: 112px; } }

/* ── track zoom mode ──────────────────────────────── */
.track-head { flex-wrap: wrap; }
.track-note { display: block; color: var(--muted); font-size: 0.72rem; margin: 2px 0 6px; }
.axis-break { position: absolute; left: calc(var(--label-w) - 6px); top: 0; bottom: 18px; display: flex; align-items: center; color: var(--muted); font-size: 0.9rem; letter-spacing: -1px; pointer-events: none; }
.finish.is-far { opacity: 0.3; }
.finish.is-far::after { opacity: 1; }

/* ── clearer rank marks ───────────────────────────── */
.team-card .rank { width: 36px; font-size: 1.6rem; line-height: 1; }
.team-card .rank.r4, .team-card .rank.r5, .team-card .rank.r6, .team-card .rank.r7 {
  font-size: 1rem; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text); border: 1.5px solid var(--line);
}
.lane-rank { width: 26px; font-size: 1.2rem; }
.lane-rank-n {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); color: var(--text); border: 1.5px solid var(--line); font-size: 0.78rem;
}

.day-hint.is-full { color: var(--accent); font-weight: 600; }
.runner-log .a { display: flex; flex-direction: column; align-items: flex-end; }
.runner-log .capped { color: var(--danger); font-size: 0.7rem; white-space: nowrap; }

/* ── special cards ────────────────────────────────── */
.tag.cards { letter-spacing: 1px; }
.tag.cards .used { opacity: 0.25; text-decoration: line-through; }
.card-ic { font-size: 0.8em; margin-right: 2px; }
.day-cards { margin-top: 10px; font-size: 0.82rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.day-cards .dc { display: inline-flex; align-items: center; gap: 4px; color: var(--text); }
.day-cards .dc.dim { color: var(--muted); }
.cardnote { display: block; color: var(--accent); font-size: 0.7rem; white-space: nowrap; }

/* ── special cards (entry page) ───────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.card-btn {
  border: 2px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 12px;
  padding: 12px 6px; display: grid; gap: 4px; justify-items: center; text-align: center; font-size: 0.82rem; font-weight: 600;
}
.card-btn .ic { font-size: 1.6rem; line-height: 1; }
.card-btn small { font-weight: 400; color: var(--muted); font-size: 0.7rem; }
.card-btn.is-active { border-color: var(--accent); background: var(--surface); }
.card-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.card-btn.is-used { opacity: 0.45; text-decoration: none; }
.card-btn.is-used .ic { filter: grayscale(1); }
.card-form { margin-top: 12px; padding: 12px; background: var(--surface-2); border-radius: 12px; display: grid; gap: 10px; }
[hidden] { display: none !important; } /* ให้ hidden ชนะ display ของ class เสมอ */
.card-form .field select { background: var(--surface); }
.card-form .desc { font-size: 0.85rem; color: var(--muted); margin: 0; }
.card-form .btn-primary { margin-top: 2px; }
.card-done { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--surface-2); text-align: center; font-weight: 600; }
.card-done .big { font-size: 1.6rem; display: block; margin: 4px 0; }
@keyframes shuffle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.card-done.is-rolling .big { animation: shuffle 0.25s ease-in-out infinite; }
.hero-links { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.hero-links .back { margin-bottom: 0; }
.hero-actions .btn-entry + .btn-entry { flex: 0.8; }
.rules-lead { margin: 0 14px 6px; font-size: 0.9rem; color: var(--muted); }
.rules-lead b { color: var(--text); }

/* ── cards: how-to + examples ─────────────────────── */
.howto { margin: 0; padding: 0 14px 12px 32px; font-size: 0.9rem; color: var(--muted); }
.howto li { margin: 4px 0; }
.howto b { color: var(--text); }
.rules-card > .hint { margin: 0 14px 14px; }
.examples { padding: 0 14px 14px; display: grid; gap: 12px; }
.ex-h { font-weight: 600; margin-bottom: 4px; }
.ex-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.ex-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.75rem; padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); }
.ex-table td { vertical-align: top; padding: 7px 8px 7px 0; border-bottom: 1px solid var(--line); }
.ex-table td:first-child { width: 48%; color: var(--muted); }
.ex-table td:last-child { color: var(--text); }
.ex-table tr:last-child td { border-bottom: 0; }
.ex-table small { color: var(--muted); font-size: 0.75rem; }
@media (max-width: 480px) {
  .ex-table thead { display: none; }
  .ex-table tr { display: block; padding: 6px 0; border-bottom: 1px solid var(--line); }
  .ex-table tr:last-child { border-bottom: 0; }
  .ex-table td { display: block; width: auto !important; padding: 1px 0; border: 0; }
  .ex-table td:last-child { padding-left: 12px; }
  .ex-table td:last-child::before { content: "→ "; color: var(--muted); }
}

/* ── week cards table ─────────────────────────────── */
.week-cards th, .week-cards td { text-align: center; padding: 6px 4px; }
.week-cards th:first-child, .week-cards td:first-child { text-align: left; }
.week-cards th small { font-weight: 400; color: var(--muted); }
.week-cards .is-today { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.week-cards td.has-card { line-height: 1.15; }
.week-cards .wc-ic { display: block; font-size: 1rem; }
.week-cards td.has-card small { font-size: 0.68rem; color: var(--muted); white-space: nowrap; }

/* ── card history ─────────────────────────────────── */
.card-summary th, .card-summary td { text-align: center; }
.card-summary th:first-child, .card-summary td:first-child { text-align: left; }
.card-summary td.up { color: #15803d; }
.card-summary td.down { color: var(--danger); }
.hl-week { font-size: 0.78rem; color: var(--muted); font-weight: 600; margin: 14px 0 4px; }
.log.hl li { align-items: center; gap: 8px; }
.log.hl .hl-what { flex: 1; min-width: 0; }
.log.hl .hl-detail { display: block; color: var(--muted); font-size: 0.72rem; }
.log.hl .eff { white-space: nowrap; font-weight: 600; font-size: 0.82rem; }
.log.hl .eff.up { color: #15803d; }
.log.hl .eff.down { color: var(--danger); }
.log.hl .eff.dim { color: var(--muted); font-weight: 400; }
.cf-preview { font-size: 0.85rem; padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px dashed var(--accent); }
.week-cards td.is-stacked { opacity: 0.45; }
.week-cards td.is-stacked em { font-style: normal; color: var(--danger); }
.btn-ghost { display: block; width: 100%; margin-top: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 10px; padding: 9px; font-size: 0.88rem; font-weight: 500; }
.seg { grid-template-columns: repeat(5, 1fr); }
.seg button { padding: 8px 0; font-size: 0.74rem; }
@media (min-width: 640px) { .seg { grid-template-columns: repeat(9, 1fr); } }

.stat-row { grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); }
/* กล่องสถิติทีม 5 ช่อง: จอกว้างแถวเดียว จอแคบ 3+2 */
#team-detail .stat-row { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 480px) { #team-detail .stat-row { grid-template-columns: repeat(3, 1fr); } }

/* ── podium: top 3 cards — ไม่แตะสีทีม เด่นด้วยเหรียญ/ตัวเลข/ริบบิ้นมุม ── */
.team-card.is-top { position: relative; overflow: hidden; }
.team-card.is-top .rank { font-size: 2rem; width: 44px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.25)); }
.team-card.is-top .team-pts b { font-size: 1.75rem; }
.team-card.top1 .team-pts b { color: var(--gold); }
.team-card.top2 .team-pts b { color: #5f6b85; }
.team-card.top3 .team-pts b { color: var(--bronze); }
.team-card.top1 { box-shadow: var(--shadow), 0 0 0 1px color-mix(in srgb, var(--gold) 45%, transparent); }
@media (prefers-color-scheme: dark) { .team-card.top2 .team-pts b { color: #d5dbe8; } }

/* ── mini pill switch (สนามแข่ง/ประวัติการ์ด) — อยู่ท้ายไฟล์ให้ชนะ .seg button ของหน้ากรอก ── */
.seg.seg-mini { display: inline-flex; grid-template-columns: none; gap: 0; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg.seg-mini button { display: inline-block; padding: 7px 16px; font-size: 0.85rem; font-weight: 600; border: 0; border-radius: 999px; line-height: 1.4; background: transparent; color: var(--muted); white-space: nowrap; }
.seg.seg-mini button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

/* ── 3 วันสุดท้าย ────────────────────────────────── */
#progress-days.is-final { color: #ffd166; font-weight: 700; display: inline-block; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

/* ── wow: celebrate banner ────────────────────────── */
.celebrate { position: relative; overflow: hidden; background: linear-gradient(135deg, #fff7d6, #ffe9f3); color: #5a3b00; border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; box-shadow: var(--shadow); font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
@media (prefers-color-scheme: dark) { .celebrate { background: linear-gradient(135deg, #3a2f0f, #3a1a2e); color: #ffe08a; } }
.celebrate .ev { display: inline-flex; align-items: center; gap: 6px; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall 2.2s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: 0.2; } }

/* ── wow: replay ──────────────────────────────────── */
.track-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-replay { border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 0.82rem; font-weight: 600; }
.btn-replay[disabled] { opacity: 0.5; cursor: wait; }
.track.is-replay .runner-dot { transition: left 0.28s linear; }
.replay-day { text-align: center; font-size: 0.85rem; color: var(--accent); font-weight: 700; min-height: 1.4em; }

/* ── wow: team badges ─────────────────────────────── */
.tag.badge-fun { background: color-mix(in srgb, var(--team) 14%, var(--surface)); color: var(--text); }

/* ── wow: podium (จบกิจกรรม) ───────────────────────── */
.podium-card { text-align: center; background: linear-gradient(160deg, #fff8e1, #fff 60%); }
@media (prefers-color-scheme: dark) { .podium-card { background: linear-gradient(160deg, #3a2f0f, var(--surface) 60%); } }
.podium-card h2 { font-size: 1.3rem; margin-bottom: 4px; }
.podium-card .sub { color: var(--muted); font-size: 0.85rem; margin: 0 0 14px; }
.podium { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 8px; align-items: end; margin-top: 8px; }
.podium .col { display: grid; justify-items: center; align-content: end; }
.podium .c1 { background: radial-gradient(closest-side, rgba(243,197,60,0.45), transparent 75%) top / 100% 70% no-repeat; } /* สปอตไลต์หลังแชมป์ */
.podium .step { width: 100%; border-radius: 12px 12px 4px 4px; padding: 8px 6px 12px; color: #fff; display: grid; gap: 2px; justify-items: center; box-shadow: inset 0 3px 0 rgba(255,255,255,0.35); }
.podium .step .place { font-size: 1.6rem; line-height: 1; }
.podium .step b { font-size: 1.3rem; }
.podium .step small { opacity: 0.9; font-size: 0.75rem; }
.podium .s1 { background: linear-gradient(180deg, #f3c53c, #c9961a); min-height: 104px; }
.podium .s2 { background: linear-gradient(180deg, #b8c2d6, #8f9bb3); min-height: 78px; }
.podium .s3 { background: linear-gradient(180deg, #d19a5b, #b5722a); min-height: 60px; }
/* นักกีฬาบนแท่น */
.athlete { width: 70px; height: 91px; margin-bottom: -6px; position: relative; z-index: 1; filter: drop-shadow(0 4px 4px rgba(0,0,0,0.2)); }
.athlete.a1 { width: 82px; height: 107px; animation: jump 1.4s ease-in-out infinite; }
.athlete-svg { width: 100%; height: 100%; overflow: visible; stroke: var(--team); fill: none; stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; }
.athlete-svg .head, .athlete-svg .jersey { fill: var(--team); stroke: none; }
.athlete-svg .legs { stroke-width: 9; }
.athlete-svg text { stroke: none; fill: #fff; font-weight: 700; font-size: 19px; font-family: inherit; }
.athlete-svg .ribbon { stroke: #d62839; stroke-width: 3.5; }
.athlete-svg .medal { stroke: #fff; stroke-width: 1.5; }
.athlete-svg .wave { transform-box: view-box; transform-origin: 64px 38px; animation: wave 0.9s ease-in-out infinite alternate; }
.athlete.a1 .athlete-svg .wave { animation-duration: 0.6s; }
@keyframes wave { from { transform: rotate(-14deg); } to { transform: rotate(14deg); } }
@keyframes jump { 0%, 100% { transform: translateY(0); } 35%, 50% { transform: translateY(-10px); } }
@media (prefers-reduced-motion: reduce) { .athlete, .athlete-svg .wave { animation: none; } }
@media (min-width: 640px) { .athlete { width: 84px; height: 109px; } .athlete.a1 { width: 100px; height: 130px; } }
.podium-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 14px; }
.podium-stats .stat b { font-size: 1.1rem; }

.nowrap { white-space: nowrap; }

/* ── สรุปทีมของฉัน (หน้ากรอก) ─────────────────────── */
.today-list { list-style: none; margin: 12px 0 0; padding: 0; }
.today-list li { display: grid; grid-template-columns: 24px 1fr auto auto; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.today-list li:last-child { border-bottom: 0; }
.today-list .tick { text-align: center; }
.today-list .nm { font-weight: 600; }
.today-list .what { color: var(--text); font-size: 0.82rem; white-space: nowrap; }
.today-list .what.dim { color: var(--muted); }
.today-list .pt { min-width: 36px; text-align: right; font-weight: 700; }
.today-list li:not(.is-done) .nm { color: var(--muted); font-weight: 500; }

/* ── ล็อกตารางคะแนน ───────────────────────────────── */
.lock-card { max-width: 420px; margin: 24px auto; text-align: left; }
.lock-card h2 { margin-bottom: 6px; }
.lock-card .btn-primary { width: 100%; margin-top: 12px; }
.lock-card .field { margin-top: 14px; }
.btn-ghost {
  border: 1px solid var(--accent); background: transparent; color: var(--accent);
  border-radius: 10px; padding: 9px 14px; font-weight: 600; font-size: 0.9rem; margin-top: 10px;
}
.btn-ghost[disabled] { opacity: 0.6; cursor: wait; }
