:root {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #171b23;
  --border: #262c37;
  --text: #e6e9ef;
  --muted: #8b93a1;
  --accent: #4f8cff;
  --danger: #ff5d5d;
  --live: #22c55e;
  --topbar-h: 53px;
  --pad-x: clamp(16px, 3vw, 36px);
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
code {
  background: var(--panel);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}
.mono {
  font-family: ui-monospace, monospace;
}
.muted {
  color: var(--muted);
  font-size: 0.85em;
}
.error {
  color: var(--danger);
  margin: 8px 0;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ---------- shell: topbar + sport nav + content ---------- */
.shell {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar"
    "side main";
}
.shell.single {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "topbar"
    "main";
}

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 var(--pad-x);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
}
.topbar nav {
  display: flex;
  gap: 16px;
  align-items: center;
}

.sport-nav {
  grid-area: side;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  border-right: 1px solid var(--border);
}
.sport-nav button {
  background: none;
  border: none;
  border-radius: 8px;
  min-height: 44px;
  padding: 10px 14px;
  text-align: left;
  color: var(--muted);
  transition:
    color 150ms,
    background-color 150ms,
    box-shadow 150ms;
}
.sport-nav button:hover {
  color: var(--text);
  background: var(--panel);
}
.sport-nav button.active {
  color: var(--text);
  background: var(--panel);
  box-shadow: inset 3px 0 0 var(--accent);
}

.content {
  grid-area: main;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 18px var(--pad-x) 64px;
}

@media (max-width: 899px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "side"
      "main";
  }
  .sport-nav {
    position: sticky;
    top: var(--topbar-h);
    z-index: 20;
    height: auto;
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 8px var(--pad-x);
    border-right: none;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(10px);
  }
  .sport-nav::-webkit-scrollbar {
    display: none;
  }
  .sport-nav button {
    flex: 0 0 auto;
    white-space: nowrap;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel);
    color: var(--text);
    padding: 9px 16px;
    min-height: 40px;
  }
  .sport-nav button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: none;
  }
  .content {
    padding-top: 14px;
  }
}

/* ---------- search ---------- */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 0 18px;
}
.search-icon {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--muted);
  pointer-events: none;
}
.search-bar input[type="search"] {
  flex: 1;
  max-width: 520px;
  min-height: 44px;
  padding-left: 38px;
  font-size: 1rem;
}
.search-clear {
  position: absolute;
  left: min(calc(520px - 40px), calc(100% - 44px));
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  background: none;
  border: none;
  color: var(--muted);
}
.search-clear:hover {
  color: var(--text);
}
.search-clear svg {
  width: 16px;
  height: 16px;
}

/* ---------- live strip ---------- */
.live-section {
  margin-bottom: 22px;
}
.strip-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}
.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--live);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
}
.badge-recent {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.accent-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.badge-soon {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.live-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 calc(-1 * var(--pad-x));
  padding: 4px var(--pad-x) 8px;
}
.live-strip::-webkit-scrollbar {
  display: none;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 10px;
}

/* ---------- event rows & hero cards ---------- */
.event-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
  text-align: left;
  transition: border-color 150ms;
}
.event-hero {
  flex: 0 0 min(280px, 76vw);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 0 0 10px;
  text-align: left;
  overflow: hidden;
  transition: border-color 150ms;
}
.event-hero .poster-fallback {
  border-radius: 0;
}
.event-hero b {
  padding: 2px 12px 0;
}
.event-hero .event-desc {
  padding: 0 12px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.event-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.event-main b {
  overflow-wrap: anywhere;
}
.event-desc {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.event-row:hover:not(:disabled),
.event-hero:hover:not(:disabled) {
  border-color: var(--accent);
}

.event-row img,
.event-hero img,
.poster-fallback {
  width: 96px;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--border);
  border-radius: 6px;
}
.event-hero img,
.event-hero .poster-fallback {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 0;
}
.poster-fallback {
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  color: color-mix(in srgb, var(--text) 65%, transparent);
}
.event-hero .poster-fallback {
  font-size: 30px;
}

.rows {
  display: flex;
  flex-direction: column;
  margin-bottom: 22px;
}
@media (max-width: 899px) {
  /* Status chips live in the text column here: as a third `auto` grid
     column the nowrap "starts …" badge keeps its ~155px min-content width
     and starves the title column at phone widths (<~500px). */
  .event-row {
    grid-template-columns: 96px minmax(0, 1fr);
  }
  .event-row .badge-live,
  .event-row .badge-soon {
    grid-column: 2;
    justify-self: start;
  }
}

.empty {
  padding: 34px 0;
  text-align: center;
}
.empty p {
  margin: 4px 0;
}

/* ---------- skeletons ---------- */
.skeleton-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 8px;
  padding: 8px 10px;
}
.skeleton-thumb,
.skeleton-lines span {
  display: block;
  border-radius: 6px;
  background: linear-gradient(100deg, var(--panel) 40%, var(--border) 50%, var(--panel) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-thumb {
  width: 96px;
  aspect-ratio: 16/9;
}
.skeleton-lines {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.skeleton-lines span {
  height: 12px;
}
.skeleton-lines span:last-child {
  width: 60%;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------- auth ---------- */
.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
}
.auth-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, 92vw);
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.auth-card h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

input,
select,
button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.95rem;
}
button {
  cursor: pointer;
}
button:hover:not(:disabled) {
  border-color: var(--accent);
}
button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
}
button.danger {
  color: var(--danger);
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- api keys panel ---------- */
.key-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  font-size: 1rem;
  font-weight: 600;
}
.key-toggle .chev {
  width: 18px;
  height: 18px;
  color: var(--muted);
  transition: transform 150ms;
}
.key-toggle .chev.open {
  transform: rotate(180deg);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin: 14px 0;
}
.key-panel > * ~ * {
  margin-top: 12px;
}
.key-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.key-list li {
  display: flex;
  align-items: center;
  gap: 12px;
}
.fresh-key {
  background: var(--bg);
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 12px;
  margin: 10px 0;
}
.key-box {
  display: block;
  word-break: break-all;
  user-select: all;
  margin-top: 6px;
}

/* ---------- player modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: grid;
  place-items: center;
  z-index: 50;
}
.modal {
  width: min(860px, 94vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.modal-head > span {
  display: flex;
  gap: 16px;
}
.modal video {
  width: 100%;
  aspect-ratio: 16/9;
  background: black;
  border-radius: 8px;
}

/* ---------- admin ---------- */
.users {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
}
.users th,
.users td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.feed-bar {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 10px;
  scrollbar-width: thin;
}
.feed-chip {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 0.85rem;
  padding: 5px 12px;
  border-radius: 999px;
}
.feed-chip.active {
  border-color: var(--accent);
  color: var(--accent);
}
.obs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.obs-head h2 {
  margin: 0;
}
.obs-tabs {
  margin: 12px 0 16px;
}
.metric-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.metric-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--live);
}
.metric-label {
  font-weight: 600;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.metric-grid h3 {
  margin: 14px 0 8px;
  font-size: 0.95rem;
}
.metric-grid h3:first-child {
  margin-top: 0;
}
.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(80px, 1.2fr) auto;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 0.85rem;
}
.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  display: block;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.bar-fill.bar-ok {
  background: var(--live);
}
.bar-value {
  color: var(--muted);
  white-space: nowrap;
}
.log-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.log-bar input[type="search"] {
  flex: 1;
}
.log-follow {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.logs {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 0.8rem;
}
.log-error {
  color: var(--danger);
}
.log-warn {
  color: #f5b301;
}
.log-info {
  color: var(--text);
}

/* Multi-view (issue #53) */

.multi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.multi-grid.single {
  grid-template-columns: 1fr;
}

.multi-grid:fullscreen {
  width: 100vw;
  height: 100vh;
  background: #000;
  padding: 8px;
  box-sizing: border-box;
  grid-auto-rows: minmax(0, 1fr);
}

.multi-grid:fullscreen .multi-tile {
  min-height: 0;
}

.multi-grid:fullscreen .multi-tile video {
  flex: 1;
  min-height: 0;
  aspect-ratio: auto;
}

.multi-tile {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border, #333);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel, #16181d);
}

.multi-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
}

.multi-tile-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.multi-tile video {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #000;
}

.selection-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border, #333);
  background: color-mix(in srgb, var(--panel, #16181d) 85%, transparent);
  backdrop-filter: blur(6px);
  z-index: 50;
}

.event-row[aria-pressed="true"],
.event-hero[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.multi-modal {
  width: min(1400px, 96vw);
}

/* topcoat port: the key panel body (everything the React version conditionally
   rendered) lives in one wrapper element, so the sibling-gap rule reapplies
   inside it. */
.ss-key-body > * ~ * {
  margin-top: 12px;
}

/* topcoat port: the pending panel is server-rendered (hidden) as a shell child
   like the React conditional; it only becomes a grid item after approval. */
.content > .ss-pending {
  grid-area: main;
}

/* topcoat port: the React version conditionally renders nodes; the server
   version toggles the hidden attribute on always-rendered nodes whose classes
   set display (flex/grid). The UA [hidden] rule loses to those, so re-assert. */
[hidden] {
  display: none !important;
}

/* issue #75: football country/competition sections (football tab only) and
   the country badge on event rows. Everything else keeps the flat row list. */
.badge-country {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
details.ss-country {
  margin-bottom: 10px;
}
details.ss-country > summary,
details.ss-comp > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
details.ss-country > summary::-webkit-details-marker,
details.ss-comp > summary::-webkit-details-marker {
  display: none;
}
details.ss-comp {
  margin: 0 0 8px 18px;
}
.ss-comp-logo {
  width: 20px;
  height: 20px;
  object-fit: contain;
}
.ss-comp-count {
  margin-left: auto;
  font-weight: 400;
}

/* favorites: star toggles, team star rows, pinned bar, row flag. */
.ss-fav-star {
  padding: 0 4px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
}
.ss-fav-star[aria-pressed="true"] {
  color: #f5b301;
}
.ss-team-stars {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: -4px 0 6px 10px;
  font-size: 12px;
}
.badge-fav {
  color: #f5b301;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
}
.fav-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.fav-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
}
.fav-kind {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-fav-dot {
  color: #f5b301;
  font-size: 14px;
}
