/* A build plan on drafting paper: Nix blue ink and grid, one typeface,
   square corners, hairlines, and red only for what failed. */

@font-face {
  font-family: "Plex Mono";
  font-weight: 400;
  font-display: swap;
  src: url(/vendor/ibm-plex-mono-latin-400-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Plex Mono";
  font-weight: 600;
  font-display: swap;
  src: url(/vendor/ibm-plex-mono-latin-600-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Plex Mono";
  font-weight: 400;
  font-display: swap;
  src: url(/vendor/ibm-plex-mono-latin-ext-400-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
    U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Plex Mono";
  font-weight: 600;
  font-display: swap;
  src: url(/vendor/ibm-plex-mono-latin-ext-600-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
    U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --paper: #f2efe6;
  --sheet: #fbfaf6;
  --ink: #1c2742;
  --ink-soft: #5b6680;
  --rule: rgb(28 39 66 / 0.18);
  --nix-dark: #5277c3;
  --nix-light: #7ebae4;
  --red: #c4402b;
  --line: 1.5px;
  font-family: "Plex Mono", ui-monospace, Menlo, Consolas, "DejaVu Sans Mono", monospace;
  /* Everything is sized in rem, so this scales the whole page: 16px on
     phones, growing with the smaller of width and height on big screens
     (about 25px on a 1920x1080 display) so a question always fits. */
  font-size: clamp(16px, min(1.5vw, 2.3vh), 30px);
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

/* Graph paper: a 4 mm grid with a heavier line every 5 squares. */
body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgb(82 119 195 / 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgb(82 119 195 / 0.16) 1px, transparent 1px),
    linear-gradient(rgb(82 119 195 / 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgb(82 119 195 / 0.07) 1px, transparent 1px);
  background-size: 80px 80px, 80px 80px, 16px 16px, 16px 16px;
  background-position: -1px -1px;
}

::selection {
  background: var(--nix-light);
}

.view {
  min-height: 100dvh;
  max-width: 46rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 2px solid var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.snowflake {
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
}

h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
}

#me {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.8rem;
  line-height: 1.3;
  text-align: right;
}

#name {
  font-weight: 600;
}

#standing {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* The clock is a ruler that runs out. */
#timer {
  position: relative;
  height: 0.875rem;
  margin: 0 1rem;
  border-right: 1px solid var(--ink);
  background:
    repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 5%) bottom / 100% 0.3rem
      no-repeat,
    repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 25%) bottom / 100%
      0.625rem no-repeat;
}

#bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 0.3rem;
  width: 0;
  background: var(--nix-dark);
  transition: width 0.2s linear;
}

#bar.hurry {
  background: var(--red);
}

main {
  flex: 1;
  padding: 1.5rem 1rem 1rem;
}

.label {
  margin: 0;
  color: var(--nix-dark);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.question {
  margin: 0.4rem 0 1.4rem;
  font-size: clamp(1.2rem, 4.6vw, 1.6rem);
  font-weight: 600;
  line-height: 1.3;
  text-wrap: balance;
}

.choices {
  display: grid;
  gap: 0.6rem;
  /* Also the answer form's fieldset. */
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

@media (min-width: 40rem) {
  .choices {
    grid-template-columns: 1fr 1fr;
  }
}

.choice {
  position: relative;
  display: flex;
  align-items: stretch;
  min-height: 3.4rem;
  border: var(--line) solid var(--ink);
  background: var(--sheet);
  color: var(--ink);
  font-size: 1rem;
  overflow: hidden;
}

.letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.6rem;
  border-right: var(--line) solid currentColor;
  font-weight: 600;
  z-index: 1;
}

.text {
  flex: 1;
  align-self: center;
  padding: 0.65rem 0.85rem;
  z-index: 1;
}

label.choice {
  cursor: pointer;
}

/* The radio stays in the page for keyboards and screen readers; the label is
   what you see and tap. */
label.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

label.choice:hover {
  background: #fff;
}

label.choice:active {
  translate: 1px 1px;
}

label.choice:has(:focus-visible) {
  outline: 2px dashed var(--nix-dark);
  outline-offset: 3px;
}

label.choice:has(:checked) {
  border-color: var(--nix-dark);
  background: var(--nix-dark);
  color: #fff;
}

.choices:has(:checked) label.choice:not(:has(:checked)) {
  color: var(--ink-soft);
  border-color: var(--ink-soft);
}

.choices:disabled label.choice {
  cursor: default;
  translate: none;
}

.choices:disabled label.choice:not(:has(:checked)) {
  opacity: 0.45;
}

/* One status line; which sentence shows depends on the form's state. */
.status {
  margin: 1rem 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

#answer .picked,
#answer .expired,
#answer:has(:checked) .unpicked,
#answer:has(:disabled) .unpicked,
#answer:has(:disabled) .picked,
.status:has(.notice:not(:empty)) > :not(.notice) {
  display: none;
}

#answer:has(:checked) .picked,
#answer:has(:disabled) .expired {
  display: inline;
}

#answer:has(:disabled):has(:checked) .expired::after {
  content: ", your answer is locked in";
}

.notice {
  color: var(--red);
}

.countdown {
  margin: 1rem 0 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.countdown.big {
  margin-top: 0.25rem;
  color: var(--ink);
  font-size: 2.6rem;
  font-weight: 600;
  line-height: 1;
  text-align: right;
}

/* Reveal. */
.result {
  display: flex;
  flex-direction: column;
  margin: 0 0 1.1rem;
}

.headline {
  font-size: 2.2rem;
  font-weight: 600;
  line-height: 1.1;
}

.log {
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.result.good .headline {
  color: var(--nix-dark);
}

.result.bad .headline {
  color: var(--red);
}

.result.bad .log {
  color: var(--red);
}

.result.none .headline {
  color: var(--ink-soft);
}

.revealed {
  color: var(--ink-soft);
  border-color: var(--rule);
}

.revealed.correct {
  color: var(--ink);
  border-color: var(--ink);
  background: var(--nix-light);
}

.revealed.wrong {
  color: var(--red);
  border-color: var(--red);
}

.revealed.wrong .text {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.count {
  align-self: center;
  padding: 0 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  z-index: 1;
}

/* How many players picked this choice, hatched behind the row. */
.share {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  appearance: none;
  border: 0;
  background: transparent;
}

.share::-webkit-progress-bar {
  background: transparent;
}

.share::-webkit-progress-value {
  background: repeating-linear-gradient(
    -45deg,
    rgb(82 119 195 / 0.16) 0 2px,
    transparent 2px 7px
  );
}

.share::-moz-progress-bar {
  background: repeating-linear-gradient(
    -45deg,
    rgb(82 119 195 / 0.16) 0 2px,
    transparent 2px 7px
  );
}

.explanation {
  margin: 1.25rem 0 0;
  padding: 0.8rem 0.95rem;
  border: var(--line) dashed var(--nix-dark);
  background: var(--sheet);
  font-size: 0.92rem;
}

.explanation::before {
  content: "# ";
  color: var(--nix-dark);
  font-weight: 600;
}

/* Leaderboard. */
.leaderboard {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 2px solid var(--ink);
}

.leaderboard li {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--sheet);
}

.leaderboard li:first-child {
  font-size: 1.15rem;
  font-weight: 600;
}

.leaderboard li.me {
  background: var(--nix-light);
}

.rank {
  width: 2.6rem;
  color: var(--nix-dark);
  font-weight: 600;
}

.leaderboard li.me .rank {
  color: var(--ink);
}

/* Dot leaders between name and score, like a table of contents. */
.who {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
}

.who::after {
  content: "";
  flex: 1;
  border-bottom: 2px dotted var(--ink-soft);
}

.points {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

footer {
  display: flex;
  justify-content: space-between;
  margin: 0 1rem;
  padding: 0.6rem 0 0.9rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  font-size: 0.78rem;
}

#connection {
  position: fixed;
  right: 1rem;
  bottom: 0.9rem;
  margin: 0;
  color: var(--red);
  font-size: 0.78rem;
}

/* Spectator screen for the livestream: fills a 16:9 frame at any resolution,
   so everything is sized from the viewport. 1920x1080 gives 24px. */
html:has(body.spectate) {
  font-size: min(1.25vw, 2.2222vh);
  overflow: hidden;
}

.stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 9.5rem;
  height: 100vh;
}

.spectate #game {
  min-width: 0;
  min-height: 0;
}

.spectate .view {
  height: 100%;
  min-height: 0;
  max-width: none;
}

.spectate header {
  padding: 1.1rem 2rem 0.9rem;
}

.spectate .snowflake {
  width: 2.6rem;
  height: 2.6rem;
}

.spectate h1 {
  font-size: 1.4rem;
}

#tally {
  font-size: 1.1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.spectate #timer {
  height: 1.1rem;
  margin: 0 2rem;
}

.spectate #bar {
  height: 0.45rem;
}

.spectate main {
  display: flex;
  flex-direction: column;
  padding: 1.6rem 2rem 1.2rem;
  overflow: hidden;
}

.spectate .label {
  font-size: 0.9rem;
}

.spectate .question {
  margin: 0.4rem 0 1.4rem;
  font-size: 2.3rem;
}

.spectate .choices {
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

.spectate .choice {
  min-height: 4.2rem;
  font-size: 1.35rem;
  border-width: 2px;
}

.spectate .letter {
  width: 3.4rem;
  border-right-width: 2px;
}

.spectate .countdown {
  margin-top: auto;
  font-size: 1.1rem;
}

.spectate .countdown.big {
  font-size: 4.5rem;
}

.spectate .explanation {
  margin-top: 1.2rem;
  font-size: 1.25rem;
}

/* Top ten in two columns of five, filled downwards, so it fits above the
   join strip. */
.spectate .leaderboard {
  display: grid;
  grid-template-rows: repeat(5, auto);
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  column-gap: 2rem;
  align-content: start;
}

.spectate .leaderboard li {
  padding: 0.45rem 0.6rem;
  font-size: 1.3rem;
}

.spectate .leaderboard li:first-child {
  font-size: 1.6rem;
}

/* The join strip along the bottom: code, address, and how to play. */
.join {
  display: flex;
  align-items: center;
  gap: 1.6rem;
  padding: 0.8rem 2rem;
  border-top: 2px solid var(--ink);
  background: var(--sheet);
}

.join p {
  margin: 0;
}

.join .how {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.join .url {
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.1;
}

.join .hint {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.steps {
  margin: 0 0 0 auto;
  padding: 0 0 0 1.6rem;
  border-left: 1px solid var(--rule);
  list-style: none;
  counter-reset: step;
  font-size: 1rem;
  line-height: 1.7;
}

.steps li {
  counter-increment: step;
}

.steps li::before {
  content: counter(step) ". ";
  color: var(--nix-dark);
  font-weight: 600;
}

.qr {
  flex: none;
  height: 100%;
  width: auto;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
}

.qr rect {
  fill: #fff;
}

.qr path {
  fill: var(--ink);
}
