/* ==========================================================================
   Killfeed v2 (/killfeed/v2) — built on Skynet UI (https://skynetui.com)

   Only page-local layout lives here. Components come from skynet-ui.css and
   the palettes from themes-v2.css, which loads first — every colour below is a
   Skynet UI token, so the page follows whichever of the twelve palettes the
   visitor picked. The one literal is the `#fff` on the new-events pill, which
   sits on a solid `--sk-primary` fill — `npm run test:themes` asserts white on
   primary clears 4.5:1 in all twelve, which is exactly what makes that safe.
   ========================================================================== */

/* Skynet UI declares `.hidden` before its component display rules, so a hidden
   `.sk-badge` or `.sk-btn` would still render. This page hides with the
   `hidden` ATTRIBUTE (one mechanism, and the one the script sets), and every
   `display` rule below is a class selector — which ties with `[hidden]` on
   specificity and then wins on order. Both guards, scoped to the page. */
.kv2 [hidden] { display: none !important; }
.kv2 .hidden { display: none !important; }

.kv2-main { padding-top: 2rem; padding-bottom: 3rem; }

/* ---------- page head ---------- */
.kv2-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kv2-head-text { min-width: 0; }
.kv2-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sk-primary-text);
}
.kv2-title {
  margin: 0 0 0.35rem;
  font-size: clamp(1.9rem, 1.3rem + 2.2vw, 2.75rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.kv2-head-acts {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* The live marker. The script only shows it while the refresh loop is actually
   running, so the dot means "this page is polling", not "this page is pretty". */
.kv2-live {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--sk-success-soft);
  color: var(--sk-success-text);
}
.kv2-live-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  animation: kv2-pulse 1.8s ease-in-out infinite;
}
.kv2-live.is-paused {
  background: var(--sk-surface-2);
  color: var(--sk-text-2);
}
.kv2-live.is-paused .kv2-live-dot { animation: none; }
@keyframes kv2-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Skynet UI toggles this element's `hidden` attribute from navigator.onLine, so
   the markup ships it hidden and the rule above takes it away again. Styling it
   `display: none` here would mean it could never be shown. */
.kv2-offline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.kv2-noscript { margin-bottom: 1.25rem; }

/* ---------- the server picker ---------- */
/* Skynet UI's .sk-card is `overflow: hidden`, and the combobox list is
   absolutely positioned inside this one — so the card was CLIPPING the list at
   its own bottom edge. Every option past the card's height was invisible and
   untappable: one of four reachable on a 1440 desktop, three of four on a
   320px phone, and with a real server list the clip lands on option two.
   Nothing about it looks broken, which is why it survived review — the list
   was in the DOM, keyboard selection worked, and only measuring where the
   options were actually painted showed it. `npm run audit:killfeed-v2`. */
.kv2-picker-card {
  margin-bottom: 1.5rem;
  overflow: visible;
}
.kv2-picker-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1.25rem;
}
.kv2-picker {
  flex: 1 1 20rem;
  /* A flex child will not shrink below its content without this, which is the
     usual cause of a row that pushes the page sideways on a phone. */
  min-width: 0;
}
.kv2-picker .sk-label { display: block; margin-bottom: 0.35rem; }
.kv2-picker-help { margin: 0.4rem 0 0; }
.kv2-combobox { width: 100%; }
/* The list is capped at the room actually left below the input — the page
   script measures that against the VISUAL viewport, which is the one the
   on-screen keyboard shrinks. The fallback is for no JS. */
.kv2-server-list { max-height: var(--kv2-list-max, min(22rem, 50vh)); }
/* When the script scrolls the picker up to make room for the list, it must
   not land under the fixed header. */
.kv2-picker { scroll-margin-top: calc(var(--skv2-h, 60px) + 0.75rem); }

/* If skynet-ui.js never arrives, the framework's click-to-open never binds and
   the list stays `display: none` — a dead input. Focus opens it in CSS alone,
   so the picker still works with the stylesheet and nothing else.

   Only when the framework is missing: public/js/killfeed-v2.js puts `kv2-sk` on
   <html> when it finds Skynet UI's globals. With both rules live, a keyboard
   pick hands focus back to the input, focus-within reopens the list, and it
   covers the controls under it — which is how this scoping was found. */
html:not(.kv2-sk) .kv2 .sk-combobox:focus-within .sk-combobox-list { display: block; }

.kv2-option {
  display: flex !important;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  text-align: left;
}
.kv2-option-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv2-option-id {
  flex: none;
  font-size: 0.75rem;
  color: var(--sk-muted);
}

.kv2-period { flex: none; }
.kv2-period .sk-label { display: block; margin-bottom: 0.35rem; }
.kv2-period-group { flex-wrap: wrap; }
.kv2-clear { flex: none; margin-bottom: 0.1rem; }

.kv2-servers-skeleton { margin-top: 0.75rem; }
.kv2-servers-error,
.kv2-stats-error,
.kv2-feed-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.75rem 0 0;
}

/* ---------- section heads ---------- */
.kv2-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.kv2-section-title {
  margin: 0 0 0.25rem;
  font-size: clamp(1.15rem, 1rem + 0.6vw, 1.5rem);
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.kv2-server { margin-top: 2rem; }
.kv2-server-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}
.kv2-server-id { color: var(--sk-muted); }
.kv2-dot { color: var(--sk-muted); }

/* ---------- tiles ---------- */
/* auto-fit + minmax rather than a column count: the same grid carries six
   figures on one page and seven on the other, and reflows at every width with
   no breakpoint of its own. */
.kv2-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 0.75rem;
  margin: 0 0 1.25rem;
}
.kv2-tile {
  position: relative;
  padding: 0.85rem 0.9rem;
  background: var(--sk-surface);
  border: 1px solid var(--sk-border);
  border-radius: var(--sk-radius);
  min-width: 0;
}
.kv2-tile-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  margin-bottom: 0.5rem;
  border-radius: var(--sk-radius-sm);
  background: var(--sk-primary-soft);
  color: var(--sk-primary-text);
  font-size: 0.8rem;
}
.kv2-tile .sk-stat-label { display: block; }
.kv2-tile-value {
  margin: 0.15rem 0 0;
  /* NO overflow-wrap here, and the clamp is sized for the narrowest column
     these tiles are ever laid out in. `overflow-wrap: anywhere` gives a browser
     permission to break inside a numeral, and it takes it: the global band
     rendered 28,004,112 as "28,004,1 / 12" at 1440px, which is not a number.
     Without it a figure is one unbreakable word, so the only thing that has to
     be right is that it fits — ten digits in a 7.5rem column at 320px. */
  font-size: clamp(1.02rem, 0.85rem + 0.7vw, 1.4rem);
  font-variant-numeric: tabular-nums;
}
/* Each stat says what it counts, because "PvE deaths" and "Flag events" are
   not self-evident and the numbers are easy to misread as something else. */
.kv2-tile-note {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--sk-muted);
}
.kv2-tile-loading { min-height: 6rem; }
.kv2-stats-skeleton {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.kv2-updated {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: -0.5rem 0 1.5rem;
  font-size: 0.8rem;
}
.kv2-global { margin-bottom: 1.5rem; }
.kv2-landing { margin-bottom: 2rem; }

/* ---------- the feed ---------- */
.kv2-feed-card { overflow: visible; }
.kv2-feed-head {
  flex-wrap: wrap;
  gap: 0.75rem;
}
.kv2-feed-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.kv2-feed-count { font-size: 0.8rem; font-weight: 400; }
.kv2-feed-acts {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.kv2-auto { margin: 0; font-size: 0.85rem; }
.kv2-filters {
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.kv2-filters .sk-tab i { margin-right: 0.35rem; }
.kv2-feed-note {
  margin: 0 0 1rem;
  font-size: 0.78rem;
}

/* Offered, never applied: new rows land above the fold only when the reader is
   already there, so this is a button rather than a live region that moves the
   page under a thumb. */
.kv2-newpill {
  position: sticky;
  top: calc(var(--skv2-h, 60px) + 0.5rem);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.9rem;
  background: var(--sk-primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--sk-shadow-lg);
}
.kv2-newpill:hover { background: var(--sk-primary-hover); }

.kv2-feed {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.kv2-feed-skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.kv2-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  background: var(--sk-surface-2);
  border: 1px solid var(--sk-border);
  border-left: 3px solid var(--sk-border-2);
  border-radius: var(--sk-radius);
  min-width: 0;
}
.kv2-row-kill { flex-direction: column; border-left-color: var(--sk-danger); }
/* The icon sits beside the first line of the sentence, not centred against a
   sentence that wrapped onto two. */
.kv2-row-simple { align-items: flex-start; }
.kv2-row-pve { border-left-color: var(--sk-warning); }
.kv2-row-join { border-left-color: var(--sk-success); }
.kv2-row-leave { border-left-color: var(--sk-muted); }
.kv2-row-build { border-left-color: var(--sk-info); }
.kv2-row-loading { align-items: center; }
.kv2-row-loading-lines { flex: 1; min-width: 0; }

/* A row that arrived while you were reading. Under reduced motion it simply
   appears — the rule below turns the fade off, and nothing depends on it. */
.kv2-row-new { animation: kv2-in 0.35s ease both; }
@keyframes kv2-in {
  from { opacity: 0; transform: translateY(-0.35rem); }
  to { opacity: 1; transform: none; }
}

.kv2-row-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
/* The type badge's label takes the page's text colour, not the framework's
   `*-text` token for its tone. Skynet UI puts that token on a 12% tint of
   itself, and here the tint composites over the row's --sk-surface-2 rather
   than a card's --sk-surface — about a point of contrast, which put the info
   badge at 4.42:1 in three light palettes (npm run audit:themes found it).
   The tone is still carried by the tint behind the label and the row's edge. */
.kv2-type { flex: none; }
.kv2 .kv2-type { color: var(--sk-text); }
.kv2-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--sk-muted);
}
.kv2-clock { font-family: var(--sk-font-mono); }

.kv2-row-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--sk-surface);
  border: 1px solid var(--sk-border);
  color: var(--sk-text-2);
  font-size: 0.8rem;
}
.kv2-row-main { flex: 1; min-width: 0; }
.kv2-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem;
  margin: 0;
  font-size: 0.9rem;
  color: var(--sk-text-2);
  overflow-wrap: anywhere;
}
.kv2-object { color: var(--sk-text); font-weight: 600; }

/* ---------- a PvP kill ---------- */
/* Three columns from 48em: killer, the weapon between them, victim. Below that
   the weapon sits between two stacked names, which is the same sentence read
   top to bottom. */
.kv2-duel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  align-items: center;
}
@media (min-width: 48em) {
  .kv2-duel {
    grid-template-columns: 1fr auto 1fr;
    gap: 1rem;
  }
  .kv2-actor-victim { text-align: right; }
  .kv2-actor-victim .kv2-actor-meta { justify-content: flex-end; }
}
.kv2-actor { min-width: 0; }
.kv2-actor-role {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sk-muted);
}
/* A kill row colours the two names by role (sk-team-friendly / sk-team-enemy).
   A simple row's name is a plain link, and inheriting the framework's `a`
   colour put --sk-primary on --sk-surface-2 at 2.8:1 in dark. --sk-primary-text
   is the token measured for exactly this job. */
.kv2-row-simple .kv2-actor-name { color: var(--sk-primary-text); }
.kv2-actor-name {
  display: block;
  font-size: 1rem;
  font-weight: 650;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.kv2-actor-name:hover { text-decoration: underline; }
.kv2-actor-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.2rem;
}
.kv2-clan { font-size: 0.7rem; }
.kv2-kd {
  font-size: 0.72rem;
  color: var(--sk-muted);
}
.kv2-kd b {
  font-family: var(--sk-font-mono);
  color: var(--sk-text-2);
}

.kv2-weapon {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.35rem 0.6rem;
  background: var(--sk-surface);
  border: 1px solid var(--sk-border);
  border-radius: 999px;
}
.kv2-weapon-img {
  /* Reserved box, so a picture arriving late cannot shift the row. */
  width: 3.5rem;
  height: 1.5rem;
  max-width: 100%;
  object-fit: contain;
  flex: none;
}
.kv2-weapon-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--sk-text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kv2-weapon-arrow {
  flex: none;
  font-size: 0.7rem;
  color: var(--sk-muted);
}
@media (min-width: 48em) {
  .kv2-weapon { justify-content: center; }
  /* The arrow reads left-to-right only in the three-column layout; stacked, the
     order already says which way the kill went. */
  .kv2-weapon-arrow { display: none; }
}

.kv2-more {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}
.kv2-feed-empty,
.kv2-feed-nolog { margin-top: 0.5rem; }

.kv2-totop {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 60;
  box-shadow: var(--sk-shadow-lg);
}

/* ---------- touch ---------- */
/* Skynet UI sizes for a mouse: .sk-tab is ~38px tall and .sk-btn-sm is 34px.
   Both are below the 44px floor a finger needs, and a 14px field makes iOS zoom
   the page on focus. Widened for coarse pointers only, so the desktop toolbar
   stays dense. */
.kv2 .sk-tab { min-height: 44px; }
@media (pointer: coarse) {
  .kv2 .sk-btn,
  .kv2 .sk-btn-sm,
  .kv2 .kv2-newpill,
  .kv2 .kv2-option { min-height: 44px; }
  .kv2 .sk-input,
  .kv2 .sk-select { min-height: 44px; font-size: 16px; }
}

@media (max-width: 30em) {
  .kv2-head-acts { width: 100%; }
  .kv2-tiles { grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); }
  .kv2-stats-skeleton { grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .kv2-live-dot { animation: none; }
  .kv2-row-new { animation: none; }
}
