/* Palette sampled straight out of the tilesets so the interface and the world
   are made of the same colours. Flat fills, hard 3px borders, no radius, no
   shadows: a HUD cut from the tileset rather than a web app floating over it. */
:root {
  --ink:        #241f26;
  --ink-2:      #322b34;
  --ink-3:      #443c47;
  --cream:      #ffead6;
  --cream-dim:  #c4b09a;
  --stone:      #726e69;
  --stone-lit:  #9a948b;
  --moss:       #72751b;
  --moss-dim:   #4c4f14;
  --gold:       #e0a03a;
  --rust:       #b4553f;
  --mine:       #9fc45a;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --pad: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--cream);
  font: 13px/1.5 var(--mono);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
}

canvas { image-rendering: pixelated; display: block; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; }

a { color: var(--gold); }
a:hover { color: var(--cream); }

:where(button, input, a, [tabindex]):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

kbd {
  font: inherit;
  border: 1px solid var(--stone);
  padding: 0 3px;
  color: var(--cream-dim);
}

code { color: var(--gold); }

.vh {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* ---------------------------------------------------------------- panels */

.panel {
  background: var(--ink-2);
  border: 3px solid var(--stone);
  padding: 22px;
  width: min(380px, calc(100vw - 32px));
}

.title { margin: 0 0 10px; }
.title canvas { display: block; }

.lede {
  margin: 0 0 20px;
  color: var(--cream-dim);
  line-height: 1.6;
}

.group-label {
  margin: 18px 0 8px;
  font-size: 11px;
  font-weight: 400;
  color: var(--cream-dim);
  text-transform: lowercase;
}

/* ---------------------------------------------------------------- forms */

label {
  display: block;
  margin-bottom: 5px;
  color: var(--cream-dim);
  font-size: 12px;
}

input {
  display: block;
  width: 100%;
  margin-bottom: 14px;
  padding: 9px 10px;
  font: 13px var(--mono);
  color: var(--cream);
  background: var(--ink);
  border: 2px solid var(--ink-3);
}
input:focus { border-color: var(--gold); outline: none; }
input::placeholder { color: #6b6070; }

.btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font: 13px var(--mono);
  color: var(--cream);
  background: var(--ink-3);
  border: 2px solid var(--stone);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--stone); }
.btn.primary { background: var(--moss-dim); border-color: var(--moss); }
.btn.primary:hover { background: var(--moss); }
.btn.link {
  margin-top: 10px;
  background: none;
  border: none;
  color: var(--cream-dim);
  text-decoration: underline;
  padding: 6px;
}
.btn.link:hover { color: var(--cream); background: none; }
.btn.small { width: auto; padding: 6px 9px; font-size: 12px; }

.error {
  min-height: 18px;
  margin: 0 0 10px;
  color: var(--rust);
  font-size: 12px;
}

/* ---------------------------------------------------------------- gate */

.gate {
  position: fixed; inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--ink);
  z-index: 20;
}
.gate[hidden] { display: none; }

.gate-bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }

.gate-panel, .picker-panel, .door-panel { position: relative; }

.credits {
  position: absolute;
  bottom: 10px;
  left: 0; right: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  justify-content: center;
  padding: 0 16px;
  font-size: 11px;
  color: var(--stone-lit);
}

.whoami { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 4px; }
.whoami-name { flex: 1; }
.whoami .swatch { width: 52px; height: 52px; flex: none; }
.whoami .swatch canvas { width: 48px; height: 48px; }
.whoami input { margin-bottom: 0; }

.row { display: flex; gap: 6px; }
.row input { text-transform: uppercase; letter-spacing: 3px; text-align: center; }
.row .btn { width: auto; padding: 9px 16px; }

.rooms {
  max-height: 168px;
  overflow-y: auto;
  margin-bottom: 14px;
  border: 2px solid var(--ink-3);
}
.rooms:empty { display: none; }
.rooms button {
  display: flex;
  width: 100%;
  gap: 8px;
  align-items: baseline;
  padding: 8px 10px;
  font: 12px var(--mono);
  color: var(--cream);
  background: none;
  border: none;
  border-bottom: 1px solid var(--ink-3);
  cursor: pointer;
  text-align: left;
}
.rooms button:last-child { border-bottom: none; }
.rooms button:hover { background: var(--ink-3); }
.rooms .who { flex: 1; color: var(--cream-dim); }
.rooms .code { color: var(--gold); letter-spacing: 2px; }
.rooms .lock { color: var(--stone-lit); }
.rooms .none { padding: 14px 10px; color: var(--cream-dim); font-size: 12px; }

/* ---------------------------------------------------------------- picker */

.door-panel { width: min(340px, calc(100vw - 32px)); }
.door-panel .lede { margin-bottom: 22px; }
.door-panel input { text-align: center; letter-spacing: 1px; }

.picker-panel { width: min(420px, calc(100vw - 32px)); text-align: center; }
.preview {
  width: 192px; height: 192px;
  margin: 4px auto 0;
  background: var(--ink);
  border: 2px solid var(--ink-3);
}
.preview-name { margin: 8px 0 0; color: var(--gold); }

/* Eight fur colours fill one row, sixteen accessories fill exactly two. */
.swatches {
  display: grid;
  grid-template-columns: repeat(8, 44px);
  margin: 0 auto;
  gap: 6px;
  justify-content: center;
}
.swatch {
  width: 44px; height: 44px;
  padding: 0;
  background: var(--ink);
  border: 2px solid var(--ink-3);
  cursor: pointer;
  transition: border-color 120ms ease;
}
.swatch:hover { border-color: var(--stone-lit); }
.swatch[aria-checked="true"] { border-color: var(--gold); background: var(--ink-3); }
.swatch canvas { width: 40px; height: 40px; }

/* ---------------------------------------------------------------- hud */

#hud[hidden] { display: none; }

.chat-log {
  position: fixed;
  left: var(--pad);
  bottom: 56px;
  width: min(420px, 46vw);
  max-height: 34vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  pointer-events: none;
}
.chat-log p {
  margin: 0;
  padding: 2px 6px;
  background: rgba(36, 31, 38, .82);
  border-left: 3px solid var(--stone);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.chat-log p b { color: var(--gold); font-weight: 400; }
.chat-log p.sys { color: var(--cream-dim); border-left-color: var(--moss); }
.chat-log p.warn { color: var(--rust); border-left-color: var(--rust); }

.chat-form {
  position: fixed;
  left: var(--pad);
  bottom: var(--pad);
  width: min(420px, 46vw);
}
.chat-form[hidden] { display: none; }
.chat-form input { margin: 0; border-color: var(--gold); }

.toast {
  position: fixed;
  top: var(--pad);
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 12px;
  background: var(--ink-2);
  border: 2px solid var(--rust);
  font-size: 12px;
  z-index: 12;
}
.toast[hidden] { display: none; }

.banner {
  position: fixed;
  top: var(--pad);
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  background: rgba(36, 31, 38, .86);
  border: 2px solid var(--stone);
  font-size: 13px;
  white-space: nowrap;
  text-align: center;
}
.banner b { color: var(--gold); font-weight: 400; }
.banner .it { color: var(--rust); }
.banner .clock { color: var(--cream); }
.banner small { display: block; font-size: 11px; color: var(--cream-dim); }

.prompt {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  margin: 0;
  padding: 5px 10px;
  background: rgba(36, 31, 38, .88);
  border: 2px solid var(--stone);
  font-size: 12px;
  color: var(--cream);
  white-space: nowrap;
}
.prompt[hidden] { display: none; }
.prompt kbd { color: var(--gold); border-color: var(--gold); }

.board { margin: 0 0 20px; padding: 0; list-style: none; }
.board li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--ink-3);
  font-size: 12px;
}
.board li span { color: var(--cream-dim); }
.board li b { color: var(--gold); font-weight: 400; }
.board li.you { color: var(--mine); }

.keys {
  position: fixed;
  right: var(--pad);
  bottom: var(--pad);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

/* ---------------------------------------------------------------- sheets */

.sheet {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(20, 17, 21, .8);
  z-index: 30;
}
.sheet[hidden] { display: none; }
.sheet-panel { width: min(520px, calc(100vw - 32px)); }

.help-list { margin: 0 0 20px; }
.help-list dt { color: var(--gold); margin-top: 12px; }
.help-list dd { margin: 3px 0 0; color: var(--cream-dim); line-height: 1.6; }

/* ---------------------------------------------------------------- touch */

.stick {
  position: fixed;
  left: 24px; bottom: 24px;
  width: 116px; height: 116px;
  border: 3px solid var(--stone);
  background: rgba(36, 31, 38, .5);
  border-radius: 50%;
  z-index: 9;
  touch-action: none;
}
.stick[hidden] { display: none; }
.stick-nub {
  position: absolute;
  left: 50%; top: 50%;
  width: 46px; height: 46px;
  margin: -23px 0 0 -23px;
  background: var(--stone);
  border-radius: 50%;
}

.boot {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--ink);
  color: var(--cream-dim);
  z-index: 40;
}
.boot[hidden] { display: none; }

/* ---------------------------------------------------------------- small screens */

@media (max-width: 720px) {
  .chat-log { width: calc(100vw - 28px); max-height: 26vh; bottom: 96px; }
  .chat-form { width: calc(100vw - 28px); bottom: 56px; }
  .emotes { grid-template-columns: repeat(5, 40px); bottom: 108px; }
  .swatches { grid-template-columns: repeat(6, 44px); }
  .banner { font-size: 12px; max-width: calc(100vw - 24px); white-space: normal; }
  .keys { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------------- pixel type

   Buttons are PixFont canvases, not text, because the licence forbids serving
   the .ttf. `stylize` swaps the words for a canvas and leaves a hidden label
   behind, so everything below is about laying that canvas out. */

.btn, .keys button, .tabs button, .rooms button, .vote-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.rooms button { justify-content: flex-start; }
:is(.btn, .keys button, .tabs button, .rooms button) canvas { flex: none; }
button:hover canvas { filter: brightness(1.22); }
label canvas, .group-label canvas, .help-list dt canvas { vertical-align: -3px; }
.rooms .who { min-width: 0; overflow: hidden; }

/* ---------------------------------------------------------------- map vote */

.vote {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 25;
  padding: 16px;
  text-align: center;
  background: rgba(20, 17, 21, .88);
  border: 3px solid var(--stone);
}
.vote-title { margin: 0 0 12px; }
.vote-cards { display: flex; gap: 12px; justify-content: center; }

.vote-card {
  flex-direction: column;
  gap: 6px;
  padding: 7px;
  background: var(--ink-2);
  border: 3px solid var(--ink-3);
  cursor: pointer;
  /* The wheel moves between cards every few frames, so nothing here may take
     longer than a frame or two to settle. */
  transition: transform 90ms ease, border-color 90ms ease, background 90ms ease;
}
.vote-card canvas { width: 176px; height: 136px; }
.vote-card:hover { border-color: var(--stone-lit); }
.vote-card.mine { background: var(--moss-dim); }
.vote-card.on {
  border-color: var(--gold);
  background: var(--ink-3);
  transform: translateY(-6px) scale(1.04);
}
.vote-card.won {
  border-color: var(--gold);
  background: var(--moss);
  transform: scale(1.09);
  animation: won 480ms steps(4) 2;
}
@keyframes won { 50% { filter: brightness(1.6); } }

.vote-tally {
  min-height: 18px;
  color: var(--gold);
}
.vote-note { margin: 10px 0 0; min-height: 18px; color: var(--cream-dim); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .vote-card, .vote-card.on, .vote-card.won { transition: none; transform: none; animation: none; }
}

@media (max-width: 620px) {
  .vote-card canvas { width: 96px; height: 74px; }
  .vote-cards { gap: 7px; }
}

/* Tabs sit side by side, so their pixel labels have to stay narrow. */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
  border-bottom: 3px solid var(--ink-3);
}
.tabs button {
  flex: 1 1 0;
  min-width: 0;
  padding: 9px 6px;
  color: var(--cream);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -3px;
  cursor: pointer;
  /* The label is a canvas baked in one colour, so the selected state is
     brightness rather than a colour swap. */
  opacity: .5;
}
.tabs button canvas { max-width: 100%; }
.tabs button[aria-selected="true"] { opacity: 1; border-bottom-color: var(--gold); }
.rooms .count { color: var(--cream-dim); white-space: nowrap; }
