:root {
  --bg: #0a0e13;
  --surface: #121a23;
  --surface-2: #18222e;
  --border: #23303d;
  --text: #e8eef5;
  --muted: #8fa0b3;
  --accent: #22c55e;
  --accent-soft: rgba(34, 197, 94, 0.14);
  --live: #ef4444;
  --geo: #f59e0b;
  --radius: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

body.locked {
  overflow: hidden;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(10, 14, 19, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(35, 48, 61, 0.6);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #22c55e, #0e9f6e);
  color: #04140b;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.5px;
  box-shadow: 0 6px 18px rgba(34, 197, 94, 0.22);
}

.brand-text {
  min-width: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: -0.3px;
}

.brand-text p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
}

.country-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
}

.country-btn span:first-child {
  font-size: 18px;
  line-height: 1;
}

main {
  padding: 12px 16px 28px;
  max-width: 900px;
  margin: 0 auto;
}

.search-row {
  position: relative;
  margin-bottom: 10px;
}

.search-row input {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0 44px 0 14px;
  font-size: 15px;
  outline: none;
}

.search-row input:focus {
  border-color: rgba(34, 197, 94, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
}

.search-row input::placeholder {
  color: #66788c;
}

.clear-search {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0 4px;
  margin: 0 -2px;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.tab[aria-selected='true'] {
  background: var(--accent-soft);
  border-color: rgba(34, 197, 94, 0.45);
  color: #b8f5cc;
}

.tab-count {
  margin-left: 6px;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.status-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 2px 12px;
  line-height: 1.4;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 10px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 128px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), #0f161e);
  text-align: left;
  overflow: hidden;
  transition: border-color 120ms ease, transform 120ms ease;
}

.card:active {
  transform: scale(0.985);
  border-color: rgba(34, 197, 94, 0.5);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.logo {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 11px;
  background: #0b131b;
  border: 1px solid rgba(35, 48, 61, 0.8);
  overflow: hidden;
}

.logo img {
  position: absolute;
  inset: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  object-fit: contain;
  background: transparent;
}

.logo .initial {
  font-size: 14px;
  font-weight: 800;
  color: #7f95aa;
  letter-spacing: -0.5px;
}

.logo.has-logo .initial {
  display: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge.live {
  background: rgba(239, 68, 68, 0.16);
  color: #ff8b8b;
}

.badge.live::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.badge.geo {
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
}

.badge.wait {
  background: rgba(143, 160, 179, 0.12);
  color: var(--muted);
}

.card-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 32px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  flex: 0 0 3px;
}

.card-meta .quality {
  color: #9fb3c8;
  font-weight: 700;
}

.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}

.empty p {
  margin: 0 0 6px;
  font-size: 14px;
}

.empty p:first-child {
  color: var(--text);
  font-weight: 700;
}

.primary {
  margin-top: 12px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: #04140b;
  font-weight: 800;
}

.footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  color: #5c6f83;
  font-size: 11px;
  line-height: 1.5;
}

.footer p {
  margin: 2px 0;
}

/* Player */

.player {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player[hidden] {
  display: none;
}

.player video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.player.idle .player-top,
.player.idle .source-list {
  opacity: 0;
  pointer-events: none;
}

.player-top,
.source-list {
  transition: opacity 180ms ease;
}

.play-toggle {
  position: relative;
  z-index: 2;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  backdrop-filter: blur(4px);
}

.play-toggle[hidden] {
  display: none;
}

.player-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 26px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0));
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 20px;
  line-height: 1;
}

.player-title {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-title strong {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-title span {
  color: #a9bacb;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-state {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 18px 24px;
  border-radius: 16px;
  background: rgba(8, 12, 17, 0.72);
  backdrop-filter: blur(6px);
  color: #d7e2ee;
  text-align: center;
  font-size: 13px;
}

.player-state[hidden] {
  display: none;
}

.player-state.error {
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.player-state p {
  margin: 0;
  max-width: 260px;
  line-height: 1.4;
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

.player-state.error .spinner {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.source-list {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 20px 12px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0));
  scrollbar-width: none;
}

.source-list::-webkit-scrollbar {
  display: none;
}

.source-chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(18, 26, 35, 0.88);
  color: #c7d4e2;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.source-chip.active {
  border-color: rgba(34, 197, 94, 0.65);
  background: rgba(34, 197, 94, 0.16);
  color: #c4f9d5;
}

/* Country sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.sheet[hidden] {
  display: none;
}

.sheet-inner {
  width: 100%;
  max-height: 78dvh;
  display: flex;
  flex-direction: column;
  background: #0e151d;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 16px;
}

.country-list {
  overflow-y: auto;
  padding: 4px 10px 16px;
}

.country-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-size: 14px;
}

.country-item:active,
.country-item.active {
  background: var(--surface-2);
}

.country-item .flag {
  font-size: 21px;
  line-height: 1;
}

.country-item .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.country-item .count {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 560px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
  .card {
    min-height: 138px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .spinner {
    transition: none;
    animation-duration: 0.01ms;
  }
}
