/* จำนวนคนดู (presence.js) — ตัวเลขจาก server · ไม่มีข้อมูล = ซ่อน */

/* หัวแผง: ให้ .pr-site กินความกว้างคอลัมน์ 2–5 เต็มแถว (เหมือน .live) ไม่ให้โดนปุ่ม ? / TH-EN / ธีม เบียดจนข้อความขาด */
.brand:has(> .pr-site:not([hidden])) {
  grid-template-areas:
    "logo title help lang theme"
    "logo pr pr pr pr"
    "logo live live live live";
}

.pr-site {
  grid-area: pr;
  margin: -2px 0 2px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--muted);
}

.pr-site[hidden] {
  display: none;
}

/* มือถือ แผงกางเป็นรายการ: หัวแผงมีที่จับตรงกลาง ("title . live") → ให้ .pr-site อยู่แถวสองเต็มความกว้าง ไม่ชนที่จับ */
@media (max-width: 899px) {
  html:not(.kid) .panel[data-mode="list"] .brand:has(> .pr-site:not([hidden])) {
    grid-template-areas:
      "title . live"
      "pr pr pr";
  }

  html:not(.kid) .panel[data-mode="list"] .pr-site {
    margin: -4px 0 2px;
    font-size: 11px;
  }
}

/* หัวแผงขบวน: "🔥 N คนกำลังดูขบวนนี้" + "⭐ ขบวนยอดนิยม" (สีตามสีขบวน --tfg/--tbg) */
.pr-train {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
}

.pr-train span {
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  background: color-mix(in srgb, currentcolor 14%, transparent);
  border: 1px solid color-mix(in srgb, currentcolor 28%, transparent);
  border-radius: 999px;
}

/* การ์ดเด็ก: "มีเพื่อนอีก N คนดูรถไฟขบวนนี้กับหนูอยู่นะ" */
.kid-friends {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  margin: 12px 0 0;
  font-size: 16.5px;
  font-weight: 600;
  line-height: 1.4;
  background: color-mix(in srgb, #38bdf8 14%, var(--panel-solid));
  border-radius: 18px;
}

/* หมุดขบวนยอดนิยม: วงทองเรืองแสง + ⭐ หน้าเลขขบวน */
.tm.is-popular .tm-puck {
  box-shadow: 0 0 0 3px color-mix(in srgb, #fbbf24 70%, transparent), 0 0 16px color-mix(in srgb, #fbbf24 75%, transparent), 0 2px 6px rgb(0 0 0 / 45%);
}

.tm.is-popular .tm-label::before {
  margin-right: 3px;
  content: "⭐";
}

@media (prefers-reduced-motion: no-preference) {
  .tm.is-popular .tm-puck {
    animation: pr-glow 2.4s ease-in-out infinite;
  }
}

@keyframes pr-glow {
  50% {
    box-shadow: 0 0 0 4px color-mix(in srgb, #fbbf24 45%, transparent), 0 0 24px color-mix(in srgb, #fbbf24 90%, transparent), 0 2px 6px rgb(0 0 0 / 45%);
  }
}

/* แถบขบวนกำลังฮิต (Most Tracked แบบ Flightradar24) — ลอยโปร่งแสงบนแผนที่ เห็นทันทีตั้งแต่เปิดเว็บ */
.pr-top {
  position: fixed;
  bottom: 58px;
  left: calc(32px + var(--panel-w));
  z-index: 890;
  display: flex;
  gap: 6px;
  align-items: center;
  max-width: calc(100vw - 120px - var(--panel-w));
  padding: 4px 10px 4px 12px;
  overflow: hidden;
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.pr-top[hidden],
.kid .pr-top {
  display: none;
}

@media (min-width: 900px) {
  .has-detail .pr-top,
  .has-locate .pr-top {
    max-width: calc(100vw - 120px - var(--panel-w) - var(--detail-w));
  }
}

@media (min-width: 900px) and (max-width: 1319px) {
  .has-detail .pr-top,
  .has-locate .pr-top {
    display: none;
  }
}

.pr-top-lbl {
  flex: none;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--warn-t);
  white-space: nowrap;
}

.pr-top-list {
  display: flex;
  flex: 1;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.pr-top-list::-webkit-scrollbar {
  display: none;
}

.pr-top-chip {
  display: inline-flex;
  flex: none;
  gap: 4px;
  align-items: center;
  height: 26px;
  padding: 0 8px 0 5px;
  font-size: 11.5px;
  background: color-mix(in srgb, var(--panel-solid) 75%, transparent);
  border: 1px solid color-mix(in srgb, #f59e0b 38%, var(--line));
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.pr-top-chip:hover {
  background: var(--card-hover);
  border-color: color-mix(in srgb, #f59e0b 65%, var(--line));
}

.pr-top-chip:active {
  transform: scale(0.97);
}

.pr-top-rank {
  font-size: 12px;
  line-height: 1;
}

.pr-top-no {
  padding: 1px 5px;
  font: 700 11px/1.2 var(--mono);
  border-radius: 5px;
}

.pr-top-to {
  max-width: 72px;
  overflow: hidden;
  font-weight: 600;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pr-top-n {
  font: 600 10.5px/1 var(--mono);
  color: var(--muted);
}

/* มือถือ: ลอยอยู่บนแผนที่ เหนือแผ่นย่อ (peek) ทันทีที่เปิดหน้าแผนที่ · พอกางแผ่น/เปิดรายละเอียดขบวน จะซ่อนอัตโนมัติไม่บัง */
@media (max-width: 899px) {
  .pr-top {
    right: auto;
    bottom: calc(var(--peek) + var(--bnav-h) + 8px);
    left: calc(8px + env(safe-area-inset-left));
    max-width: calc(100vw - 48px - env(safe-area-inset-left) - env(safe-area-inset-right));
    padding: 3px 8px 3px 10px;
  }

  .panel:not([data-snap="peek"]) ~ .pr-top,
  .detail:not([hidden]) ~ .pr-top {
    visibility: hidden;
    pointer-events: none;
  }
}

@media (max-width: 899px) and (max-height: 500px) and (orientation: landscape) and (min-aspect-ratio: 4/3) {
  .pr-top {
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: calc(var(--side-l) + var(--side-w) + 8px);
    max-width: calc(100vw - var(--side-l) - var(--side-w) - 48px);
  }

  .panel:not([data-snap="peek"]) ~ .pr-top {
    visibility: visible;
    pointer-events: auto;
  }
}
