/* Doom's fire and pixels on LavinMQ's dark, topographic site. Fire marks
   what starts the game, green what's live on the broker. */

@font-face {
  font-family: "Jersey 10";
  src: url("fonts/jersey-10.woff2") format("woff2");
  font-display: swap;
}

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

:root {
  color-scheme: dark;
  --night: #141414;
  --ash: #1b1b1b;
  --rim: #2b2b2b;
  --bone: #f7f5f2;
  --dust: #d9d6ce;
  --smoke: #95928c;
  --fire: #ff7a1a;
  --flame: #ffa24d;
  --signal: #44fc70;
  --pixel: "Jersey 10", ui-monospace, monospace;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --gutter: clamp(20px, 4vw, 40px);
  font: 17px/1.55 "Familjen Grotesk", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--night);
  color: var(--dust);
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--flame);
  outline-offset: 3px;
}

code {
  font: 0.8rem/1.4 var(--mono);
}

/* Header */

.bar {
  display: flex;
  align-items: center;
  gap: 12px 28px;
  flex-wrap: wrap;
  padding: 18px var(--gutter);
}

.brand {
  font: 34px/1 var(--pixel);
  color: var(--bone);
  text-decoration: none;
}

.broker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--smoke);
  font-size: 15px;
  text-decoration: none;
}

.broker:hover {
  color: var(--bone);
}

/* A quiet link on the right, like lavinmq.com's top menu */
.nav {
  margin-left: auto;
  color: var(--smoke);
  font-size: 15px;
  text-decoration: none;
  text-underline-offset: 5px;
}

.nav:hover,
.nav[aria-current] {
  color: var(--bone);
}

.nav[aria-current] {
  text-decoration: underline;
  text-decoration-color: var(--fire);
}

#status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 13px var(--mono);
  color: var(--smoke);
}

#status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--smoke);
}

#status.ok::before {
  background: var(--signal);
  box-shadow: 0 0 10px var(--signal);
}

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

#music-toggle {
  display: grid;
  padding: 6px;
  border-radius: 8px;
  background: none;
  color: var(--smoke);
}

#music-toggle:hover {
  background: var(--ash);
  color: var(--bone);
}

#music-toggle svg {
  fill: currentColor;
  shape-rendering: crispEdges;
}

#music-toggle[aria-pressed="true"] .off,
#music-toggle[aria-pressed="false"] .on {
  display: none;
}

#music-volume {
  width: 88px;
  accent-color: var(--fire);
}

/* Controls */

.button,
button {
  display: inline-block;
  padding: 9px 18px 7px;
  border: 0;
  border-radius: 12px;
  background: var(--fire);
  color: var(--night);
  font: 26px/1 var(--pixel);
  text-decoration: none;
  cursor: pointer;
}

.button:hover,
button:hover {
  background: var(--flame);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--smoke);
  font-size: 15px;
}

input,
select {
  font: inherit;
  font-size: 16px;
  color: var(--bone);
  background: var(--night);
  border: 1px solid var(--rim);
  border-radius: 10px;
  padding: 9px 12px;
}

/* The browser's own arrow sits wherever the browser likes, often hard
   against the rounded edge, so draw one that lines up with the padding */
select {
  appearance: none;
  padding-right: 38px;
  background: var(--night)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%2395928c' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E")
    no-repeat right 14px center;
}

input:focus,
select:focus {
  border-color: var(--fire);
  outline: none;
}

label.check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--dust);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--fire);
}

progress {
  appearance: none;
  height: 3px;
  border: 0;
  border-radius: 2px;
  background: var(--rim);
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: var(--rim);
}

progress::-webkit-progress-value {
  background: var(--fire);
}

progress::-moz-progress-bar {
  background: var(--fire);
}

/* Lobby: the fire */

.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 48px;
  min-height: min(86vh, 880px);
  padding: clamp(24px, 6vh, 72px) var(--gutter) 0;
}

/* LavinMQ's contour lines, glowing over the fire */
.topo {
  position: absolute;
  inset: 0;
  z-index: -2;
  /* cool and faint up top, as on lavinmq.com, heating up toward the fire */
  background: linear-gradient(rgb(247 245 242 / 0.1), rgb(247 245 242 / 0.05) 25%, #b3290b 62%, #ff8a2a);
  mask: url("img/topo.png") center top / 1440px auto repeat;
}

.hero .fire {
  position: absolute;
  inset: auto 0 0;
  z-index: -1;
  width: 100%;
  height: 72%;
  image-rendering: pixelated;
}

/* The fire and the letters sink into the page below */
.hero::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 56px;
  background: linear-gradient(transparent, var(--night));
}

.pitch {
  max-width: 36rem;
}

.lead {
  margin: 0 0 14px;
  color: var(--bone);
  font-size: clamp(30px, 3.6vw, 46px);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.pitch p {
  margin-top: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px 24px;
  margin-top: 28px;
}

.actions button {
  padding: 10px 22px 8px;
  font-size: 30px;
}

.name input {
  width: 14rem;
}

#preload {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 28px 0 0;
  font: 12.5px var(--mono);
  color: var(--smoke);
}

#preload progress {
  width: 14rem;
  visibility: hidden;
}

#preload.downloading progress {
  visibility: visible;
}

#preload.ready {
  color: var(--signal);
}

#preload.failed {
  color: var(--flame);
}

.hero h1 {
  margin: 0 0 -0.06em -0.03em;
  font: clamp(120px, 40vw, 600px) / 0.8 var(--pixel);
  /* lit by the fire below, and standing out from it */
  background: linear-gradient(to bottom, var(--bone) 45%, #ffd9a0 70%, var(--flame));
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0.03em 0.03em 0 rgb(20 20 20 / 0.75));
}

/* Lobby: games */

.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-areas: "games create" "saved create";
  align-items: start;
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 64px var(--gutter);
}

.games {
  grid-area: games;
}

#create {
  grid-area: create;
}

#saved {
  grid-area: saved;
}

/* A terminal window, as on lavinmq.com */
.window {
  background: var(--ash);
  border: 1px solid var(--rim);
  border-radius: 16px;
  overflow: hidden;
}

.titlebar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--rim);
}

.lights {
  width: 10px;
  height: 10px;
  margin-right: 30px;
  border-radius: 50%;
  background: #ff5f57;
  box-shadow:
    16px 0 #febc2e,
    32px 0 #28c840;
}

.titlebar h1,
.titlebar h2,
.titlebar h3 {
  margin: 0;
  color: var(--bone);
  font: 28px/1 var(--pixel);
}

.titlebar code {
  margin-left: auto;
  color: var(--signal);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 18px;
  text-align: left;
  border-bottom: 1px solid var(--rim);
}

th {
  color: var(--smoke);
  font-size: 14px;
  font-weight: 500;
}

td:first-child {
  color: var(--bone);
  font-weight: 600;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #202020;
}

/* Players, in the status bar's numbers */
#games td:nth-child(6) {
  color: var(--fire);
  font: 26px/1 var(--pixel);
}

td:last-child {
  text-align: right;
  white-space: nowrap;
}

td .button {
  font-size: 22px;
  padding: 6px 14px 5px;
  border-radius: 10px;
}

td .button + .button {
  margin-left: 8px;
}

td .muted {
  color: var(--smoke);
  font-size: 15px;
  white-space: nowrap;
}

#empty {
  margin: 0;
  padding: 28px 18px;
  color: var(--smoke);
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 18px;
}

.fields .wide,
.fields button {
  grid-column: 1 / -1;
}

.fields button {
  margin-top: 4px;
  padding: 12px 18px 10px;
  font-size: 28px;
}

/* Lobby: how it works */

.wire {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px var(--gutter) 72px;
}

.wire h2 {
  margin: 0 0 8px;
  color: var(--bone);
  font: 44px/1 var(--pixel);
}

.wire > p {
  max-width: 40rem;
  margin-top: 0;
}

.wire dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 24px 32px;
  margin: 32px 0 0;
}

.wire dl > div {
  padding-top: 16px;
  border-top: 1px solid var(--rim);
}

.wire dt {
  color: var(--signal);
  overflow-wrap: anywhere;
}

.wire dd {
  margin: 8px 0 0;
}

#watch-all {
  color: var(--smoke);
  font-size: 15px;
}

#watch-all:hover {
  color: var(--bone);
}

td .watch {
  background: var(--rim);
  color: var(--bone);
}

td .watch:hover {
  background: #3a3a3a;
}

/* Spectators */

#watch {
  max-width: 1440px;
  margin: 0 auto;
  padding: 8px var(--gutter) 56px;
}

.watching {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 28px;
  margin-bottom: 24px;
}

.watching h1 {
  margin: 0;
  color: var(--bone);
  font: 56px/1 var(--pixel);
}

.watching p {
  max-width: 44rem;
  margin: 0;
}

.watching code {
  color: var(--signal);
}

#all-games {
  color: var(--smoke);
}

#arena {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr));
  gap: 24px;
}

/* One game, as big as it gets */
#arena:has(.match:only-child) {
  grid-template-columns: minmax(0, 1fr);
}

#nothing {
  padding: 48px 0;
  color: var(--smoke);
  text-align: center;
}

.match .details {
  margin: 0;
  color: var(--smoke);
  font-size: 15px;
}

.field {
  position: relative;
  background: #0d0d0d;
}

.field canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
}

/* One game: the map, and the scores beside it */
#arena:has(.match:only-child) .match {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}

#arena:has(.match:only-child) .titlebar {
  grid-column: 1 / -1;
}

#arena:has(.match:only-child) .field canvas {
  aspect-ratio: auto;
  height: min(72vh, 780px);
}

#arena:has(.match:only-child) .scores {
  border-left: 1px solid var(--rim);
}

.banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0 10%;
  color: var(--bone);
  font: clamp(28px, 3.2vw, 40px) / 1.05 var(--pixel);
  text-align: center;
  background: rgb(13 13 13 / 0.55);
}

/* No players to show yet, the space stays so the map doesn't jump */
.scores:has(tbody:empty) {
  visibility: hidden;
}

.scores td:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
}

.scores i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.scores td:nth-child(2) {
  color: var(--bone);
  font: 26px/1 var(--pixel);
}

.scores .leader td:nth-child(2) {
  color: var(--fire);
}

.scores td:last-child {
  color: var(--smoke);
  text-align: left;
}

/* Why MQTT, a page to read */

.article {
  max-width: 50rem;
  margin: 0 auto;
  padding: clamp(24px, 6vh, 64px) var(--gutter) 72px;
}

.article h1 {
  margin: 0 0 20px;
  color: var(--bone);
  font: clamp(72px, 12vw, 128px) / 0.85 var(--pixel);
}

.article h2 {
  margin: 56px 0 12px;
  color: var(--bone);
  font: 40px/1 var(--pixel);
}

.article p,
.article li {
  max-width: 40rem;
}

.article .lead {
  max-width: 36rem;
  margin-bottom: 28px;
  font-size: clamp(22px, 2.4vw, 27px);
  line-height: 1.3;
}

.article code {
  color: var(--signal);
  overflow-wrap: anywhere;
}

#now {
  padding: 12px 16px;
  border: 1px solid var(--rim);
  border-radius: 12px;
  color: var(--dust);
  font-size: 15px;
}

#now::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 10px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 10px var(--signal);
}

.article .window {
  margin: 24px 0;
}

.mapping td {
  vertical-align: top;
  font-size: 15.5px;
}

.mapping td:first-child {
  width: 26%;
}

.mapping td:last-child {
  text-align: left;
}

.mapping td:nth-child(2) {
  width: 22%;
  color: var(--fire);
  font-weight: 600;
}

.mapping tbody tr:hover {
  background: none;
}

pre.terminal {
  padding: 18px;
  overflow-x: auto;
  font: 13.5px/1.8 var(--mono);
}

pre.terminal code {
  overflow-wrap: normal;
  font: inherit;
}

pre.terminal span {
  color: var(--smoke);
}

/* A protocol log: what the client does, on which topic */
pre.terminal b {
  color: var(--bone);
  font-weight: 600;
}

pre.terminal i {
  color: var(--signal);
  font-style: normal;
}

/* A game's life, step by step */
.how {
  counter-reset: step;
}

.how h2.step::before {
  counter-increment: step;
  content: counter(step);
  display: inline-block;
  min-width: 1em;
  color: var(--fire);
}

/* Payloads plain, topics green */
.how pre.terminal code {
  color: var(--dust);
}

.features li {
  margin-bottom: 10px;
}

.features strong {
  color: var(--bone);
}

.next {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 28px;
  margin-top: 48px;
}

.next a:not(.button) {
  color: var(--smoke);
}

@media (max-width: 640px) {
  .mapping thead {
    display: none;
  }

  .mapping tr {
    display: block;
    padding: 12px 0;
    border-bottom: 1px solid var(--rim);
  }

  .mapping td {
    display: block;
    width: auto !important;
    padding: 2px 16px;
    border: 0;
  }
}

/* A game */

#game {
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px var(--gutter) 48px;
}

#details {
  margin: 0;
  color: var(--smoke);
  font-size: 15px;
}

#game .titlebar .back {
  margin-left: auto;
  color: var(--smoke);
  font-size: 15px;
}

.screen {
  position: relative;
  background: #000;
}

#canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border: 0;
  padding: 0;
}

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #000;
  overflow: hidden;
}

#loading .fire {
  position: absolute;
  inset: auto 0 0;
  width: 100%;
  height: 40%;
  image-rendering: pixelated;
}

#loading-text {
  position: relative;
  margin: 0;
  color: var(--bone);
  font: 30px/1 var(--pixel);
}

#loading progress {
  position: relative;
  width: min(50%, 22rem);
}

#hint {
  color: var(--dust);
  text-align: center;
}

.keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 22px;
  color: var(--smoke);
  font-size: 15px;
}

#game:not(.spectating) .keys .spectator,
#game.spectating .keys .player {
  display: none;
}

kbd {
  display: inline-block;
  min-width: 1.7em;
  margin-right: 3px;
  padding: 1px 6px;
  border: 1px solid var(--rim);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: var(--ash);
  color: var(--bone);
  font: 13px/1.6 var(--mono);
  text-align: center;
}

/* A game on a phone or a tablet, see js/touch.js: Doom fills the screen,
   and the controls lie over all of it */

body:has(#game.touch:not([hidden])) > :is(.bar, footer),
#game.touch :is(.titlebar, .keys) {
  display: none;
}

#game.touch {
  position: fixed;
  inset: 0;
  max-width: none;
  padding: 0;
  background: #000;
}

#game.touch .window {
  height: 100%;
  border: 0;
  border-radius: 0;
  background: #000;
}

#game.touch .screen {
  width: min(100vw, 100dvh * 4 / 3);
  margin: 0 auto;
}

#game.touch #hint {
  position: fixed;
  inset: env(safe-area-inset-top) 0 auto;
  margin: 6px 0;
  font-size: 15px;
  pointer-events: none;
}

#touch {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#touch button {
  position: absolute;
  right: calc(var(--right) + env(safe-area-inset-right));
  bottom: calc(var(--bottom) + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: var(--size, 64px);
  height: var(--size, 64px);
  /* Browsers on phones pad buttons, which pushes the text aside */
  padding: 0;
  border: 2px solid rgb(247 245 242 / 0.5);
  border-radius: 50%;
  background: rgb(20 20 20 / 0.45);
  color: var(--bone);
  font: 18px/1 var(--pixel);
}

#touch .back {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left));
  top: calc(12px + env(safe-area-inset-top));
  padding: 8px;
  color: var(--smoke);
  font-size: 15px;
}

#touch [data-action="fire"] {
  --size: 88px;
  --right: 20px;
  --bottom: 28px;
  border-color: var(--fire);
}

#touch [data-action="use"] {
  --right: 120px;
  --bottom: 20px;
}

#touch [data-action="weapon"] {
  --size: 72px;
  --right: 24px;
  --bottom: 132px;
}

#touch :is([data-action="start"], [data-action="fullscreen"]) {
  --right: 12px;
  top: calc(12px + env(safe-area-inset-top));
  bottom: auto;
  width: auto;
  height: auto;
  padding: 8px 14px;
  border-radius: 10px;
}

#touch [data-action="start"] {
  right: auto;
  left: 50%;
  top: 40%;
  translate: -50%;
  padding: 14px 28px;
  border-color: var(--fire);
  font-size: 30px;
}

/* Where the thumb went down, and the knob where it is now */
#touch .stick {
  position: absolute;
  width: 112px;
  height: 112px;
  margin: -56px;
  border: 2px solid rgb(247 245 242 / 0.35);
  border-radius: 50%;
  pointer-events: none;
}

#touch .stick::after {
  content: "";
  position: absolute;
  inset: 30px;
  border-radius: 50%;
  background: rgb(247 245 242 / 0.5);
  translate: var(--x, 0) var(--y, 0);
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: var(--gutter);
  background: rgb(20 20 20 / 0.9);
  backdrop-filter: blur(6px);
}

#message {
  max-width: 22ch;
  margin: 0;
  color: var(--bone);
  font: clamp(36px, 6vw, 56px) / 1 var(--pixel);
  text-align: center;
}

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px var(--gutter) 40px;
  border-top: 1px solid var(--rim);
  font-size: 15px;
}

footer a {
  color: var(--smoke);
  text-decoration: none;
}

footer a:hover {
  color: var(--bone);
}

@media (max-width: 1000px) {
  #arena:has(.match:only-child) .match {
    display: block;
  }

  #arena:has(.match:only-child) .field canvas {
    aspect-ratio: 4 / 3;
    height: auto;
  }

  #arena:has(.match:only-child) .scores {
    border-left: 0;
  }
  .board {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "games" "create" "saved";
  }
}

@media (max-width: 640px) {
  /* Host, mode and skill can wait for a bigger screen */
  #games :is(th, td):is(:nth-child(2), :nth-child(3), :nth-child(5)),
  #saves :is(th, td):is(:nth-child(2), :nth-child(3)) {
    display: none;
  }

  .hero {
    min-height: 0;
    gap: 72px;
  }

  .hero .fire {
    height: calc(40vw + 48px);
  }

  th,
  td {
    padding: 10px 12px;
  }

  .titlebar code {
    margin-left: 0;
  }

  /* The link starts the second row, the connection and music end it */
  .bar {
    column-gap: 16px;
  }

  .nav {
    margin-left: 0;
  }

  #status {
    margin-left: auto;
  }
}
