/* ============================================================================
   VT Stats - Game Watch (/gw)
   Page-specific layer, loaded LAST (after vtstats-theme.css).

   Conventions (DEVELOPER_GUIDE.md section 6 + .cursor/rules/styling.mdc):
     - All colors via var(--kb-*); all effects via var(--vt-*). Zero hardcoded.
     - Reuses the glass-surface + shadow + pulse patterns from vtstats-theme.css.
     - All motion honors prefers-reduced-motion (block at the bottom).

   Card model: a dedicated 4-band grid (status bar / info / players / footer)
   rendered by js/gw/gw-card.js, modeled on the BZCC-Website GameWatch
   reference for dimensional consistency. Cards are uniform width everywhere;
   of-interest lobbies are differentiated by an accent ring + badge, not size.
   ============================================================================ */

:root {
  --gw-card-min: 460px;
  --gw-thumb: 112px;
  --gw-label-col: 3.6rem;
}

.vt-gw-main {
  width: 100%;
}

/* Embedded mode: when /gw is iframed in the dashboard Game Watch modal
   (?embed=1), hide the standalone navbar so only the live grid + header
   strip show. The modal supplies its own chrome. */
html.gw-embed .navbar {
  display: none !important;
}

/* ----------------------------------------------------------------- Header strip */

.vt-gw-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.8rem 1.1rem;
  margin-bottom: 1.1rem;
  border-radius: 1rem;
  background: color-mix(in oklab, var(--kb-bg-card) var(--vt-glass-opacity), transparent);
  backdrop-filter: blur(var(--vt-glass-blur));
  -webkit-backdrop-filter: blur(var(--vt-glass-blur));
  border: 1px solid color-mix(in oklab, var(--kb-text-primary) var(--vt-glass-border-luminance), transparent);
  box-shadow: var(--vt-shadow-elevation-1);
}

.vt-gw-header-lead {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.vt-gw-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--kb-text-primary);
  letter-spacing: -0.01em;
}

.vt-gw-title i {
  color: var(--kb-primary);
}

.vt-gw-header-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.vt-gw-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 999px;
  color: var(--kb-text-secondary);
  background: color-mix(in oklab, var(--kb-bg-subtle) 70%, transparent);
  border: 1px solid var(--kb-border-subtle);
  white-space: nowrap;
}

.gw-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--kb-success);
  box-shadow: 0 0 0 0 color-mix(in oklab, var(--kb-success) 50%, transparent);
  animation: vtActiveGamePulse 2.2s ease-in-out infinite;
  flex: 0 0 auto;
}

.gw-dot.gw-dot--stale {
  background-color: var(--kb-warning);
  animation: none;
}

/* Next-update countdown ring (informational; sits before the updated chip).
   The foreground arc fills 0 -> full as the next poll approaches; JS sets
   stroke-dashoffset (smooth via rAF, or coarse 1s steps under reduced motion). */
.gw-ring {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
}

.gw-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.gw-ring circle {
  fill: none;
  stroke-width: 3;
}

.gw-ring-track {
  stroke: color-mix(in oklab, var(--kb-text-primary) 16%, transparent);
}

.gw-ring-fg {
  stroke: var(--kb-primary);
  stroke-linecap: round;
}

/* ----------------------------------------------------------------- Sections */

.vt-gw-section {
  margin-bottom: 1.6rem;
}

/* Single uniform grid (of-interest lobbies sort first, border-distinguished).
   position:relative anchors exiting cards that the reconciler freezes out of
   flow during fade-out. */
.vt-gw-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--gw-card-min), 1fr));
  gap: 1rem;
  align-items: stretch;
}

@media (max-width: 575.98px) {
  .vt-gw-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   CARD: 4-band grid -> bar / info / players (1fr) / footer
   ============================================================================ */

.gw-card {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0;
  border-radius: 0.85rem;
  overflow: hidden;
  background: color-mix(in oklab, var(--kb-bg-card) var(--vt-glass-opacity), transparent);
  backdrop-filter: blur(var(--vt-glass-blur));
  -webkit-backdrop-filter: blur(var(--vt-glass-blur));
  border: 1px solid color-mix(in oklab, var(--kb-text-primary) var(--vt-glass-border-luminance), transparent);
  box-shadow: var(--vt-shadow-elevation-1);
  font-size: 0.9rem;
  transition:
    transform var(--vt-anim-duration) var(--vt-anim-ease),
    opacity var(--vt-anim-duration) var(--vt-anim-ease),
    box-shadow var(--vt-anim-duration) var(--vt-anim-ease);
  will-change: transform, opacity;
}

.gw-card--interest {
  border-color: color-mix(in oklab, var(--kb-primary) 45%, transparent);
  box-shadow:
    var(--vt-shadow-elevation-2),
    0 0 0 1px color-mix(in oklab, var(--kb-primary) 35%, transparent),
    0 0 26px color-mix(in oklab, var(--kb-primary) 16%, transparent);
}

/* ---------------------------------------------------------- Band 1: status bar */

.gw-card-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  background: color-mix(in oklab, var(--kb-bg-subtle) 45%, transparent);
  border-bottom: 1px solid color-mix(in oklab, var(--kb-text-primary) var(--vt-glass-border-luminance), transparent);
  min-height: 2.9rem;
}

.gw-bar-left,
.gw-bar-right {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.gw-count {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--kb-text-secondary);
  white-space: nowrap;
}

.gw-count i {
  color: var(--kb-text-muted);
  font-size: 0.85em;
}

.gw-state {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.3;
  white-space: nowrap;
}

.gw-state--ingame {
  color: var(--kb-success);
  background: color-mix(in oklab, var(--kb-success) 16%, transparent);
}

.gw-state--pregame {
  color: var(--kb-warning);
  background: color-mix(in oklab, var(--kb-warning) 18%, transparent);
}

.gw-state--neutral {
  color: var(--kb-text-secondary);
  background: color-mix(in oklab, var(--kb-bg-muted) 55%, transparent);
}

.gw-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--kb-text-secondary);
  background: color-mix(in oklab, var(--kb-bg-muted) 55%, transparent);
  white-space: nowrap;
}

.gw-tag--vsr {
  color: var(--kb-primary);
  background: color-mix(in oklab, var(--kb-primary) 15%, transparent);
}

.gw-join {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.22rem 0.6rem;
  border-radius: 0.45rem;
  font-size: 0.74rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--kb-primary-fg);
  background: var(--kb-primary);
  border: 1px solid transparent;
  transition: filter 0.15s ease;
  white-space: nowrap;
}

.gw-join:hover {
  filter: brightness(1.08);
  color: var(--kb-primary-fg);
}

.gw-join--locked {
  color: var(--kb-text-muted);
  background: color-mix(in oklab, var(--kb-bg-muted) 50%, transparent);
  cursor: not-allowed;
}

/* ---------------------------------------------------------- Band 2: info block */

.gw-card-info {
  display: grid;
  grid-template-columns: var(--gw-thumb) 1fr;
  grid-template-areas:
    "thumb dl"
    "msg   msg";
  gap: 0.7rem 0.9rem;
  padding: 0.9rem;
}

.gw-thumb {
  grid-area: thumb;
  width: var(--gw-thumb);
  height: var(--gw-thumb);
  border-radius: 0.5rem;
  overflow: hidden;
  background: color-mix(in oklab, var(--kb-bg-muted) 70%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.gw-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gw-thumb-broken {
  visibility: hidden;
}

.gw-thumb-placeholder {
  color: var(--kb-text-muted);
  font-size: 1.5rem;
}

.gw-dl {
  grid-area: dl;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  min-width: 0;
}

.gw-dl-row {
  display: grid;
  grid-template-columns: var(--gw-label-col) 1fr;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
}

.gw-dl-row dt {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--kb-text-muted);
}

.gw-dl-row dd {
  margin: 0;
  font-size: 0.8rem;
  color: var(--kb-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.gw-dd-map {
  font-weight: 600;
  color: var(--kb-text-primary);
}

.gw-dd-map .gw-map-link {
  color: inherit;
  text-decoration: none;
}

.gw-dd-map .gw-map-link:hover {
  text-decoration: underline;
}

.gw-dd-host {
  font-weight: 700;
  color: var(--kb-primary);
}

.gw-host-link {
  color: inherit;
  text-decoration: none;
}

.gw-host-link:hover {
  text-decoration: underline;
}

.gw-card-msg {
  grid-area: msg;
  font-size: 0.74rem;
  color: var(--kb-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.gw-card-msg--empty {
  color: var(--kb-text-muted);
  font-style: italic;
}

/* ---------------------------------------------------------- Band 3: players */

.gw-card-players {
  min-height: 0;
  max-height: 16rem;
  overflow-y: auto;
  padding: 0 0.9rem 0.8rem;
}

.gw-teams {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.gw-team {
  min-width: 0;
}

.gw-team-head {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--kb-text-muted);
  padding: 0 0.4rem 0.3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gw-team-rows,
.gw-plist {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.gw-others {
  margin-top: 0.4rem;
}

.gw-team-empty {
  font-size: 0.74rem;
  font-style: italic;
  color: var(--kb-text-muted);
  padding: 0.3rem 0.45rem;
}

.gw-prow {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.45rem;
  border-radius: 0.4rem;
  background: color-mix(in oklab, var(--kb-bg-muted) 28%, transparent);
  min-width: 0;
}

.gw-pname-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

.gw-prole {
  font-size: 0.7em;
  flex: 0 0 auto;
}

.gw-prole--cmdr {
  color: var(--kb-primary);
}

.gw-pname {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--kb-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  text-decoration: none;
}

a.gw-pname:hover {
  color: var(--kb-primary);
  text-decoration: underline;
}

.gw-pkds {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--kb-text-secondary);
  white-space: nowrap;
  flex: 0 0 auto;
}

.gw-open {
  margin-top: 0.4rem;
  font-size: 0.7rem;
  color: var(--kb-text-muted);
  font-style: italic;
}

/* ---------------------------------------------------------- Band 4: footer */

.gw-card-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  background: color-mix(in oklab, var(--kb-bg-subtle) 40%, transparent);
  border-top: 1px solid color-mix(in oklab, var(--kb-text-primary) var(--vt-glass-border-luminance), transparent);
  min-height: 2.8rem;
}

.gw-foot-version {
  font-size: 0.7rem;
  color: var(--kb-text-muted);
  flex: 0 0 auto;
}

.gw-foot-mod {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  flex: 1 1 auto;
}

.gw-mod {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  max-width: 100%;
  font-size: 0.72rem;
  color: var(--kb-text-secondary);
  text-decoration: none;
}

.gw-mod span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gw-mod i {
  color: var(--kb-text-muted);
  flex: 0 0 auto;
}

a.gw-mod:hover {
  color: var(--kb-primary);
}

a.gw-mod:hover i {
  color: var(--kb-primary);
}

.gw-mod--stock {
  font-style: italic;
  color: var(--kb-text-muted);
}

.gw-more {
  flex: 0 0 auto;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--kb-primary);
  background: color-mix(in oklab, var(--kb-primary) 12%, transparent);
  border: none;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  cursor: pointer;
}

.gw-more:hover {
  background: color-mix(in oklab, var(--kb-primary) 20%, transparent);
}

.gw-details {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border: none;
  border-radius: 0.4rem;
  color: var(--kb-text-secondary);
  background: color-mix(in oklab, var(--kb-bg-muted) 45%, transparent);
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.gw-details:hover {
  color: var(--kb-text-primary);
  background: color-mix(in oklab, var(--kb-primary) 15%, transparent);
}

/* ----------------------------------------------------------------- Popovers */

.vt-gw-popover {
  --bs-popover-bg: color-mix(in oklab, var(--kb-bg-card) 96%, transparent);
  --bs-popover-border-color: var(--kb-border-subtle);
  --bs-popover-header-bg: transparent;
  --bs-popover-header-color: var(--kb-text-primary);
  --bs-popover-body-color: var(--kb-text-secondary);
  --bs-popover-max-width: 280px;
  box-shadow: var(--vt-shadow-elevation-2);
}

.vt-gw-popover .popover-header {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom-color: var(--kb-border-subtle);
}

.gw-pop-mods {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.gw-pop-mod {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--kb-text-secondary);
  text-decoration: none;
}

a.gw-pop-mod:hover {
  color: var(--kb-primary);
}

.gw-pop-stats {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.gw-pop-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.78rem;
}

.gw-pop-stat-label {
  color: var(--kb-text-muted);
}

.gw-pop-stat-val {
  color: var(--kb-text-primary);
  font-weight: 600;
}

/* ----------------------------------------------------------------- Empty state */

.vt-gw-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--kb-text-muted);
}

.vt-gw-empty-icon {
  font-size: 2.6rem;
  color: var(--kb-text-muted);
  margin-bottom: 0.75rem;
  opacity: 0.7;
}

.vt-gw-empty-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--kb-text-secondary);
}

.vt-gw-empty-sub {
  font-size: 0.9rem;
  max-width: 42ch;
}

/* ----------------------------------------------------------------- Enter / exit / FLIP */

.gw-card.gw-enter-init {
  opacity: 0;
  transform: translateY(10px) scale(0.985);
}

.gw-card.gw-exit {
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
}

/* ----------------------------------------------------------------- Reduced motion */

@media (prefers-reduced-motion: reduce) {
  .gw-dot {
    animation: none;
  }
  .gw-card {
    transition: none;
  }
  .gw-card.gw-enter-init {
    opacity: 1;
    transform: none;
  }
}
