/* =====================================================================
   SA GAMES — Live Dashboard (TV / Projector / LED / Mobile)
   แนวคิด: สนามกรีฑายามค่ำ — พื้นน้ำเงินสนาม เส้นลู่สีขาวประ คณะสีคือสีเดียวที่ฉูดฉาด
   คะแนนสีแสดงเป็น "ลู่วิ่ง": หมายเลขลู่ = อันดับ, ความยาวแถบ = คะแนน
   ===================================================================== */
:root {
  --lv-bg: #0D1B33;
  --lv-panel: #12264A;
  --lv-ink: #F3F6FB;
  --lv-muted: #93A6C6;
  --lv-lane: rgba(255, 255, 255, .16);
  --lv-live: #FF3B3B;
  --lv-ok: #3DDC97;
  --lv-radius: 14px;
  --lv-head: "Kanit", "Sarabun", system-ui, sans-serif;
  --lv-body: "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
}
html[data-theme="light"] {
  --lv-bg: #EEF1F7;
  --lv-panel: #FFFFFF;
  --lv-ink: #14213D;
  --lv-muted: #5B6886;
  --lv-lane: rgba(20, 33, 61, .16);
  --lv-live: #D7262E;
  --lv-ok: #1E8E5A;
}
html { font-size: clamp(15px, .55vw + 8px, 30px); }
* { box-sizing: border-box; }
body.lv { margin: 0; min-height: 100vh; background: var(--lv-bg); color: var(--lv-ink); font-family: var(--lv-body); line-height: 1.45; -webkit-font-smoothing: antialiased; }
.lv a { color: inherit; }
.lv :focus-visible { outline: 3px solid var(--lv-ok); outline-offset: 2px; }
.lv-idle-cursor, .lv-idle-cursor * { cursor: none !important; }

/* ---------- Header ---------- */
.lv-top { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem; padding: .9rem clamp(1rem, 2.5vw, 2.5rem); border-bottom: 2px dashed var(--lv-lane); }
.lv-brand { display: flex; flex-direction: column; text-decoration: none; margin-right: auto; }
.lv-brand-name { font-family: var(--lv-head); font-weight: 700; font-size: 1.6rem; line-height: 1.1; letter-spacing: .01em; }
.lv-brand-sub { color: var(--lv-muted); font-size: .85rem; }
.lv-day { display: flex; flex-direction: column; font-family: var(--lv-head); font-weight: 500; }
.lv-day small { color: var(--lv-muted); font-weight: 400; font-size: .75rem; }
.lv-clock { font-family: var(--lv-head); font-weight: 600; font-size: 1.9rem; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.lv-live-badge { display: inline-flex; align-items: center; gap: .45rem; background: var(--lv-live); color: #fff; font-family: var(--lv-head); font-weight: 600; padding: .3rem .8rem; border-radius: 999px; }
.lv-idle { color: var(--lv-muted); font-size: .9rem; }
.lv-dot { width: .6rem; height: .6rem; border-radius: 50%; background: currentColor; animation: lv-pulse 1.4s ease-in-out infinite; }
.lv-live-badge .lv-dot { display: none; }  /* อีโมจิ 🔴 ทำหน้าที่แทนแล้ว */
@keyframes lv-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.lv-nav { display: flex; flex-wrap: wrap; gap: .25rem; width: 100%; }
.lv-nav a, .lv-fs { color: var(--lv-muted); text-decoration: none; font-size: .9rem; padding: .25rem .65rem; border-radius: 999px; border: 1px solid transparent; background: none; font-family: inherit; cursor: pointer; }
.lv-nav a:hover, .lv-fs:hover { color: var(--lv-ink); border-color: var(--lv-lane); }
.lv-fs { margin-left: auto; font-size: 1.1rem; line-height: 1; }

/* ---------- Grid ---------- */
.lv-grid { display: grid; gap: 1rem; padding: 1rem clamp(1rem, 2.5vw, 2.5rem); grid-template-columns: 1fr;
  grid-template-areas: "now" "board" "latest" "today" "progress"; }
.lv-panel { background: var(--lv-panel); border-radius: var(--lv-radius); padding: 1rem 1.25rem; min-width: 0; }
.lv-panel h2 { font-family: var(--lv-head); font-weight: 500; font-size: 1rem; color: var(--lv-muted); margin: 0 0 .75rem; }
.lv-p-board { grid-area: board; }
.lv-p-now { grid-area: now; }
.lv-p-latest { grid-area: latest; }
.lv-p-today { grid-area: today; }
.lv-p-progress { grid-area: progress; }
.lv-empty { color: var(--lv-muted); margin: 0; }
.lv-changed { animation: lv-flash 1.2s ease-out; }
@keyframes lv-flash { from { box-shadow: 0 0 0 3px var(--lv-ok); border-radius: 8px; } to { box-shadow: 0 0 0 3px transparent; } }

@media (min-width: 900px) {
  .lv-grid { grid-template-columns: 7fr 5fr; grid-template-areas: "board now" "latest today" "latest progress"; }
  .lv-nav { width: auto; }
}
/* TV / LED / Projector: เต็มจอพอดี ไม่ต้องเลื่อน */
@media (min-width: 1500px) and (min-aspect-ratio: 16/10) {
  body.lv { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
  .lv-grid { flex: 1; min-height: 0; grid-template-columns: 6fr 4fr 3fr; grid-template-rows: auto 1fr;
    grid-template-areas: "board now progress" "latest latest today"; }
  .lv-panel { overflow: hidden; }
  .lv-p-today { overflow: hidden; }
}
html[data-tv="1"] .lv-top { padding-top: .6rem; padding-bottom: .6rem; }

/* ---------- Scoreboard: ลู่วิ่งคณะสี ---------- */
.lv-lanes { list-style: none; margin: 0; padding: 0; border-top: 2px dashed var(--lv-lane); }
.lv-lane { display: grid; grid-template-columns: 3.2rem 1fr auto; align-items: center; gap: 1rem; padding: .7rem 0; border-bottom: 2px dashed var(--lv-lane); }
.lv-lane-rank { font-family: var(--lv-head); font-weight: 700; font-size: 2.6rem; line-height: 1; text-align: center; color: transparent;
  -webkit-text-stroke: 2px var(--house); }
.lv-lane[data-rank="1"] .lv-lane-rank { color: var(--house); }
.lv-lane-track { min-width: 0; }
.lv-lane-head { display: flex; align-items: baseline; gap: .6rem; }
.lv-lane-name { font-family: var(--lv-head); font-weight: 500; font-size: 1.15rem; }
.lv-tie { font-size: .75rem; color: var(--lv-muted); border: 1px solid var(--lv-lane); border-radius: 999px; padding: 0 .5rem; }
.lv-lane-bar { height: .9rem; border-radius: 999px; background: color-mix(in srgb, var(--house) 18%, transparent); margin: .35rem 0; overflow: hidden; }
.lv-lane-bar span { display: block; height: 100%; background: var(--house); border-radius: 999px; transition: width .8s cubic-bezier(.2, .7, .2, 1); }
.lv-lane-medals { display: flex; gap: 1rem; color: var(--lv-muted); font-variant-numeric: tabular-nums; font-size: .95rem; }
.lv-lane-medals span { display: inline-flex; align-items: center; gap: .3rem; }
.lv-medal { display: inline-block; width: .8rem; height: .8rem; border-radius: 50%; background: var(--medal); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25); }
.lv-lane-score { font-family: var(--lv-head); font-weight: 600; font-size: 2.4rem; line-height: 1; font-variant-numeric: tabular-nums; text-align: right; }
.lv-lane-score small { display: block; font-size: .75rem; font-weight: 400; color: var(--lv-muted); }

/* ---------- LIVE NOW ---------- */
.lv-now { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.lv-now-item { display: grid; gap: .2rem; padding: .75rem .9rem; border-radius: 10px; border: 2px solid var(--lv-live); background: color-mix(in srgb, var(--lv-live) 10%, transparent); }
.lv-live-tag { display: inline-flex; align-items: center; gap: .4rem; font-family: var(--lv-head); font-weight: 600; color: var(--lv-live); font-size: .85rem; }
.lv-live-tag .lv-dot { display: none; }
.lv-now-event { font-family: var(--lv-head); font-weight: 600; font-size: 1.35rem; line-height: 1.2; }
.lv-now-meta { color: var(--lv-muted); font-size: .9rem; }
.lv-heats { display: flex; align-items: center; gap: .3rem; margin-top: .2rem; }
.lv-heats i { width: 1.4rem; height: .4rem; border-radius: 999px; background: var(--lv-lane); }
.lv-heats i.is-done { background: var(--lv-ok); }
.lv-heats em { font-style: normal; font-size: .85rem; color: var(--lv-muted); margin-left: .3rem; }

/* ---------- ผลล่าสุด ---------- */
.lv-results { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 21rem), 1fr)); }
.lv-result h3 { font-family: var(--lv-head); font-weight: 500; font-size: 1.05rem; margin: 0 0 .4rem; }
.lv-result h3 span { color: var(--lv-muted); font-weight: 400; font-size: .85rem; }
.lv-podium { list-style: none; margin: 0; padding: 0; }
.lv-podium li { display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: .6rem; padding: .35rem 0 .35rem .6rem; border-left: 5px solid var(--house); }
.lv-podium li + li { margin-top: .3rem; }
.lv-place { width: 1.8rem; height: 1.8rem; border-radius: 50%; display: grid; place-items: center; font-family: var(--lv-head); font-weight: 600; font-size: .95rem; border: 2px solid var(--lv-lane); }
.lv-place.has-medal { background: var(--medal); border-color: var(--medal); color: #1B1B1B; }
.lv-who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv-who small { display: block; color: var(--lv-muted); font-size: .75rem; }
.lv-mark { font-family: var(--lv-head); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- วันนี้ ---------- */
.lv-timeline { list-style: none; margin: 0; padding: 0; }
.lv-slot { display: grid; grid-template-columns: 3.4rem 1fr auto; gap: .6rem; align-items: baseline; padding: .4rem 0; border-bottom: 1px dashed var(--lv-lane); }
.lv-slot time { font-family: var(--lv-head); font-variant-numeric: tabular-nums; color: var(--lv-muted); }
.lv-slot-name small { color: var(--lv-muted); }
.lv-slot-state { font-size: .8rem; color: var(--lv-muted); white-space: nowrap; }
.lv-slot.is-done { opacity: .55; }
.lv-slot.is-live .lv-slot-state { color: var(--lv-live); font-weight: 600; }
.lv-slot.is-live time, .lv-slot.is-next time { color: var(--lv-ink); }
.lv-slot.is-next .lv-slot-state { color: var(--lv-ok); }

/* ---------- Progress ---------- */
.lv-progress { display: grid; gap: .9rem; }
.lv-meter-label { display: flex; justify-content: space-between; gap: .5rem; font-size: .9rem; color: var(--lv-muted); }
.lv-meter-label strong { color: var(--lv-ink); font-family: var(--lv-head); font-weight: 500; }
.lv-meter-bar { height: .6rem; background: var(--lv-lane); border-radius: 999px; overflow: hidden; margin-top: .3rem; }
.lv-meter-bar span { display: block; height: 100%; background: var(--lv-ok); border-radius: 999px; transition: width .8s ease; }
.lv-facts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 0; }
.lv-facts dt { font-weight: 400; color: var(--lv-muted); font-size: .8rem; }
.lv-facts dd { margin: 0; font-family: var(--lv-head); font-weight: 600; font-size: 1.6rem; font-variant-numeric: tabular-nums; }

/* ---------- Footer / ticker ---------- */
.lv-foot { display: flex; align-items: center; gap: 1rem; padding: .5rem clamp(1rem, 2.5vw, 2.5rem) .8rem; color: var(--lv-muted); font-size: .85rem; }
.lv-foot .lv-ticker { font-size: 1rem; }
.lv-slot-name small { display: block; }
.lv-ticker { flex: 1; overflow: hidden; white-space: nowrap; mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent); }
.lv-ticker-track { display: inline-flex; gap: 3rem; padding-left: 100%; animation: lv-marquee 40s linear infinite; color: var(--lv-ink); }
@keyframes lv-marquee { to { transform: translateX(-100%); } }
.lv-sync.is-bad { color: var(--lv-live); }

@media (max-width: 599px) {
  .lv-brand-name { font-size: 1.25rem; }
  .lv-clock { font-size: 1.3rem; }
  .lv-lane { grid-template-columns: 2.4rem 1fr auto; gap: .6rem; }
  .lv-lane-rank { font-size: 2rem; }
  .lv-lane-score { font-size: 1.8rem; }
}
@media (prefers-reduced-motion: reduce) {
  .lv-dot, .lv-ticker-track, .lv-changed { animation: none; }
  .lv-ticker-track { padding-left: 0; }
  .lv-lane-bar span, .lv-meter-bar span { transition: none; }
}
@media (max-width: 640px) { .lv-foot { flex-wrap: wrap; } .lv-foot .lv-ticker { flex-basis: 100%; } .lv-sync { margin-left: auto; } }

/* ---------- Phase 15: ป้ายสถิติใหม่ + ฉลองผู้ชนะเต็มจอ ---------- */
.lv-record { display: inline-block; margin-right: .4rem; font-size: .72em; font-weight: 600; padding: .1em .45em; border-radius: 999px;
  background: #FFD54A; color: #3A2600; vertical-align: middle; }
.lv-celebrate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 4vh 4vw; overflow: hidden;
  background: radial-gradient(120% 120% at 50% 0%, #2B3A80, #080C1C); color: #fff; text-align: center;
  animation: lv-cel-in .5s ease-out both; }
.lv-celebrate[hidden] { display: none; }
.lv-celebrate.is-out { animation: lv-cel-out .6s ease-in both; }
.lv-celebrate > div { position: relative; z-index: 1; width: min(1100px, 100%); }
.lv-cel-kicker { font-family: var(--lv-head); font-weight: 600; font-size: clamp(1.4rem, 3vw, 2.6rem); margin: 0 0 .4rem; color: #FFD54A; }
.lv-cel-title { font-family: var(--lv-head); font-weight: 700; font-size: clamp(2rem, 5vw, 4.6rem); line-height: 1.1; margin: 0 0 3vh; }
.lv-cel-podium { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.6vh; }
.lv-cel-podium li { display: grid; grid-template-columns: auto 1fr auto; gap: 1.2rem; align-items: center; text-align: left;
  padding: 1.6vh 2vw; border-radius: 18px; background: rgba(255, 255, 255, .08); border-left: 10px solid var(--house);
  opacity: 0; animation: lv-cel-row .6s cubic-bezier(.2, .8, .2, 1) forwards; }
.lv-cel-podium li:nth-child(1) { animation-delay: .9s; font-size: 1.25em; background: rgba(255, 213, 74, .16); }
.lv-cel-podium li:nth-child(2) { animation-delay: .6s; }
.lv-cel-podium li:nth-child(3) { animation-delay: .3s; }
.lv-cel-place { width: 2.6em; height: 2.6em; border-radius: 50%; display: grid; place-items: center; background: var(--medal); color: #1b1b1b;
  font-family: var(--lv-head); font-weight: 700; font-size: clamp(1.1rem, 2.2vw, 2rem); box-shadow: 0 0 0 4px rgba(255, 255, 255, .25); }
.lv-cel-who { font-family: var(--lv-head); font-weight: 600; font-size: clamp(1.3rem, 2.8vw, 2.6rem); line-height: 1.15; }
.lv-cel-who small { display: block; font-family: var(--lv-body); font-weight: 400; font-size: .55em; opacity: .85; }
.lv-cel-mark { font-family: var(--lv-head); font-weight: 600; font-size: clamp(1.2rem, 2.6vw, 2.4rem); font-variant-numeric: tabular-nums; }
.lv-confetti { position: absolute; top: -5vh; width: 12px; height: 18px; border-radius: 3px; opacity: .9; animation: lv-fall linear forwards; }
@keyframes lv-cel-in { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }
@keyframes lv-cel-out { to { opacity: 0; } }
@keyframes lv-cel-row { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes lv-fall { to { transform: translateY(115vh) rotate(720deg); } }
@media (prefers-reduced-motion: reduce) { .lv-celebrate, .lv-cel-podium li { animation: none; opacity: 1; } .lv-confetti { display: none; } }
/* Phase 16: โลโก้โรงเรียน */
.lv-brand { flex-direction: row; align-items: center; gap: .7rem; }
.lv-brand-text { display: flex; flex-direction: column; }
.lv-brand-logo { width: 52px; height: 52px; border-radius: 50%; background: #fff; padding: 3px; object-fit: contain; flex: none; }
