/* ===========================================================================
   /watch/<Name> ON A TELEVISION

   The third dress for this page, after player-channel.css (a live match) and
   player-channel-scenes.css (the rest of the evening). This one is not a
   different look -- it is the same page with the website taken off it.

   WHY IT EXISTS. The place this page actually gets watched is a monitor propped
   beside a pool table, ten feet from the people reading it. In a browser window
   that screen spends a third of its height on a logo, a nav bar and a banner,
   none of which anybody standing at a table is going to click, and the picture
   and the score get what is left. Full screen gives the whole screen to the two
   things being watched.

   TWO SWITCHES, ONE CLASS. `html.is-tv` is this layout; the browser's own
   fullscreen is separate and optional. They are driven together by
   js/player-channel/tv-mode.js, but the class stands on its own -- on an iPhone,
   where a document cannot go fullscreen at all, and on ?tv=1, where a bookmarked
   screen comes up chromeless with no gesture to request fullscreen with.

   THE SIZES ARE IN vh, NOT vw. Everything else on this page scales with
   viewport WIDTH, which is the right choice in a window and the wrong one here:
   a 1080p television and a 1080p laptop are the same number of pixels wide and
   about eight feet apart. Height is what actually differs once the browser's own
   chrome is gone, and it is the axis the layout is fighting for -- a 16:9
   picture plus a panel of numbers has to fit between the top and bottom of a
   screen nobody is going to scroll.
   ========================================================================= */

/* ---------------------------------------------------------------------------
   The switch itself
   ---------------------------------------------------------------------------
   In a window: a quiet chip above the stage, right-aligned over the panel it
   belongs to. In full screen: fixed in the corner, and gone within seconds --
   see the idle rules at the bottom of this file. */

.pc-viewer-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}

/* The page renders the bar hidden and tv-mode.js unhides it, and `display:
   flex` above would otherwise beat the browser's own [hidden] rule and leave a
   dead button on the page for anybody without JavaScript. */
.pc-viewer-bar[hidden] {
  display: none;
}

.pc-tv-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;

  margin: 0;
  padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;

  font: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.82);
  background: rgba(8, 13, 20, 0.85);

  cursor: pointer;
  transition:
    color 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease;
}

.pc-tv-toggle:hover,
.pc-tv-toggle:focus-visible {
  color: #fff;
  border-color: rgba(46, 255, 115, 0.55);
  background: rgba(46, 255, 115, 0.12);
}

.pc-tv-toggle-icon {
  display: block;
  width: 15px;
  height: 15px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* One label per state, both in the markup, so the script only ever flips a
   class and there is no second copy of this wording in JavaScript to drift. */
html:not(.is-tv) .pc-tv-toggle-exit,
html.is-tv .pc-tv-toggle-enter {
  display: none;
}

.pc-tv-toggle kbd {
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  font: inherit;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
}

/* The browser cannot put this document in full screen (an iPhone), so the
   button must not promise that it can. The class is still worth having -- it
   still strips the chrome -- and the script says so by way of this attribute. */
.pc-tv-toggle[data-fullscreen="unsupported"] .pc-tv-toggle-icon {
  display: none;
}

/* ---------------------------------------------------------------------------
   Taking the website off
   ---------------------------------------------------------------------------
   Everything #wrapper-index holds except this page: the header, the nav, the
   member/apply banner, the footer, and whatever banner gets added next -- which
   is why this is a negation rather than a list of ids to keep in step. */

html.is-tv #wrapper-index > *:not(.player-channel-page) {
  display: none !important;
}

/* Dark regardless of theme, like the rest of this page: it frames video. */
html.is-tv body {
  background: #04070c;
}

/* What else is on tonight is a page of links. Nobody clicks a television. */
html.is-tv .player-channel-elsewhere {
  display: none;
}

/* ---------------------------------------------------------------------------
   Filling the screen
   ---------------------------------------------------------------------------
   Only where there is a screen to fill. Under 900px the hero is already one
   column and the page is already mostly picture, so full screen there means
   the chrome coming off and nothing else -- forcing a phone's worth of height
   to hold a feed AND a scoreboard would just crop the scoreboard. */

@media (min-width: 901px) {
  html.is-tv {
    /* The margin around the whole picture. Small, and not zero: a screen with
       a bezel wants a little air, and a 16:9 feed in a 16:9 screen with no
       margin at all leaves the scoreboard nowhere to be. The match board
       reads this too, to know how much of the height is its own. */
    --pc-tv-pad: clamp(10px, 1.6vh, 28px);
  }

  html.is-tv,
  html.is-tv body {
    height: 100%;
    /* There is no scrollbar on a television and nobody to drag one. Anything
       that does not fit has to fit some other way -- see the panel below. */
    overflow: hidden;
  }

  html.is-tv .player-channel-page {
    width: 100%;
    max-width: none;
    height: 100dvh;
    margin: 0;
    padding: var(--pc-tv-pad);
    display: flex;
    flex-direction: column;
  }

  /* The root is rewritten wholesale on every state change -- match, idle,
     searching -- so the rule that makes its contents fill the screen has to be
     about whatever is in there, not about one scene. */
  html.is-tv .player-channel-root {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  html.is-tv .player-channel-root > * {
    flex: 1 1 auto;
    min-height: 0;
  }

  /* --- A live match ----------------------------------------------------- */

  /* Sized in player-channel-board.css, which owns every part of the match
     screen and has its own television rules. */

  /* --- An idle scene ---------------------------------------------------- */

  /* The tall minimum exists so the page does not lurch when a match starts.
     In full screen the scene is already exactly as tall as the screen. */
  html.is-tv .pc-scene {
    min-height: 0;
    border-radius: 16px;
  }

  /* 880px of centred text is a reasonable column in a window and a postage
     stamp on a 4K television. */
  html.is-tv .pc-scene-inner {
    max-width: min(1200px, 78vw);
  }

  /* On air with no ranked match on: the scene is wrapped around a feed, so its
     width is governed by the height available, exactly as the match stage is. */
  html.is-tv .pc-scene--channel .pc-scene-inner {
    max-width: min(1600px, calc((100dvh - 14vh) * 16 / 9));
  }
}

/* ---------------------------------------------------------------------------
   The control, once the screen is a television
   ---------------------------------------------------------------------------
   Out of the layout and into the corner, below both cards that can appear over
   the feed -- a message somebody has just typed and "this game cannot be won
   any more" are both more important than the way out of full screen.

   BOTTOM RIGHT. The top of the screen is the scoreboard now -- flags, names
   and scores edge to edge -- and a button parked there covers a player's flag
   for as long as somebody is moving a mouse. The bottom right is the foot of the
   round-by-round card, which holds nothing but the head count. On the idle
   scenes it is empty felt. */

html.is-tv .pc-viewer-bar {
  position: fixed;
  bottom: clamp(10px, 1.6vh, 28px);
  right: clamp(10px, 1.6vh, 28px);
  z-index: 58;
  margin: 0;
  transition:
    opacity 320ms ease,
    visibility 320ms ease;
}

/* Nothing has moved and no key has been pressed for a few seconds, so there is
   nobody at the keyboard and this is a screen on a wall. The button goes, and
   the mouse pointer with it -- an arrow parked in the middle of a stream is the
   single most common thing wrong with a picture on a television.

   Any movement, any key, brings both straight back: see tv-mode.js. */
html.is-tv.is-tv-idle .pc-viewer-bar {
  opacity: 0;
  visibility: hidden;
}

html.is-tv.is-tv-idle,
html.is-tv.is-tv-idle body {
  cursor: none;
}

/* Keyboard focus is somebody at the keyboard, whatever the idle timer thinks.
   On the bar and not on the button: the button cannot bring back a parent that
   has been faded out, and opacity does not inherit the way visibility does. */
html.is-tv.is-tv-idle .pc-viewer-bar:focus-within {
  opacity: 1;
  visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
  html.is-tv .pc-viewer-bar {
    transition: none;
  }
}
