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

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface-page);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.45;
  accent-color: var(--accent);
}

.page {
  width: 100%;
  margin-inline: auto;
  padding: var(--space-5) var(--gutter);
}

main.page {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.page--narrow {
  max-width: var(--page-narrow);
}

.page--default {
  max-width: var(--page-default);
}

.page--wide {
  max-width: var(--page-wide);
}

/* The room owns the whole viewport: no width cap, no page padding. */
main.page--table {
  padding: 0;
  height: 100dvh;
  overflow: hidden;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack--sm {
  gap: var(--space-2);
}

.stack--lg {
  gap: var(--space-5);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.form-row {
  display: flex;
  gap: var(--space-2);
}

.form-row > .input {
  flex: 1;
  min-width: 0;
}

.empty {
  text-align: center;
  padding-block: var(--space-6);
}

.landing {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  text-align: center;
}

.landing__nav {
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
}

.landing__lede {
  max-width: 44em;
  padding-inline: var(--gutter);
}

.landing__cta {
  position: relative;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-4) var(--space-5);
  margin-top: var(--space-5);
  padding-inline: var(--gutter);
}

/* Everything below the call to action is table: the felt starts here, so
   the rail can never run under the buttons on a short screen. */
.modal {
  width: calc(100% - var(--gutter) * 2);
  max-width: var(--page-modal);
}

/* A tall dialog keeps its title, close button and action in place and
   scrolls only what is between them. */
.modal--tall {
  max-width: var(--page-modal-wide);
}

.modal--tall[open] {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - var(--space-5) * 2);
  overflow: hidden;
}

.modal__form {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.modal__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin-inline: calc(var(--space-6) * -1);
  padding: var(--space-5) var(--space-6);
}

.modal__foot {
  flex: none;
  padding-top: var(--space-5);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: var(--gutter);
}

.namecard {
  position: relative;
  width: calc(100% - var(--gutter) * 2);
  max-width: var(--page-card);
}

dialog.namecard {
  position: fixed;
  overflow: visible;
}

.namecard__back {
  position: absolute;
  inset: 0;
}

.namecard__face {
  position: relative;
  display: flex;
  min-height: 31rem;
}

.namecard__index {
  position: absolute;
  inset: 0.9rem auto auto 1rem;
}

.namecard__index--br {
  inset: auto 1rem 0.9rem auto;
  rotate: 180deg;
}

.namecard__form {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-5);
}

.namecard__here {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
}

.namecard__pile {
  display: inline-flex;
}

.namecard__pile .pc + .pc {
  margin-left: calc(var(--space-2) * -1);
}

.modal__close {
  position: absolute;
  inset: var(--space-2) var(--space-2) auto auto;
}

.landing__table {
  position: relative;
  flex: 1;
  align-self: stretch;
  min-height: calc(var(--fan-card) * 1.6);
  margin-top: var(--space-6);
}

.landing__felt {
  position: absolute;
  inset: 0 auto auto 50%;
  width: 150vw;
  height: 100vh;
  translate: -50% 0;
}

.landing__fan {
  position: absolute;
  inset: auto auto calc(var(--fan-sink) * -1) 50%;
  width: 0;
  height: var(--fan-radius);
}

.landing__slot {
  position: absolute;
  inset: auto auto 0 calc(var(--fan-card) / -2);
  width: var(--fan-card);
  height: var(--fan-radius);
  transform-origin: 50% 100%;
  rotate: calc((var(--i) - 6) * var(--fan-step));
}

.landing__hint {
  position: absolute;
  inset: 2.5rem 0 auto;
  z-index: 1;
}

body:has(.landing) .foot {
  display: none;
}

.room {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.room__head {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) 0;
}

.room__head .chip {
  margin-inline: auto 0;
}

.board {
  flex: 1;
  min-height: 0;
  position: relative;
}

.tools {
  position: absolute;
  inset: var(--space-2) var(--space-4) auto auto;
  z-index: 3;
  display: flex;
  gap: var(--space-1);
}

/* The table takes the height left between the header and the hand, less
   the room its seats need above and below, and never loses its shape. */
.felt {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(50vw, (var(--board-height) - var(--seat-reach-y) * 4) / 1.25);
  aspect-ratio: 1 / 1.25;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
}

/* The seat list covers the table exactly and is a size container, so each
   seat is placed from the table's real edge and always sits just outside. */
.seats {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  container-type: size;

  /* It lies over the whole table; clicks must reach the chip beneath it. */
  pointer-events: none;
}

.seat {
  pointer-events: auto;
  position: absolute;
  inset: 50% auto auto 50%;
  width: calc(var(--seat-card) * 2);
  transform: translate(
    calc(-50% + cos(var(--a)) * (50cqw + var(--seat-reach-x))),
    calc(-50% + sin(var(--a)) * (50cqh + var(--seat-reach-y)))
  );
}

.seats--close {
  --seat-card: 34px;
}

.seats--packed {
  --seat-card: 26px;
}

.board > .hint {
  position: absolute;
  inset: auto var(--space-4) var(--space-2);
  text-align: center;
}

.hand {
  flex: none;
  position: relative;
  height: var(--hand-height);
}

.hand__card {
  position: absolute;
  left: 50%;
  bottom: calc(var(--hand-sink) * -1);
  width: var(--hand-card);
  height: var(--hand-radius);
  margin-left: calc(var(--hand-card) / -2);
  transform-origin: 50% 100%;
  transform: rotate(calc((var(--i) - var(--mid)) * var(--step)));
}

.hand__card[aria-pressed="true"] {
  transform: rotate(calc((var(--i) - var(--mid)) * var(--step))) translateY(calc(var(--hand-lift) * -1));
}

.is-presenting .room__head,
.is-presenting .hand,
.is-presenting .foot {
  display: none;
}

.foot {
  flex: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-block: var(--space-4);
}

body:has(.room) .foot {
  display: none;
}

/* Phones fan a 13-card hand at 6 degrees; the step set per deck is for laptops. */
@media (width < 56rem) {
  .seat .pc i {
    display: none;
  }

  /* No room for the full name beside the room number: the spade stands in. */
  .room__head .wordmark {
    font-size: 0;
  }

  .room__head .wordmark::after {
    font-size: 1.5rem;
  }

  /* The top of the table is a seat on a phone; the tools move below it. */
  .tools {
    inset: auto auto var(--space-1) var(--space-2);
  }

  .hand__card {
    transform: rotate(calc((var(--i) - var(--mid)) * var(--step) * 2.4));
  }

  .hand__card[aria-pressed="true"] {
    transform: rotate(calc((var(--i) - var(--mid)) * var(--step) * 2.4)) translateY(calc(var(--hand-lift) * -1));
  }
}

@media (width >= 40rem) {
  :root {
    --gutter: 1.5rem;
  }
}

/* Laptop and above: a wide table, larger seats, a flatter and bigger hand. */
@media (width >= 56rem) {
  :root {
    --head-height: 4.25rem;
    --seat-reach-x: calc(var(--seat-card) + 1.75rem);
    --seat-reach-y: calc(var(--seat-card) * 0.7 + 2.75rem);
    --fan-card: 120px;
    --fan-radius: 2000px;
    --fan-sink: 1840px;
    --fan-step: 3.3deg;
    --seat-card: clamp(34px, 5.1vh, 46px);
    --hand-card: 67px;
    --hand-height: 157px;
    --hand-radius: 1600px;
    --hand-sink: 1469px;
    --hand-lift: 32px;
  }

  .room__head {
    padding: var(--space-5) var(--space-6) 0 var(--space-5);
  }

  .landing__nav {
    padding: var(--space-5) var(--space-6) var(--space-3);
  }

  .tools {
    inset: var(--space-3) var(--space-6) auto auto;
  }

  .felt {
    width: min(62vw, 920px, (var(--board-height) - var(--seat-reach-y) * 4) * 2.1);
    aspect-ratio: 2.1 / 1;
  }

  .seats--close {
    --seat-card: 37px;
  }

  .seats--packed {
    --seat-card: 27px;
  }

  .hand__card:hover:not([aria-pressed="true"]) {
    transform: rotate(calc((var(--i) - var(--mid)) * var(--step))) translateY(-16px);
  }
}
