/* A screen-print look: six flat inks on a gold sheet, slab titles, hard offset shadows, crop marks in the corners. */

@font-face {
  font-family: "Alfa Slab One";
  src: url("/fonts/AlfaSlabOne.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Rubik";
  src: url("/fonts/Rubik.woff2") format("woff2");
  font-weight: 300 900;
  font-display: swap;
}

@font-face {
  font-family: "Cormorant Garamond";
  src: url("/fonts/CormorantGaramond-Italic.woff2") format("woff2");
  font-style: italic;
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: "Lalezar";
  src: url("/fonts/Lalezar.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --cream: #f8e5c2;
  --gold: #e7a945;
  --teal: #4c9195;
  --coral: #e35849;
  --terra: #a75435;
  --navy: #152745;
  --page: 76rem; /* the widest the content of any page gets */
  --slab: "Alfa Slab One", Rockwell, "Courier New", serif;
  --ui: "Rubik", "Segoe UI", system-ui, sans-serif;
  --hand: "Cormorant Garamond", Georgia, serif;
  --arabic: "Lalezar", "Segoe UI", Tahoma, sans-serif;
  /* Speckles, as ink leaves them on rough paper. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.15' numOctaves='2' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.65 0 0 0 0 0.33 0 0 0 0 0.21 0 0 0 -2.6 1.32'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23g)'/%3E%3C/svg%3E");
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--gold) var(--grain);
  color: var(--navy);
  font: 400 1rem/1.5 var(--ui);
}

h1,
h2,
p,
ol,
fieldset {
  margin: 0;
}

a {
  color: inherit;
  text-underline-offset: 0.18em;
}

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

[hidden] {
  display: none !important;
}

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

::selection {
  background: var(--navy);
  color: var(--cream);
}

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

/* Crop marks, one in each corner of the sheet */

.marks i {
  position: fixed;
  z-index: 1;
  width: 1.4rem;
  height: 1.4rem;
  border: 1.5px solid var(--navy);
  border-radius: 50%;
  pointer-events: none;
}

.marks i::before,
.marks i::after {
  content: "";
  position: absolute;
  background: var(--navy);
}

.marks i::before {
  top: 50%;
  left: -0.4rem;
  right: -0.4rem;
  height: 1.5px;
  margin-top: -0.75px;
}

.marks i::after {
  left: 50%;
  top: -0.4rem;
  bottom: -0.4rem;
  width: 1.5px;
  margin-left: -0.75px;
}

.marks i:nth-child(1) { top: 0.75rem; left: 0.75rem; }
.marks i:nth-child(2) { top: 0.75rem; right: 0.75rem; }
.marks i:nth-child(3) { bottom: 0.75rem; left: 0.75rem; }
.marks i:nth-child(4) { bottom: 0.75rem; right: 0.75rem; }

/* They are fixed to the window, so they show only where the page's own margins are wider than they are. */
@media (max-width: 74.99rem) {
  .marks {
    display: none;
  }
}

/* Printed pieces of paper: a card, a two-colour label, a button */

.card {
  padding: 1.1rem 1.25rem;
  border: 2px solid var(--navy);
  border-radius: 3px;
  background: var(--cream);
  box-shadow: 6px 6px 0 var(--navy);
}

.label {
  display: inline-flex;
  border: 2px solid var(--navy);
  border-radius: 3px;
  box-shadow: 4px 4px 0 var(--navy);
  font: 400 0.8125rem/1 var(--slab);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.label span {
  padding: 0.5rem 0.75rem;
  background: var(--teal);
  color: var(--cream);
}

.label span + span {
  background: var(--cream);
  color: var(--coral);
}

.btn {
  display: inline-block;
  padding: 0.7rem 1rem;
  border: 2px solid var(--navy);
  border-radius: 3px;
  background: var(--coral);
  box-shadow: 4px 4px 0 var(--navy);
  color: var(--navy);
  font: 400 0.8125rem/1 var(--slab);
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.btn:hover {
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 var(--navy);
}

.btn:active {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 var(--navy);
}

.btn.quiet {
  background: var(--cream);
}

.btn.quiet[aria-pressed="true"] {
  background: var(--gold);
}

.btn.big {
  padding: 1.05rem 1.6rem;
  box-shadow: 6px 6px 0 var(--navy);
  font-size: 1.125rem;
}

.btn.big:hover {
  box-shadow: 5px 5px 0 var(--navy);
}

.btn.big:active {
  transform: translate(6px, 6px);
  box-shadow: 0 0 0 var(--navy);
}

.btn:disabled {
  opacity: 0.45;
  transform: none;
  box-shadow: 4px 4px 0 var(--navy);
  cursor: default;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  font: 600 0.9375rem/1.3 var(--ui);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.22em;
  cursor: pointer;
}

.link-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* The board */

.board {
  position: relative;
  width: 100%;
  width: round(down, 100%, 8px); /* whole pixels per square keep the edges crisp */
  aspect-ratio: 1;
  container-type: inline-size;
  outline: 3px solid var(--navy);
  background-color: var(--cream);
  background-image: repeating-conic-gradient(var(--teal) 0 25%, transparent 0 50%);
  background-size: 25% 25%;
  box-shadow: 0.7rem 0.7rem 0 var(--navy);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.board.is-dragging {
  cursor: grabbing;
}

.board-layer {
  position: absolute;
  inset: 0;
}

.board-marks,
.board-coords,
.board-pieces {
  pointer-events: none;
}

.sq {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
}

.piece {
  background-position: center;
  background-repeat: no-repeat;
  background-size: 96% 96%;
  transition: transform 0.19s cubic-bezier(0.25, 0.7, 0.3, 1), opacity 0.16s linear;
  will-change: transform;
}

.board-pieces.still .piece,
.piece.dragging {
  transition: none;
}

.piece.dragging {
  z-index: 5;
  filter: drop-shadow(0.9cqw 0.9cqw 0 rgba(21, 39, 69, 0.45));
}

.piece.leaving,
.piece.arriving {
  opacity: 0;
}

.mark-last {
  background: var(--gold);
  opacity: 0.82;
}

.mark-selected {
  background: var(--navy);
  opacity: 0.34;
}

.mark-check {
  background: var(--coral);
}

.mark-hover {
  background: var(--navy);
  opacity: 0.3;
}

.mark-go::after,
.mark-take::after {
  content: "";
  position: absolute;
  border-radius: 50%;
}

.mark-go::after {
  inset: 35%;
  background: var(--navy);
  opacity: 0.4;
}

.mark-take::after {
  inset: 5%;
  border: 0.75cqw solid var(--navy);
  opacity: 0.4;
}

.coord {
  position: absolute;
  font: 700 max(12px, 1.9cqw) / 1 var(--ui);
}

.coord-file {
  bottom: 0.55cqw;
  width: 12.5%;
  padding-right: 0.7cqw;
  text-align: right;
}

.coord-rank {
  left: 0.7cqw;
  margin-top: 0.6cqw;
}

.on-light {
  color: var(--teal);
}

.on-dark {
  color: var(--cream);
}

.board-promo {
  z-index: 10;
  background: rgba(21, 39, 69, 0.55);
}

.promo-choice {
  padding: 0;
  border: 2px solid var(--navy);
  border-radius: 50%;
  background-color: var(--cream);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 84% 84%;
  cursor: pointer;
}

.promo-choice:hover,
.promo-choice:focus-visible {
  background-color: var(--gold);
}

/* The bar at the top of a room, and of the small pages */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 1.1rem;
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 0.7rem;
  text-decoration: none;
}

.wordmark .ar {
  font: 400 2rem/1 var(--arabic);
  text-shadow: 0.07em 0.07em 0 var(--coral);
}

.wordmark .en {
  font: 400 0.9375rem/1 var(--slab);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.state {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--navy);
  border-radius: 3px;
  background: var(--cream);
  box-shadow: 4px 4px 0 var(--navy);
  font: 600 0.875rem/1.2 var(--ui);
}

.state:empty {
  visibility: hidden;
}

.state[data-state="live"] {
  background: var(--teal);
  color: var(--cream);
}

.state[data-state="lost"] {
  background: var(--coral);
}

/* The front page */

.home {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  grid-template-areas: "pitch stage" "more stage";
  grid-template-rows: auto 1fr;
  column-gap: clamp(2rem, 6vw, 5.5rem);
  align-items: start;
  max-width: var(--page);
  margin: 0 auto;
  padding: clamp(2.25rem, 5vw, 3.75rem) clamp(1rem, 4vw, 3rem) 3.5rem;
}

.pitch {
  grid-area: pitch;
  max-width: 31rem;
  container-type: inline-size;
}

.stage {
  grid-area: stage;
  max-width: 35.7rem;
  padding-right: 0.7rem;
}

.more {
  grid-area: more;
  max-width: 31rem;
  margin-top: 2.75rem;
}

.stage-board {
  position: relative;
}

/* The place and year of the game on the board, pinned over its top edge. */
.stage-board .label {
  position: absolute;
  right: 1.4rem;
  bottom: calc(100% - 0.4rem);
  z-index: 3;
  transform: rotate(2deg);
}

.pitch h1 {
  margin: 0 0 1.6rem;
}

/* The title is sized from the column it sits in, so the word and the knight fill its width on every screen. */
.title-row {
  display: flex;
  align-items: center;
  gap: 0.08em;
  margin-top: -0.12em;
  font-size: clamp(4rem, 31cqw, 9.75rem);
}

/* The line is taller than the letters look: the tail of the last letter needs the room. */
.title-ar {
  font: 400 1em/1.2 var(--arabic);
  text-shadow: 0.055em 0.055em 0 var(--coral);
}

.title-piece {
  width: 0.62em;
  height: 0.62em;
  filter: drop-shadow(0.05em 0.05em 0 var(--coral));
}

.title-en {
  display: block;
  font: 400 clamp(1.2rem, 7.6cqw, 2.45rem) / 1.1 var(--slab);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  white-space: nowrap;
}

.words {
  font: italic 500 1.4rem/1.32 var(--hand);
}

.words p + p {
  margin-top: 0.6rem;
}

.start {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  margin-top: 1.9rem;
}

.aside {
  font-weight: 500;
}

.start-error {
  margin-top: 1rem;
  font-weight: 700;
}

.dashed {
  border-style: dashed;
  box-shadow: none;
}

.more h2,
.block h2,
.prose h2 {
  font: 400 0.9375rem/1.25 var(--slab);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.more h2 {
  margin-bottom: 0.7rem;
}

.steps {
  padding-left: 1.6rem;
}

.steps li {
  padding-left: 0.3rem;
}

.steps li + li {
  margin-top: 0.45rem;
}

.steps li::marker {
  color: var(--coral);
  font: 400 1.0625rem var(--slab);
}

.also {
  margin-top: 1.4rem;
  font-weight: 500;
}

.caption {
  margin-top: 1.9rem;
}

.game-title {
  font: 400 0.9375rem/1.3 var(--slab);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-wrap: balance;
}

.game-place {
  font: italic 600 1.2rem/1.3 var(--hand);
}

.game-moves {
  margin: 0.55rem 0 0.65rem;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.85;
  font-variant-numeric: tabular-nums;
}

.game-moves .pair {
  margin-right: 0.3em;
  white-space: nowrap;
}

.game-moves .no {
  margin-right: 0.25em;
  color: var(--terra);
  font-weight: 700;
}

.caption-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.6rem;
}

/* Struck onto the page when the game reaches its last move. */
.stamp {
  margin-right: 1rem;
  padding: 0.5rem 0.8rem 0.45rem;
  border: 3px solid var(--navy);
  border-radius: 3px;
  outline: 1.5px solid var(--navy);
  outline-offset: 3px;
  font: 400 1.0625rem/1 var(--slab);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0;
  transform: rotate(-6deg) scale(1.7);
  transform-origin: 100% 50%; /* it grows toward the middle of the page, never past its edge */
  transition: opacity 0.08s linear, transform 0.17s cubic-bezier(0.3, 1.3, 0.5, 1);
}

.stamp.on {
  opacity: 1;
  transform: rotate(-6deg);
}

.game-moves .mv {
  margin-right: 0.1em;
  padding: 0.12em 0.3em;
  border: 0;
  border-radius: 2px;
  background: none;
  cursor: pointer;
}

.game-moves .mv:hover {
  background: var(--cream);
}

.game-moves .mv.latest,
.moves .mv.latest {
  background: var(--navy);
  color: var(--cream);
}

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem 2rem;
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.1rem clamp(1rem, 4vw, 3rem) 3rem;
  border-top: 2px solid var(--navy);
  font-size: 0.875rem;
  font-weight: 500;
}

/* A room */

.room {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 21.5rem;
  column-gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: start;
  max-width: var(--page);
  margin: 0 auto;
  padding: 0.6rem clamp(1rem, 4vw, 3rem) 3.5rem;
}

.table {
  display: flex;
  justify-content: center;
  padding-right: 0.7rem;
}

.table-inner {
  width: min(100%, 100vh - 11.5rem);
  width: min(100%, 100dvh - 11.5rem);
  min-width: 17rem;
}

.status {
  min-height: 1.4em;
  margin-top: 1.6rem;
  font: 400 1rem/1.4 var(--slab);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.side {
  display: grid;
  gap: 1.4rem;
  padding-right: 6px;
}

.block h2 {
  margin-bottom: 0.65rem;
}

.block p {
  font-size: 0.9375rem;
}

.moves {
  display: grid;
  grid-template-columns: 2.5rem 1fr 1fr;
  row-gap: 0.15rem;
  max-height: 13.5rem;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.moves li {
  display: contents;
}

.moves .no {
  color: var(--terra);
  font-weight: 700;
}

.moves-empty {
  font: italic 600 1.2rem/1.3 var(--hand);
}

.moves .mv {
  justify-self: start;
  margin-left: -0.3em;
  padding: 0 0.3em;
  border-radius: 2px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 1rem 0 1.1rem;
}

.invite-row {
  display: flex;
  gap: 0.7rem;
  margin-top: 0.8rem;
}

.invite-row input,
.field input,
.field select {
  width: 100%;
  min-width: 0;
  padding: 0.6rem 0.65rem;
  border: 2px solid var(--navy);
  border-radius: 3px;
  background: #fff8ea;
  font: 500 0.9375rem/1.2 var(--ui);
}

.invite-row input {
  flex: 1;
}

.invite-row .btn {
  flex: none;
}

.share {
  margin-top: 0.9rem;
}

.qr {
  width: 8.5rem;
  margin-top: 1.1rem;
}

.qr svg {
  display: block;
  width: 100%;
  height: auto;
  fill: var(--navy);
}

.hint {
  margin-top: 0.4rem;
  font: italic 600 1.1rem/1.3 var(--hand);
}

/* Setting a position up */

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.3rem;
  margin: 0.85rem 0 0.8rem;
}

.tool {
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 3px;
  background-color: #fff8ea;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 88% 88%;
  cursor: pointer;
}

.tool:nth-child(n + 7) {
  background-color: #f0d6a6;
}

.tool[aria-pressed="true"] {
  border-color: var(--navy);
  background-color: var(--gold);
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.turns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  margin-top: 1.1rem;
  padding: 0;
  border: 0;
  font-weight: 600;
}

.turns label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.turns input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--navy);
}

.field {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.9rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.setup-error {
  min-height: 1.4em;
  margin-top: 0.6rem;
  color: #a3261b;
  font-size: 0.9rem;
  font-weight: 700;
}

#setup .actions {
  margin: 0.5rem 0 0.3rem;
}

/* A room that cannot be joined, the page for a wrong address, and the credits */

.ended,
.prose {
  max-width: 42rem;
  margin: 0 auto;
  padding: clamp(1.25rem, 5vw, 3rem) clamp(1rem, 4vw, 3rem) 4rem;
}

.ended h1,
.prose h1 {
  margin-bottom: 1.25rem;
  font: 400 clamp(1.6rem, 4.6vw, 2.5rem) / 1.12 var(--slab);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ended p + p {
  margin-top: 1.9rem;
}

.prose .card + .card {
  margin-top: 1.4rem;
}

.prose h2 {
  margin-bottom: 0.4rem;
}

.prose p + p {
  margin-top: 0.6rem;
}

/* The twelve pieces. Drawn by RhosGFX and released under CC0: see /credits. */

.wK { background-image: url("/pieces/wK.svg"); }
.wQ { background-image: url("/pieces/wQ.svg"); }
.wR { background-image: url("/pieces/wR.svg"); }
.wB { background-image: url("/pieces/wB.svg"); }
.wN { background-image: url("/pieces/wN.svg"); }
.wP { background-image: url("/pieces/wP.svg"); }
.bK { background-image: url("/pieces/bK.svg"); }
.bQ { background-image: url("/pieces/bQ.svg"); }
.bR { background-image: url("/pieces/bR.svg"); }
.bB { background-image: url("/pieces/bB.svg"); }
.bN { background-image: url("/pieces/bN.svg"); }
.bP { background-image: url("/pieces/bP.svg"); }

/* Narrow screens: one column */

@media (max-width: 58rem) {
  .home {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "pitch" "stage" "more";
    row-gap: 2.75rem;
  }

  .more {
    margin-top: 0;
  }

  .board {
    box-shadow: 0.45rem 0.45rem 0 var(--navy);
  }

  .stage {
    max-width: none;
  }

  .stage,
  .table {
    padding-right: 0.45rem;
  }

  .room {
    display: block;
    padding-top: 0.25rem;
  }

  .table-inner {
    width: 100%;
  }

  .status {
    margin-top: 1.2rem;
  }

  .side {
    margin-top: 1.4rem;
  }

  .moves {
    display: flex;
    gap: 0 0.9rem;
    max-height: none;
    padding-bottom: 0.3rem;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
  }

  .moves li {
    display: flex;
    gap: 0.4rem;
  }

  .moves .mv {
    margin-left: 0;
  }

  .moves .mv:empty {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .piece,
  .btn,
  .stamp {
    transition: none;
  }
}
