:root {
  --felt: #1e3a2f;
  --felt-deep: #182f26;
  --felt-line: #315544;
  --chalk: #efeadf;
  --chalk-muted: #a9b9ae;
  --board-light: #e4cfa6;
  --board-dark: #a46f45;
  --board-frame: #4b2f1d;
  --brass: #dcb75e;
  --brass-ink: #221a0b;
  --alert: #e8705a;
  --piece-white: #fbf8f1;
  --piece-black: #1f1813;

  --radius: 6px;
  --gutter: clamp(1rem, 4vw, 2.5rem);

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--felt);
  color: var(--chalk);
  font-family: "Archivo", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}

h1,
h2,
p {
  margin: 0;
}

button,
input {
  font: inherit;
  color: inherit;
}

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

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

.site-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1.25rem var(--gutter);
}

.wordmark {
  color: var(--chalk);
  font-weight: 800;
  font-stretch: 70%;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.room-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1rem;
  min-width: 0;
}

.room-title {
  font-size: 1rem;
  font-weight: 600;
}

.language {
  display: flex;
  margin-left: auto;
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
}

.language button {
  padding: 0.3rem 0.65rem;
  border: 0;
  background: none;
  color: var(--chalk-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.language button[aria-pressed="true"] {
  background: var(--chalk);
  color: var(--felt);
}

.language button:first-child {
  border-radius: calc(var(--radius) - 1px) 0 0 calc(var(--radius) - 1px);
}

.language button:last-child {
  border-radius: 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brass);
  font-size: 0.9375rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem 1.5rem;
  border: 1px solid var(--brass);
  border-radius: var(--radius);
  background: var(--brass);
  color: var(--brass-ink);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  background: var(--chalk);
  border-color: var(--chalk);
}

.button-quiet {
  background: none;
  border-color: var(--felt-line);
  color: var(--chalk);
}

.button-quiet:hover {
  background: var(--felt-deep);
  border-color: var(--chalk-muted);
}

.button-small {
  padding: 0.5rem 0.9rem;
  font-size: 0.9375rem;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.field label {
  font-weight: 600;
}

input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  background: var(--felt-deep);
}

input:focus-visible {
  outline-offset: 0;
  border-color: var(--brass);
}

#code {
  font-weight: 700;
  letter-spacing: 0.08em;
}

.hint,
.empty,
figcaption {
  color: var(--chalk-muted);
  font-size: 0.9375rem;
}

.form-error {
  color: var(--alert);
  font-weight: 600;
}

h2 {
  font-size: 1.125rem;
  font-weight: 700;
}

.lobby {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  grid-template-areas:
    "intro showcase"
    "rooms showcase";
  align-items: start;
  gap: 3rem clamp(2rem, 6vw, 6rem);
  max-width: 76rem;
  margin: 0 auto;
  padding: 1rem var(--gutter) 4rem;
}

.lobby-intro {
  grid-area: intro;
}

.display {
  font-size: clamp(4.5rem, 13vw, 10rem);
  font-weight: 800;
  font-stretch: 62%;
  line-height: 0.82;
  letter-spacing: -0.015em;
  margin-left: -0.04em;
}

.tagline {
  max-width: 30rem;
  margin-top: 1.5rem;
  font-size: 1.1875rem;
  color: var(--chalk-muted);
}

.entry {
  display: grid;
  gap: 1.25rem;
  max-width: 24rem;
  margin-top: 2.5rem;
}

.entry .button {
  justify-self: start;
}

.showcase {
  grid-area: showcase;
  margin: 0;
  position: sticky;
  top: 2rem;
}

.showcase figcaption {
  margin-top: 1rem;
}

.open-rooms {
  grid-area: rooms;
  max-width: 30rem;
}

.room-list {
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.room-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--felt-line);
}

.room-list li:last-child {
  border-bottom: 1px solid var(--felt-line);
}

.room-code {
  font-weight: 800;
  font-stretch: 75%;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
}

.room-host {
  color: var(--chalk-muted);
  font-size: 0.9375rem;
}

.open-rooms .empty {
  margin-top: 0.75rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  width: 100%;
  border: 10px solid var(--board-frame);
  border-radius: 4px;
  background: var(--board-frame);
  box-shadow: 0 20px 45px rgb(5 14 10 / 0.45);
  container-type: inline-size;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 0;
}

button.square {
  cursor: pointer;
}

.light {
  background: var(--board-light);
}

.dark {
  background: var(--board-dark);
}

.light.is-last {
  background: #ecd388;
}

.dark.is-last {
  background: #c29447;
}

.square.is-selected {
  box-shadow: inset 0 0 0 0.6cqi var(--brass);
}

.square.is-check {
  background: radial-gradient(circle, #f2846c 0%, #d0503a 45%, transparent 75%), var(--board-dark);
}

.light.is-check {
  background-color: var(--board-light);
}

.square.is-target::after {
  content: "";
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgb(30 58 47 / 0.45);
}

.square.is-capture::after {
  content: "";
  position: absolute;
  inset: 6%;
  border: 0.8cqi solid rgb(30 58 47 / 0.5);
  border-radius: 50%;
}

.coord {
  position: absolute;
  font-size: max(9px, 2.1cqi);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.light .coord {
  color: var(--board-dark);
}

.dark .coord {
  color: var(--board-light);
}

.coord-rank {
  top: 6%;
  left: 6%;
}

.coord-file {
  right: 6%;
  bottom: 6%;
}

.piece {
  position: relative;
  font-size: 9.2cqi;
  line-height: 1;
  pointer-events: none;
}

.piece-white {
  color: var(--piece-white);
  -webkit-text-stroke: 0.22cqi var(--piece-black);
  filter: drop-shadow(0 0.35cqi 0 rgb(0 0 0 / 0.25));
}

.piece-black {
  color: var(--piece-black);
  -webkit-text-stroke: 0.15cqi rgb(251 248 241 / 0.35);
  filter: drop-shadow(0 0.35cqi 0 rgb(0 0 0 / 0.2));
}

.room {
  display: grid;
  grid-template-columns: min(calc(100svh - 13.5rem), 46rem) minmax(18rem, 24rem);
  justify-content: center;
  align-items: start;
  gap: 2rem clamp(1.5rem, 4vw, 3.5rem);
  padding: 0.5rem var(--gutter) 3rem;
}

.table {
  display: grid;
  gap: 0.75rem;
  min-width: 18rem;
}

.player {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2rem;
  font-weight: 600;
}

.player.is-empty {
  color: var(--chalk-muted);
  font-weight: 400;
}

.chip {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--felt-line);
}

.player[data-color="white"] .chip {
  background: var(--piece-white);
}

.player[data-color="black"] .chip {
  background: var(--piece-black);
  box-shadow: 0 0 0 1px var(--chalk-muted);
}

.player.is-turn .player-name {
  color: var(--brass);
}

.player.is-turn .chip {
  box-shadow: 0 0 0 2px var(--felt), 0 0 0 4px var(--brass);
}

.side {
  display: grid;
  gap: 2rem;
  padding-top: 2.75rem;
}

.status {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 800;
  font-stretch: 75%;
  line-height: 1.15;
}

.status.is-alert {
  color: var(--alert);
}

.move-list {
  display: grid;
  max-height: 12rem;
  margin: 0.75rem 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  counter-reset: move;
}

.move-list li {
  display: grid;
  grid-template-columns: 2.25rem 1fr 1fr;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--felt-line);
  counter-increment: move;
}

.move-list li::before {
  content: counter(move) ".";
  color: var(--chalk-muted);
}

.moves .empty {
  margin-top: 0.75rem;
}

.chat-log {
  display: grid;
  align-content: start;
  gap: 0.4rem;
  height: 11rem;
  margin: 0.75rem 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  font-size: 0.9375rem;
  overflow-wrap: anywhere;
}

.chat-log strong[data-color="white"] {
  color: var(--chalk);
}

.chat-log strong[data-color="black"] {
  color: var(--brass);
}

.chat-log .notice {
  color: var(--chalk-muted);
  font-style: italic;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
}

#leave {
  justify-self: start;
}

.result {
  width: min(26rem, calc(100vw - 2rem));
  padding: 2rem;
  border: 1px solid var(--felt-line);
  border-radius: 10px;
  background: var(--felt-deep);
  color: var(--chalk);
}

.result::backdrop {
  background: rgb(8 18 13 / 0.6);
}

.result h2 {
  font-size: 3rem;
  font-weight: 800;
  font-stretch: 65%;
  line-height: 1;
}

.result p {
  margin-top: 0.75rem;
  color: var(--chalk-muted);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  z-index: 10;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius);
  background: var(--chalk);
  color: var(--felt);
  font-weight: 600;
  transform: translateX(-50%);
}

.toast[hidden] {
  display: none;
}

@media (max-width: 960px) {
  .lobby {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "intro"
      "showcase"
      "rooms";
  }

  .showcase {
    position: static;
    max-width: 34rem;
  }

  .room {
    grid-template-columns: minmax(0, 1fr);
  }

  .table {
    width: 100%;
    max-width: 40rem;
    min-width: 0;
    justify-self: center;
  }

  .side {
    padding-top: 0;
  }
}

@media (max-width: 560px) {
  .site-header {
    flex-wrap: wrap;
  }

  .room-heading {
    order: 3;
    width: 100%;
  }

  .room-list li {
    grid-template-columns: auto 1fr;
  }

  .room-list .button {
    grid-column: 1 / -1;
    justify-self: start;
  }
}
