@font-face {
  font-family: "League Gothic";
  font-weight: 400;
  font-display: swap;
  src: url(fonts/league-gothic-latin.woff2) format("woff2");
}

/* The dojo's brush: Yuji Syuku, cut down to the hiragana of the phase
   words れい, はじめ and まて. A TV's browser may have no Japanese font of its own.
   It stands in wherever League Gothic has no glyph. */
@font-face {
  font-family: "Ippon Brush";
  font-weight: 400;
  font-display: swap;
  src: url(fonts/yuji-syuku-ippon.woff2) format("woff2");
  unicode-range: U+306F, U+3058, U+3081, U+307E, U+3066, U+308C, U+3044;
}

@font-face {
  font-family: "Familjen Grotesk";
  font-weight: 400 700;
  font-display: swap;
  src: url(fonts/familjen-grotesk-latin.woff2) format("woff2");
}

:root {
  --black: #0a0a0a;
  --panel: #222;
  --white: #fff;
  --red: #ed1c24; /* the ring of the dojo's logo */
  --mute: #a6a6a6; /* secondary text on black */
  --display: "League Gothic", "Ippon Brush", "Arial Narrow", Impact, sans-serif;
  --body: "Familjen Grotesk", system-ui, sans-serif;
}

/* One cell per digit, all the same width (digits.js): League Gothic has no
   tabular figures. */
.d {
  display: inline-block;
  min-width: .38em; /* League Gothic's widest digit; a fallback face's wider digits push it out */
  text-align: center;
}

/* Phone remote */

/* The remote fits the screen, so a drag should not rubber-band the page. */
html:has(> body.remote) {
  overscroll-behavior: none;
}

.remote {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-block-size: 100dvh; /* fill the phone: the spare height goes between the groups (below) */
  margin: 0 auto;
  max-inline-size: 30rem;
  /* Sized so an iPhone Pro in portrait shows it all without scrolling, with
     Safari's bars showing (about 393 by 659 points). */
  padding: .625rem 1rem max(.75rem, env(safe-area-inset-bottom));
  background: var(--black);
  color: var(--white);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.3;
}

/* On a taller phone the groups spread out and START sits by the thumb: each
   heading and the action row take an equal share of the spare height above
   them. On a short phone there is none and the layout is as tight as before. */
.remote main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Remote type roles, display face unless noted:
   clock 5rem · action 1.75rem · value 1.5rem · phase 1.5rem ·
   control 1.375rem · heading and round 1.125rem · label 1rem body 600 · note .875rem body 500 */

.remote ::selection {
  background: var(--red);
  color: var(--white);
}

.remote h1,
.remote h2,
.remote button,
.remote input,
.remote .status {
  font-family: var(--display);
  font-weight: 400; /* League Gothic has one weight */
  letter-spacing: .04em;
}

.remote header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-block-end: .5rem;
}

/* The logo is black lettering round a red ring: it needs a white ground. */
.remote header .mark {
  display: block;
  box-sizing: border-box;
  inline-size: 2.75rem;
  block-size: 2.75rem;
  padding: 3px;
  border-radius: 50%;
  background: var(--white);
  object-fit: contain;
}

.remote h1 {
  margin: 0;
  font-size: 1.5rem;
}

/* One short row: round and phase stacked on the left, the clock on the
   right, the bar under both. Kept low so the whole remote fits a phone. */
.remote .status {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: .75rem;
  padding: .5rem .875rem .625rem;
  border: 2px solid var(--panel);
  background: var(--panel);
  color: var(--white);
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

.remote[data-phase="ready"] .status { background: var(--white); border-color: var(--white); color: var(--red); }
.remote[data-phase="work"] .status { background: var(--black); border-color: var(--panel); color: var(--white); }
.remote[data-phase="rest"] .status { background: var(--red); border-color: var(--red); color: var(--white); }
.remote[data-phase="done"] .status { background: var(--black); color: var(--white); }

.remote .status-top {
  display: flex;
  flex-direction: column;
  gap: .125rem;
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.1;
}

/* A brushed call fills more of its line than League Gothic's capitals. */
.remote #phase:lang(ja) {
  font-size: 1.625rem;
  letter-spacing: .02em;
}

/* The phase word leads and the round is secondary, as on the TV. */
.remote #label {
  font-size: 1.125rem;
  letter-spacing: .07em; /* small condensed capitals need the air */
  opacity: .8;
}

.remote .clock {
  margin: 0;
  text-align: end;
  font-size: min(20vw, 5rem); /* 20:00 is 1.7em wide in League Gothic */
  font-size: min(22vw, 12dvh, 6rem); /* larger where the phone is tall enough to spare it */
  line-height: .9;
  letter-spacing: 0; /* tracking that suits labels spreads big digits apart */
}

.remote .track {
  position: relative;
  grid-column: 1 / -1;
  margin-block-start: .5rem;
  block-size: 8px;
}

.remote .track i {
  position: relative;
  display: block;
  block-size: 100%;
  inline-size: 0;
  background: currentColor;
}

.remote button {
  min-block-size: 44px;
  min-inline-size: 44px;
  border: 0;
  background: var(--panel);
  color: var(--white);
  font-size: 1.375rem; /* League Gothic is narrow: it needs the height */
  cursor: pointer;
  touch-action: manipulation; /* no double-tap-zoom wait before a tap counts */
  transition: transform .12s cubic-bezier(.23, 1, .32, 1);
}

/* A press is felt at once: the button gives a little under the thumb. */
.remote button:active:not(:disabled) {
  filter: brightness(1.25);
  transform: scale(.97);
}

@media (prefers-reduced-motion: reduce) {
  .remote button:active:not(:disabled) {
    transform: none;
  }
}

@media (hover: hover) {
  .remote button:hover:not(:disabled) {
    filter: brightness(1.15);
  }
}

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

.remote button:disabled {
  opacity: .35;
  cursor: default;
}

.remote button[aria-pressed="true"] {
  background: var(--white);
  color: var(--black);
}

/* Locked mid-session, the chosen program is still information: keep it
   readable while the controls around it fade. */
.remote button[aria-pressed="true"]:disabled {
  opacity: .6;
}

.remote .acts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: .625rem;
  margin-block-start: auto; /* a share of the spare height: toward the thumb on a tall phone */
  padding-block-start: .875rem;
}

.remote .go,
.remote .reset {
  min-block-size: 54px;
  min-block-size: max(54px, 8dvh); /* a bigger target where there is room */
  font-size: 1.75rem;
}

.remote .go {
  background: var(--red);
  color: var(--white);
}

.remote .reset {
  border: 2px solid var(--mute);
}

.remote h2 {
  margin: auto 0 .25rem; /* a share of the spare height above each group */
  padding-block-start: .625rem;
  font-size: 1.125rem;
  letter-spacing: .06em;
  color: var(--mute);
}

.remote .note {
  display: none;
  margin-inline-start: .375rem;
  font-family: var(--body);
  font-weight: 500;
  font-size: .875rem;
  letter-spacing: .01em;
  color: var(--white);
}

.remote:is([data-status="running"], [data-status="paused"], [data-status="done"]) .note {
  display: inline;
}

.remote .chips {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.remote .chips.three {
  grid-template-columns: repeat(3, 1fr);
}

.remote .chip {
  min-block-size: 44px;
  padding-inline: 0; /* "3 min" stays on one line on a 320px phone */
}

.remote .step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.remote .step span {
  flex: 1;
  font-weight: 600; /* light text on black reads thin at 400 */
  letter-spacing: .01em;
}

.remote .step button {
  inline-size: 48px;
  /* held to repeat: no text selection, callout or double-tap zoom */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Drawn, so minus and plus match: League Gothic's are small and uneven. */
.remote .step svg {
  display: block;
  inline-size: 1.25rem;
  block-size: 1.25rem;
  margin: auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
}

.remote .step input {
  inline-size: 76px;
  min-block-size: 44px;
  padding: 0;
  border: 0;
  border-block-end: 2px solid var(--mute);
  border-radius: 0;
  background: none;
  color: var(--white);
  text-align: center;
  font-size: 1.5rem; /* 16px or more, or iOS zooms the page on focus */
  caret-color: var(--red);
}

.remote .step input::placeholder {
  color: var(--mute);
}

.remote .step input:focus-visible {
  outline: 3px solid var(--white);
  outline-offset: 3px;
}

.remote .step input:disabled {
  opacity: .7;
  border-color: transparent;
}

/* Paused goes to the black ground, where a dimmed clock still reads. */
.remote[data-status="paused"] .status { background: var(--black); border-color: var(--panel); color: var(--white); }
.remote[data-status="paused"] .clock { opacity: .45; }
.remote[data-final] .status { background: var(--black); border-color: var(--panel); }
.remote[data-final] .clock { color: var(--red); }

/* Done: the main button already resets, so it takes the whole row. */
.remote[data-status="done"] .acts { grid-template-columns: 1fr; }
.remote[data-status="done"] .reset { display: none; }

.remote .full {
  margin: 3rem 0;
  font-size: 1.25rem;
  line-height: 1.35;
  text-align: center;
  text-wrap: balance;
}

.remote .full p {
  margin: 0 0 .5rem;
}

.remote .full .note-full {
  margin-block-end: 1.5rem;
  font-size: 1rem;
  color: var(--mute);
}

.remote .full .go {
  inline-size: 100%;
}

/* TV page: sized for a 16:9 screen in vw/vh, with a 5% safe margin for
   overscan. Plain properties only: the TV's browser may be old. */

.tv {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  background: var(--black);
  color: var(--white);
  font-family: var(--display);
  font-weight: 400; /* League Gothic has one weight */
  line-height: 1;
}

/* The brand column is white: the logo is black lettering round a red ring,
   and is shown as the dojo drew it. */
.tv .brand {
  position: relative;
  width: 34%;
  box-sizing: border-box;
  /* The foot is kept for the time of day, so the logo centres in the space
     above it. */
  padding: 5vh 2.5vw calc(8vh + 4.4vw) 3vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--white);
  color: var(--black);
  border-right: .5vw solid var(--red);
}

/* The seal holds the logo and the stroke that makes its ring wrap round. */
.tv .seal {
  position: relative;
  width: 100%;
  max-width: 50vh; /* leaves the maxims their room on a short screen */
}

.tv .seal .mark {
  display: block;
  width: 100%;
  height: auto;
}

/* White covers lying exactly on the red parts of the logo's i (measured
   from the image, in tv.html): its ring, its stem and its dot. At rest they
   are hidden. To write the i, they cover it and are then drawn away in the
   order a pen would go: the dot, down the stem, then round the ring
   clockwise (up and over the top). The ring starts just below the stem, so
   the whole joint appears at once and the ring closes underneath it. */
.tv .seal .wrap {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

.tv .seal .wrap * {
  fill: none;
  stroke: var(--white);
  visibility: hidden;
}

.tv .seal .w-ring {
  stroke-width: 99;
  stroke-dasharray: 2768 2768; /* the ring's length */
  stroke-dashoffset: 2768;
}

.tv .seal .w-stem {
  stroke-width: 90;
  stroke-dasharray: 165 165; /* the stem's length */
  stroke-dashoffset: 165;
}

.tv .seal .wrap .w-dot {
  fill: var(--white);
  stroke: none;
}

/* Kano's two maxims, as they hang on a dojo's front wall: seiryoku zen'yo
   (best use of energy) and jita kyoei (mutual welfare and benefit), in two
   columns read from the right. Each character is stroke data (maxim.html),
   so it can be drawn stroke by stroke. */
.tv .maxim {
  display: flex;
  flex-direction: row-reverse;
  margin: 3.5vh 0 0;
  font-size: 2.6vw;
}

.tv .maxim p {
  display: flex;
  flex-direction: column;
  margin: 0 .2em;
}

.tv .maxim svg {
  display: block;
  width: 1em;
  height: 1em;
  margin: .06em 0;
}

.tv .maxim .f {
  fill: var(--black);
  /* a little weight, so the brushwork holds beside the logo's heavy lettering */
  stroke: var(--black);
  stroke-width: 12;
  stroke-linejoin: round;
}

/* The brush: a fat line down the middle of a stroke, seen only through that
   stroke's outline. */
.tv .maxim .s {
  fill: none;
  stroke: var(--black);
  stroke-width: 128;
  stroke-linecap: round;
  stroke-dasharray: 3337 3337;
  stroke-dashoffset: 0;
}

/* The brand's motion. The red i of the logo is written (the dot, the stem,
   then round the ring) and the maxims are then written stroke by stroke in
   their proper order. brand.js plays it on load, as each round starts, and
   again every 16 s, in a round as well as while the timer waits. Without any
   of it, or for a less-motion viewer, the logo and the maxims simply show. */
@media (prefers-reduced-motion: no-preference) {
  .tv [data-brand].in .w-dot {
    animation: dot-land .2s ease-out .15s backwards;
  }

  .tv [data-brand].in .w-stem {
    animation: stem-wrap .25s cubic-bezier(.4, 0, .6, 1) .35s backwards;
  }

  .tv [data-brand].in .w-ring {
    animation: ring-wrap 1.2s cubic-bezier(.4, 0, .25, 1) .58s backwards;
  }

  /* Longhands, not the shorthand: the shorthand would reset each stroke's
     delay, which is its turn (set inline in maxim.html). */
  .tv [data-brand].in .maxim .s {
    animation-name: stroke;
    animation-duration: .42s;
    animation-timing-function: cubic-bezier(.3, .1, .3, 1);
    animation-fill-mode: backwards;
  }

  /* A stroke's outline is filled in only once its brush has passed. */
  .tv [data-brand].in .maxim .f {
    animation-name: ink;
    animation-duration: .42s;
    animation-timing-function: step-end;
    animation-fill-mode: backwards;
  }
}

@keyframes ring-wrap {
  0% { visibility: visible; stroke-dashoffset: 0; }
  99% { visibility: visible; }
  100% { visibility: hidden; stroke-dashoffset: 2768; }
}

@keyframes stem-wrap {
  0% { visibility: visible; stroke-dashoffset: 0; }
  99% { visibility: visible; }
  100% { visibility: hidden; stroke-dashoffset: 165; }
}

@keyframes dot-land {
  0% { visibility: visible; opacity: 1; }
  99% { visibility: visible; }
  100% { visibility: hidden; opacity: 0; }
}

@keyframes stroke {
  0% { stroke-dashoffset: 3339; }
  100% { stroke-dashoffset: 0; }
}

@keyframes ink {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Time of day, at the foot of the brand column. */
.tv .now {
  position: absolute;
  bottom: 5vh;
  left: 3vw; /* the column's padding, so it centres under the logo */
  right: 2.5vw;
  margin: 0;
  font-size: 4.4vw; /* the widest time, 12:00:00 PM, still fits the column */
  letter-spacing: .03em;
  text-align: center;
  opacity: .8;
}

.tv .side {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 5vh 5vw calc(5vh + 4vw) 4vw;
  /* Black is the round being fought (and the idle screen), red is rest,
     white is get ready. */
  background: var(--black);
  color: var(--white);
}

.tv[data-phase="ready"] .side { background: var(--white); color: var(--red); }
.tv[data-phase="work"] .side { background: var(--black); color: var(--white); }
.tv[data-phase="rest"] .side { background: var(--red); color: var(--white); }
.tv[data-phase="done"] .side { background: var(--black); color: var(--white); }

/* The phase word is what the room reads from the mat; the round is secondary. */
.tv .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0;
  font-size: 7vw;
  letter-spacing: .03em;
}

/* League Gothic is tightly spaced for headlines; the smaller lines are read
   from across the mat, so they get more tracking. */
.tv #label {
  font-size: 4.2vw;
  letter-spacing: .06em;
  opacity: .8;
}

/* The referee's calls, brushed: sized so the kana stand as tall as the
   capitals beside them and stay clear of the clock. */
.tv #phase:lang(ja) {
  font-size: 6.8vw;
  letter-spacing: .02em;
  margin-right: -.02em; /* tracking adds a gap after the last kana: keep the right edge */
}

/* Idle has no phase word. An empty one still holds its line, so the round
   label and the clock sit where they do mid-round. */
.tv #phase:empty::before {
  content: "\00a0";
}

.tv .clock {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0; /* the digits' line box is taller than the room: let it overhang, centred */
  margin: 0;
  /* The room for the clock is the screen less the lines above and below it,
     about 73vh - 11vw; the digits' ink is 0.74em tall. Sized from that room,
     the clock never touches its neighbours, whatever the screen's shape. */
  font-size: 28vw;
  font-size: min(30vw, calc((73vh - 11vw) * 1.12));
}

/* During a session the clock is what the room reads, so the brand column
   narrows to give it the width: 20:00 is about 1.7em wide, and the side's
   content is now 71vw. Idle keeps the full column for the logo. */
.tv:not([data-phase=""]) .brand {
  width: 24%;
  padding-right: 2vw;
  padding-bottom: calc(8vh + 3vw);
}

.tv:not([data-phase=""]) .maxim {
  margin-top: 2.5vh;
  font-size: 2.1vw;
}

.tv:not([data-phase=""]) .now {
  right: 2vw;
  font-size: 3vw;
}

.tv:not([data-phase=""]) .clock {
  font-size: 33vw;
  font-size: min(36vw, calc((73vh - 11vw) * 1.12));
}

.tv .bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 4vw; /* the smallest text on screen: about 2 cm tall on a 32-inch TV */
  letter-spacing: .06em;
  text-transform: uppercase;
}

.tv .qr {
  display: block;
  height: 17vh;
}

/* A QR code is squares: scaled up, they must stay sharp to scan. */
.tv .qr,
.tv .welcome img {
  image-rendering: pixelated;
}

.tv .track {
  position: absolute;
  left: 4vw;
  right: 5vw;
  bottom: 5vh;
  height: 2.2vw;
}

.tv .track i {
  position: relative;
  display: block;
  height: 100%;
  width: 0;
  background: currentColor;
}

/* The empty track is the text colour, faint: grey on black, pink on red and
   on red-on-white, never a muddy grey over red. */
.tv .track::before,
.remote .track::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: currentColor;
  opacity: .25;
}

/* Paused: the screen is on the black ground and the clock dims, so the room
   sees it stopped without reading. Dimmed digits on red or white would be
   too faint. */
.tv[data-status="paused"] .side { background: var(--black); color: var(--white); }
.tv[data-status="paused"] .clock { opacity: .45; }
/* In the last ten seconds of a round the clock turns red on the black. */
.tv[data-final] .side { background: var(--black); }
.tv[data-final] .clock { color: var(--red); }

/* Before a phone has scanned in, the clock side is only the QR code. */
.tv .welcome {
  display: none;
}

.tv[data-welcome] .side {
  padding-bottom: 5vh; /* no progress bar to clear */
  background: var(--black);
  color: var(--white);
}

.tv[data-welcome] .welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* As large as the screen allows: on a 43-inch TV about 38 cm across, to scan
   from 10 to 15 feet away. */
.tv[data-welcome] .welcome img {
  width: 72vh;
  height: 72vh;
}

.tv[data-welcome] .welcome p {
  margin: 3vh 0 0;
  font-size: 4.5vw;
  letter-spacing: .06em;
}

.tv[data-welcome] .top,
.tv[data-welcome] .clock,
.tv[data-welcome] .bottom,
.tv[data-welcome] .track {
  display: none;
}
