@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@500;600;700&family=IBM+Plex+Mono:wght@500&family=Oswald:wght@500;600;700&display=swap');

:root {
  color-scheme: dark;
  --bg: #070b14;
  --panel: #121c31;
  --line: #2a3a57;
  --text: #f2f5fb;
  --muted: #92a0b8;
  --accent: #d50a0a;
  --accent-deep: #9e0b0f;
  --online: #3bbf6a;
  --offline: #e25555;
  font-family: 'Barlow', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 70% 45% at 50% -8%, rgba(1, 51, 105, 0.35), transparent 55%),
    linear-gradient(180deg, #0a1020 0%, var(--bg) 42%, #05080f 100%);
}

header {
  height: 92px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 4%;
  border-bottom: 1px solid rgba(42, 58, 87, 0.85);
  background: rgba(8, 14, 26, 0.9);
}

.header-side {
  display: flex;
  align-items: center;
  min-width: 0;
}

.header-status {
  justify-content: flex-end;
  padding-right: 4px;
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  line-height: 0;
  padding: 10px 0;
}

.brand img {
  width: 42px;
  height: auto;
  display: block;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 12px 0 10px;
  border: 1px solid #31425f;
  border-radius: 6px;
  background: #0d1524;
  color: #b7c3d8;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.status-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6a778f;
  flex-shrink: 0;
}

.status-uptime {
  min-width: 7ch;
  text-align: right;
  color: #d5deee;
}

.status-active {
  border-left: 1px solid #31425f;
  margin-left: 2px;
  padding-left: 12px;
  color: #d5deee;
  white-space: nowrap;
  letter-spacing: 0;
}

.status-chip.online {
  border-color: #2f4d3a;
  background: #0d1814;
}

.status-chip.online .status-led {
  background: var(--online);
  box-shadow: 0 0 0 1px rgba(59, 191, 106, 0.25);
  animation: led-breathe 2.4s ease-in-out infinite;
}

.status-chip.offline {
  border-color: #553236;
  background: #180e12;
}

.status-chip.offline .status-led {
  background: var(--offline);
}

.status-chip.checking .status-led {
  background: #7d8da8;
}

@keyframes led-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

main {
  max-width: 1100px;
  margin: auto;
  padding: 40px 24px 56px;
}

h1, h2, .toolbar strong {
  font-family: 'Oswald', 'Arial Narrow', sans-serif;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

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

.games {
  display: grid;
  gap: 28px;
  margin-bottom: 36px;
}

.games[hidden] { display: none !important; }

.live-now-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 16px;
  font-size: 22px;
  color: #ffe3e6;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff3b4a;
  box-shadow: 0 0 0 0 rgba(255, 59, 74, 0.55);
  animation: live-pulse 1.4s ease-out infinite;
}

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 59, 74, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(255, 59, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 59, 74, 0); }
}

.game-day-live {
  padding: 18px;
  border: 1px solid rgba(255, 59, 74, 0.35);
  border-radius: 16px;
  background:
    linear-gradient(160deg, rgba(255, 59, 74, 0.1), transparent 45%),
    #101826;
}

.game-card-live {
  border-color: rgba(255, 59, 74, 0.4);
}

.game-day h2 {
  margin: 0 0 14px;
  font-size: 22px;
  color: #e8eef8;
}

.game-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.game-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #101826;
}

.game-matchup {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

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

.game-side.away {
  justify-content: flex-end;
}

.game-side.home {
  justify-content: flex-start;
}

.game-team {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.game-team img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.game-team span {
  font-size: 13px;
  font-weight: 600;
  color: #d5deee;
}

.game-score {
  font-family: 'Oswald', 'Arial Narrow', sans-serif;
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  color: #f2f5fb;
  min-width: 1.4ch;
  text-align: center;
}

.game-vs {
  font-family: 'Oswald', sans-serif;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: #7f90ab;
}

.game-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}

.game-card .open-game {
  width: 100%;
  background: #182338;
}

.game-card .open-game-watch {
  background: linear-gradient(180deg, #d50a0a, #9e0b0f);
  border-color: transparent;
  color: #fff;
}

.game-card .open-game-view {
  background: transparent;
  border-color: #3b4861;
  color: #9aabc3;
  font-weight: 500;
}

button {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  cursor: pointer;
}

button:hover {
  background: #1a2740;
  border-color: #4d6a9a;
}

button:focus-visible {
  outline: 2px solid rgba(213, 10, 10, 0.7);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.sites button {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 12px;
  min-height: 0;
  background: #101826;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.sites button:hover {
  transform: translateY(-2px);
  border-color: rgba(213, 10, 10, 0.5);
}

.site-thumb {
  aspect-ratio: 16 / 10;
  width: 100%;
  border-radius: 8px;
  object-fit: cover;
  background: #182338;
  display: block;
}

.site-label {
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}

.site-add .site-thumb-add {
  aspect-ratio: 16 / 10;
  width: 100%;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #152033;
  border: 1px dashed #3a4d6d;
  color: #9eb0cc;
  font-size: 36px;
  font-weight: 500;
  line-height: 1;
}

.site-add:hover .site-thumb-add {
  border-color: rgba(213, 10, 10, 0.55);
  color: #d7e2f5;
}

#offline.offline-banner {
  min-height: 0;
  display: block;
  margin-bottom: 22px;
}

#offline[hidden] { display: none !important; }

.offline-card {
  max-width: none;
  text-align: center;
  padding: 28px 22px;
  border: 1px solid rgba(213, 10, 10, 0.35);
  border-radius: 16px;
  background: linear-gradient(160deg, #182338, #101826);
}

.offline-card h1 {
  font-size: clamp(22px, 3vw, 30px);
  letter-spacing: 0.04em;
  margin: 0;
  line-height: 1.2;
}

#session {
  position: relative;
  min-height: calc(100vh - 140px);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  position: relative;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar strong { font-size: 22px; }

.toolbar-title span {
  display: block;
  font-size: 14px;
  color: #a6b6d4;
  margin-top: 7px;
  font-family: 'Barlow', sans-serif;
  text-transform: none;
  letter-spacing: 0;
}

.toolbar-title span[hidden] { display: none !important; }

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #152033;
  border: 1px solid var(--line);
  color: #d7e2f5;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  display: block;
  flex-shrink: 0;
  overflow: visible;
}

.icon-btn:hover {
  background: #1c2b44;
  border-color: #4d6a9a;
}

.icon-btn-danger {
  color: #ffb4bc;
  border-color: #6a3340;
  background: #2a141a;
}

.icon-btn-danger:hover {
  background: #3a1a22;
  border-color: #963e57;
  filter: none;
}

.end-confirm {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 8, 16, 0.72);
  backdrop-filter: blur(4px);
}

.end-confirm[hidden] { display: none !important; }

.end-confirm-card {
  width: min(420px, 100%);
  padding: 28px 24px 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #101928;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  display: grid;
  gap: 14px;
  justify-items: center;
}

.end-confirm-card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: #f2f6fc;
}

.end-confirm-card p {
  margin: 0;
  max-width: 28ch;
  font-size: 15px;
  line-height: 1.45;
  color: var(--muted);
}

.end-confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 6px;
}

.end-confirm-actions .text-btn {
  min-width: 150px;
}

.text-btn-danger {
  background: #6a2230;
  border-color: #963e57;
  color: #ffd5db;
}

.text-btn-danger:hover {
  background: #822a3c;
  border-color: #b34d63;
}

.settings-wrap {
  position: relative;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(280px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0f1728;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  z-index: 20;
  display: grid;
  gap: 10px;
}

.settings-panel[hidden] { display: none !important; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.settings-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.settings-row strong {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 16px;
  color: #e8eef8;
  letter-spacing: 0;
  text-transform: none;
}

.quality-picks {
  display: grid;
  gap: 8px;
}

.quality-picks .quality-auto {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #182338;
  color: #e8eef8;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.quality-manual {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.quality-manual button {
  flex: 1 1 0;
  min-width: 0;
  padding: 5px 6px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #141c2c;
  color: #b7c3d8;
  font-size: 11px;
  font-weight: 600;
}

.quality-picks button.active {
  border-color: rgba(213, 10, 10, 0.7);
  background: rgba(213, 10, 10, 0.22);
  color: #fff;
}

.text-btn {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: #182338;
}

#loading {
  padding: 65px 20px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #111a2a;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid #314363;
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 22px;
  animation: spin 1s linear infinite;
}

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

ol {
  display: flex;
  gap: 20px;
  justify-content: center;
  list-style: none;
  padding: 0;
  counter-reset: stage;
  margin: 35px 0;
}

li {
  font-size: 14px;
  color: #7c8ba4;
  max-width: 145px;
}

li:before {
  counter-increment: stage;
  content: counter(stage);
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border: 1px solid #3b4861;
  border-radius: 50%;
  margin: 0 auto 10px;
}

li.active { color: #ffc9c9; }
li.done { color: #76d6ae; }
li.done:before {
  content: '✓';
  background: #1c3c36;
  border-color: #3d8e70;
}

#viewer {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

#viewer iframe {
  display: block;
  width: 100%;
  height: min(76vh, 850px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #000;
}

#viewer:fullscreen,
#viewer:-webkit-full-screen {
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#viewer:fullscreen iframe,
#viewer:-webkit-full-screen iframe {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
}

/* Portrait fullscreen: lay the 16:9 stream on its side so it fills the phone. */
@media (orientation: portrait) {
  #viewer:fullscreen iframe,
  #viewer:-webkit-full-screen iframe {
    width: 100dvh;
    height: 100dvw;
    max-width: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
  }
}

#error {
  padding: 18px 22px;
  border: 1px solid #963e57;
  background: #351d2b;
  color: #ffbece;
  border-radius: 12px;
  margin-top: 20px;
}

[hidden] { display: none !important; }

body.viewing main {
  max-width: none;
  padding: 20px 24px;
}

@media (max-width: 700px) {
  header {
    height: 64px;
    padding: 0 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .brand img { width: 34px; }
  .sites { grid-template-columns: repeat(2, 1fr); }
  main {
    padding: 20px 12px 28px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }
  .games { gap: 20px; }
  .game-list { grid-template-columns: 1fr; gap: 12px; }
  .game-card { padding: 14px; gap: 12px; }
  .game-team img { width: 44px; height: 44px; }
  .game-score { font-size: 28px; }
  .toolbar {
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
  }
  .toolbar strong { font-size: 16px; }
  .toolbar-title { min-width: 0; flex: 1; }
  .toolbar-title strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .icon-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }
  ol {
    flex-wrap: wrap;
    gap: 12px;
    margin: 20px 0;
  }
  li { max-width: 120px; font-size: 12px; }
  #loading { padding: 36px 14px; }

  #viewer iframe {
    height: auto;
    min-height: 0;
    aspect-ratio: 16 / 9;
    max-height: calc(100dvh - 150px);
  }

  body.viewing header {
    height: 52px;
  }
  body.viewing main {
    padding: 8px 10px 12px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  body.viewing #session {
    min-height: calc(100dvh - 60px);
    display: flex;
    flex-direction: column;
  }
  body.viewing #viewer {
    flex: 1;
    display: flex;
    min-height: 0;
  }
  body.viewing #viewer iframe {
    max-height: none;
    height: 100%;
    aspect-ratio: auto;
    min-height: min(56dvh, calc(100dvw * 9 / 16));
  }

  .status-chip {
    padding: 0 8px 0 8px;
    gap: 6px;
    font-size: 10px;
    min-height: 30px;
  }
  .status-uptime { min-width: 6ch; }
  .status-active { padding-left: 8px; }
}

/* Phone landscape while watching: immersive, almost edge-to-edge. */
@media (max-width: 950px) and (orientation: landscape) {
  body.viewing header {
    display: none;
  }
  body.viewing main {
    padding: 6px 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  body.viewing .toolbar {
    margin-bottom: 6px;
  }
  body.viewing .toolbar strong {
    font-size: 14px;
  }
  body.viewing #session {
    min-height: calc(100dvh - 12px);
  }
  body.viewing #viewer iframe {
    height: calc(100dvh - 58px);
    min-height: 0;
    aspect-ratio: auto;
    border-radius: 6px;
  }
  body.viewing.fs-active .toolbar,
  body.viewing:has(#viewer:fullscreen) .toolbar {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
