/* The home page: one card per table being played. On a card's top, the table's live broadcast
   (a preview to click) or what it is doing; below, the same match box as the LED screens.
   A clicked broadcast opens in a window over the page; on a phone it plays in its card. */

:root {
  color-scheme: dark;
  --bg: #0a1022;
  --card: #111a33;
  --line: rgba(255, 255, 255, .08);
  --text: #e8ecf6;
  --muted: #94a0bd;
  --yellow: #ffde00;
  --red: #e5262a;
}

* {
  box-sizing: border-box;
}

body.viewing {
  overflow: hidden;
}

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #1c2a55 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}


/* Top: the title, the tournament, 3 cushion or pool */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 8px;
}

.brand h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 750;
  letter-spacing: -.01em;
}

/* The tournament's line keeps its place while the data loads, so nothing moves when it comes */
.brand p {
  min-height: 1.35em;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}

.tabs {
  display: flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .05);
}

.tabs a {
  padding: 8px 20px;
  border-radius: 999px;
  color: #c5cde0;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
}

.tabs a:hover {
  color: #fff;
}

.tabs a.active {
  background: var(--yellow);
  color: #111;
}


/* Cards */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 24px 48px;
}

.cards {
  display: grid;
  /* 2 cards a row, as on the old home page; 1 on phones (below). Rows further apart than
     columns, so a match box is not taken for the broadcast below it. */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 32px 20px;
}

/* A little room between the white frame and what is inside, which is rounded to follow it */
.card {
  overflow: hidden;
  padding: 4px;
  border: 1px solid #fff;
  border-radius: 14px;
  background: var(--card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

.empty {
  padding: 96px 0;
  color: var(--muted);
  font-size: 18px;
  text-align: center;
}


/* The screen on top of a card: the broadcast's preview, or what the table's broadcast is doing */

.screen {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 0;
  padding: 0;
  border: 0;
  background: #060a16;
  color: var(--muted);
  font: inherit;
}

button.screen {
  cursor: pointer;
}

/* A preview shows only once it has turned out to be a real picture (home.js), not YouTube's grey
   stand-in for a broadcast that has none yet; until then the screen is dark with its play button */
.screen img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .25s;
}

.screen img.shown {
  opacity: 1;
}

.screen img[hidden] {
  display: none;
}

/* Darkens the preview's lower part. Not over a player playing in the card (phones): it would
   take the taps meant for YouTube's own buttons (pause, full screen). */
.screen.live:not(.inline)::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, .45), transparent 45%);
}

.screen .table {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .06em;
}

.badge i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.6s ease-in-out infinite;
}

.screen .badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
}

.screen .play {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 64px;
  height: 64px;
  margin: auto;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  transition: transform .15s, background .15s;
}

.screen .play::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 54%;
  border-style: solid;
  border-width: 11px 0 11px 18px;
  border-color: transparent transparent transparent #fff;
  transform: translate(-50%, -50%);
}

button.screen:hover .play,
button.screen:focus-visible .play {
  background: var(--red);
  transform: scale(1.08);
}

button.screen:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: -3px;
}

.screen .state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.screen .state b {
  color: #aab4cc;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .02em;
}

.screen .state svg {
  width: 36px;
  height: 36px;
  opacity: .55;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, .15);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}


/* The shared match box, sized by its own width (on the LED, a box in the 3×3 grid is 32.53vw wide) */

.board-box {
  container-type: inline-size;
  aspect-ratio: 1.9336;
  overflow: hidden;
  border-radius: 0 0 10px 10px;
}

.screen-box {
  overflow: hidden;
  border-radius: 10px 10px 0 0;
}

.board-box .board {
  --u: calc(100cqw / 32.53);
}


/* Watching a broadcast: a window over the page (on a phone it plays in its card) */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 3vw 3vh;
  background: rgba(4, 7, 16, .88);
  backdrop-filter: blur(4px);
}

.viewer[hidden] {
  display: none;
}

.viewer-dialog {
  --side: 320px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side);
  /* The video and its caption fit the screen's height; the summary column takes --side beside them */
  width: min(1560px, 100%, calc((100vh - 60px - 3vh - 44px) * 16 / 9 + var(--side)));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #000;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}

.viewer-main {
  min-width: 0;
}


/* The summary beside the video: as tall as the video and its caption, scrolling inside */

.viewer-side {
  position: relative;
  border-left: 1px solid var(--line);
  background: #0c1430;
}

.viewer-list {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 8px;
}

.mini {
  display: block;
  width: 100%;
  margin: 0 0 6px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, .035);
  color: var(--text);
  font: inherit;
  text-align: left;
}

button.mini {
  cursor: pointer;
}

button.mini:hover,
button.mini:focus-visible {
  border-color: rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .07);
  outline: none;
}

.mini.now {
  border-color: var(--red);
  background: rgba(229, 38, 42, .1);
}

.mini-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 18px;
  margin-bottom: 6px;
}

.mini-table {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* Every state takes the same box, so rows keep their height when the state changes */
.mini .tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 18px;
  padding: 0 7px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.mini .tag.live {
  background: var(--red);
  color: #fff;
}

.mini .tag.live i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.6s ease-in-out infinite;
}

.mini .tag.now {
  color: var(--yellow);
}

.mini-player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
}

.mini-player span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-player b {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.mini-player.p2 {
  color: var(--yellow);
}

/* The player to shoot */
.mini-player.shooter span::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 7px 1px 0;
  border-radius: 50%;
  background: currentColor;
}

.mini-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1100px) {
  /* Too narrow for the summary: the window shows the video alone */
  .viewer-dialog {
    --side: 0px;
    grid-template-columns: minmax(0, 1fr);
  }

  .viewer-side {
    display: none;
  }
}

.viewer-video {
  aspect-ratio: 16 / 9;
  background: #000;
}

.viewer-video iframe,
.screen.inline iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.viewer-caption {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 14px;
  background: var(--card);
  font-size: 15px;
}

.viewer-close {
  position: fixed;
  top: 12px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.viewer-close:hover {
  background: rgba(255, 255, 255, .22);
}


/* The card whose broadcast is being watched */

/* Red, and a second line drawn as a shadow so the frame is thicker without moving the card */
.card.playing {
  border-color: var(--red);
  box-shadow: 0 0 0 1px var(--red), 0 10px 30px rgba(0, 0, 0, .35);
}

.screen .now {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: fit-content;
  height: fit-content;
  margin: auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--yellow);
  color: #111;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}


@keyframes pulse {
  50% { opacity: .3; }
}

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

@media (max-width: 600px) {
  .top {
    padding: 20px 16px 4px;
  }

  .brand h1 {
    font-size: 22px;
  }

  /* 3 cushion / pool always on a row of its own under the title: beside it while the
     tournament's name loads, it jumped down when the name came */
  .brand {
    flex: 1 0 100%;
  }

  main {
    padding: 12px 16px 32px;
  }

  .cards {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
  }

  /* One card per row: without a broadcast to watch, the screen is a thin bar */
  .screen:not(.live) {
    aspect-ratio: auto;
    height: 52px;
  }

  .screen:not(.live) .table {
    top: 50%;
    transform: translateY(-50%);
  }

  .screen .state {
    flex-direction: row;
    gap: 8px;
  }

  .screen:not(.live) .state svg {
    width: 22px;
    height: 22px;
  }

  .screen:not(.live) .spinner {
    width: 18px;
    height: 18px;
    border-width: 2px;
  }
}
