:root {
  --bg: #050914;
  --panel: rgba(13, 20, 34, .9);
  --card: rgba(255, 255, 255, .07);
  --card-focus: rgba(59, 130, 246, .28);
  --line: rgba(255, 255, 255, .12);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --ok: #22c55e;
  --shadow: 0 24px 70px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 80% 0%, rgba(59, 130, 246, .24), transparent 34%),
    radial-gradient(circle at 15% 10%, rgba(34, 197, 94, .12), transparent 28%),
    var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
}

button {
  border: 0;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.app, .screen {
  width: 100%;
  height: 100%;
}

.screen {
  display: none;
  grid-template-rows: auto 1fr;
  gap: clamp(14px, 2vw, 24px);
  padding: clamp(16px, 3vw, 44px);
}
.screen.active { display: grid; }

.activation-screen {
  place-items: center;
}
.activation-card {
  width: min(720px, 94vw);
  max-width: 100%;
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: clamp(28px, 5vw, 58px);
  border: 1px solid var(--line);
  border-radius: 34px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}
.activation-card h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 3rem);
}
.device-code {
  direction: ltr;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 26px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(2rem, 7vw, 4.8rem);
  font-weight: 900;
  letter-spacing: clamp(.04em, 1vw, .12em);
  line-height: 1.1;
  white-space: nowrap;
}
.activation-text {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.35rem);
  line-height: 1.7;
}

.screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
}
.screen-head h1 {
  margin: 4px 0 0;
  font-size: clamp(1.55rem, 3vw, 3rem);
  letter-spacing: -.03em;
}
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: clamp(.75rem, 1vw, 1rem);
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.status {
  margin: 0;
  color: var(--muted);
  font-size: clamp(.9rem, 1.35vw, 1.25rem);
  font-weight: 800;
}

.grid {
  min-height: 0;
  overflow: auto;
  padding: 4px;
  scroll-padding: 24px;
}
.topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  align-content: start;
  gap: clamp(12px, 1.7vw, 22px);
}
.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  align-content: start;
  gap: clamp(10px, 1.4vw, 18px);
}

.tile {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .14);
  transition: transform .14s ease, background .14s ease, border-color .14s ease;
}
.tile:focus {
  outline: 4px solid var(--accent);
  outline-offset: 4px;
  border-color: rgba(255, 255, 255, .36);
  background: var(--card-focus);
  transform: scale(1.045);
  z-index: 2;
}
.tile.active {
  border-color: rgba(34, 197, 94, .65);
  background: rgba(34, 197, 94, .12);
}

.topic-tile {
  min-height: clamp(132px, 15vw, 210px);
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 18px;
  text-align: center;
}
.topic-tile strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(1rem, 1.45vw, 1.35rem);
}
.tile-logo {
  width: clamp(58px, 7vw, 96px);
  height: clamp(58px, 7vw, 96px);
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 22px;
  background: rgba(255, 255, 255, .09);
  color: var(--muted);
  font-size: 1.4rem;
  font-weight: 900;
}
.tile-logo img, .channel-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.channel-tile {
  min-height: clamp(82px, 8vw, 112px);
  display: grid;
  grid-template-columns: clamp(58px, 6vw, 82px) 1fr;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  text-align: right;
}
.channel-logo {
  width: clamp(58px, 6vw, 82px);
  height: clamp(58px, 6vw, 82px);
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 8px;
  border-radius: 18px;
  background: rgba(255, 255, 255, .09);
  color: var(--muted);
  font-weight: 900;
}
.channel-meta {
  min-width: 0;
}
.channel-meta strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(1rem, 1.35vw, 1.3rem);
}
.channel-meta small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  direction: ltr;
  text-align: left;
  font-size: .82rem;
  font-weight: 700;
}

.nav-btn {
  min-width: 110px;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .09);
  font-weight: 900;
}
.nav-btn:focus {
  outline: 4px solid var(--accent);
  outline-offset: 4px;
  background: rgba(59, 130, 246, .28);
}

.player-screen {
  position: fixed;
  inset: 0;
  display: none;
  padding: 0;
  background: #000;
}
.player-screen.active { display: block; }
video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.player-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 24px;
  background: radial-gradient(circle, rgba(15, 23, 42, .58), rgba(0, 0, 0, .88));
  text-align: center;
}
.player-loader[hidden] { display: none; }
.player-loader strong {
  font-size: clamp(1.5rem, 3vw, 3rem);
}
.player-loader span {
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.4rem);
}
.player-controls {
  position: absolute;
  right: clamp(12px, 2vw, 28px);
  bottom: clamp(12px, 2vw, 28px);
  left: clamp(12px, 2vw, 28px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.player-controls.visible,
.player-controls:focus-within {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.server-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  width: min(440px, 92vw);
  max-height: 50vh;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(7, 11, 18, .96);
  box-shadow: var(--shadow);
}
.server-menu[hidden] { display: none; }
.server-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-radius: 14px;
  background: transparent;
  text-align: right;
  font-weight: 800;
}
.server-option.active {
  background: rgba(34, 197, 94, .18);
}
.server-option:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  background: rgba(59, 130, 246, .22);
}
.server-option small {
  color: var(--muted);
  direction: ltr;
}

@media (max-width: 700px) {
  body { overflow: auto; }
  .screen {
    min-height: 100svh;
    height: auto;
    padding: 14px;
  }
  .screen-head {
    min-height: 54px;
  }
  .topics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .channels-grid {
    grid-template-columns: 1fr;
  }
  .topic-tile {
    min-height: 118px;
    border-radius: 18px;
  }
  .channel-tile {
    border-radius: 18px;
  }
  .nav-btn {
    min-width: 86px;
    padding: 10px 13px;
  }
  .player-controls {
    align-items: stretch;
    flex-direction: column-reverse;
  }
  .player-controls .nav-btn {
    width: 100%;
  }
  .server-menu {
    right: 0;
    left: auto;
    width: 100%;
  }
}
