:root {
  --walnut: #4A2E1C;
  --bone: #F6EFE4;
  --oxblood: #9A2E32;
  --soot: #2A211C;
  --straw: #C4A574;
  --muted: color-mix(in srgb, var(--soot) 74%, var(--straw));
  --hairline: color-mix(in srgb, var(--soot) 12%, transparent);
  --chip: color-mix(in srgb, var(--soot) 8%, var(--bone));
  --chip-hover: color-mix(in srgb, var(--soot) 12%, var(--bone));
  --chip-press: color-mix(in srgb, var(--soot) 17%, var(--bone));
  --font-display: "Bodoni Moda", "Palatino Linotype", Palatino, serif;
  --font-body: "Figtree", "Gill Sans", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI", Helvetica, "Apple Color Emoji", "Noto Sans Arabic", "Noto Sans Hebrew", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --head: 64px;
  --mini-w: 40px;
  --btn-radius: 8px;
  --card-radius: 20px;
  --tray-pad: 12px;
  --tray-radius: 20px;
  --lift:
    0 1px 0 color-mix(in srgb, var(--soot) 10%, transparent),
    0 14px 32px color-mix(in srgb, var(--soot) 30%, transparent);
}

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

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

body {
  --photo-h: max(112svh, 700px);
  --photo-y: calc(var(--photo-h) * -0.12);
  margin: 0;
  min-height: 100dvh;
  color: var(--soot);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
  background:
    linear-gradient(180deg, transparent 72%, var(--walnut)) center var(--photo-y) / 100% var(--photo-h) no-repeat,
    url("../assets/table.jpg") center var(--photo-y) / auto var(--photo-h) no-repeat,
    var(--walnut);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
}

.skip {
  position: absolute;
  left: 12px;
  top: 0;
  z-index: 30;
  padding: 8px 12px;
  border-radius: 0 0 8px 8px;
  background: var(--oxblood);
  color: var(--bone);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-120%);
}

.skip:focus {
  transform: none;
}

/* Portrait: name, board, then the paper cards, stacked. */

.app {
  --now-h: 104px;
  --board-w: min(100%, calc((100svh - var(--head) - 36px - var(--now-h)) * 5 / 7), 36rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: var(--board-w);
  height: var(--head);
  color: var(--bone);
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 30px;
  font-optical-sizing: auto;
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.lede {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: color-mix(in srgb, var(--bone) 80%, transparent);
  white-space: nowrap;
}

.deal {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--btn-radius);
  background: var(--chip);
  color: var(--soot);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 150ms var(--ease);
}

.deal::before {
  content: "";
  position: absolute;
  inset: -4px 0;
}

.deal:active {
  background: var(--chip-press);
}

.stage {
  width: var(--board-w);
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 1.4vmin, 9px);
  width: 100%;
  aspect-ratio: 5 / 7;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: var(--board-w);
}

.now,
.howto {
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--bone);
  box-shadow: var(--lift);
}

/* Seats and cards */

.seat {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 7% / 5%;
  outline: 2px solid transparent;
  outline-offset: 2px;
  background: color-mix(in srgb, var(--soot) 22%, transparent);
  box-shadow: inset 0 1px 3px color-mix(in srgb, var(--soot) 28%, transparent);
  cursor: default;
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  transition: background-color 150ms var(--ease), outline-color 150ms var(--ease);
}

.seat[data-legal="true"] {
  background: color-mix(in srgb, var(--straw) 32%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bone) 30%, transparent);
  cursor: pointer;
}

.seat[data-legal="true"]:active {
  background: color-mix(in srgb, var(--straw) 58%, transparent);
}

.seat.is-selected,
.seat:focus-visible {
  outline: 2px solid var(--bone);
  outline-offset: 2px;
  z-index: 1;
}

.seat.is-flying {
  z-index: 4;
}

.seat[data-occupied="true"] {
  background: transparent;
  box-shadow: none;
}

.face {
  container-type: size;
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 7% / 5%;
  background: var(--bone);
  color: var(--soot);
  outline: 2px solid transparent;
  outline-offset: -3px;
  box-shadow:
    0 1px 0 color-mix(in srgb, var(--soot) 12%, transparent),
    0 8px 16px color-mix(in srgb, var(--soot) 22%, transparent);
  transition: outline-color 150ms var(--ease);
}

.face.is-coral {
  color: var(--oxblood);
}

.seat.is-neighbor .face {
  outline-color: var(--oxblood);
}

.face .idx {
  position: absolute;
  top: 6cqh;
  left: 8cqw;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--font-display);
  font-size: max(13px, 12.5cqh);
  font-weight: 700;
  line-height: 0.92;
}

.face .idx .s {
  margin-top: 0.12em;
  font-size: 0.74em;
  line-height: 1;
}

.face .idx.br {
  top: auto;
  left: auto;
  right: 8cqw;
  bottom: 6cqh;
  transform: rotate(180deg);
}

.face .pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 30cqh;
  line-height: 1;
}

@container (max-height: 124px) {
  .face .idx .s,
  .face .idx.br {
    display: none;
  }
}

.seat.is-flying .face {
  z-index: 1;
  transition: transform 200ms var(--ease), outline-color 150ms var(--ease);
}

.face.is-dealt {
  animation: deal-in 180ms var(--ease) both;
}

@keyframes deal-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.seat.is-leaving .face {
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease), outline-color 150ms var(--ease);
}

/* The deal: deck, last draw, and what just happened */

.now {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 16px;
  align-items: center;
}

.piles {
  display: flex;
  gap: 8px;
}

.pile {
  display: grid;
  justify-items: center;
  gap: 5px;
  margin: 0;
}

.pile figcaption {
  font-size: 13px;
  line-height: 16px;
  color: var(--muted);
}

.deck,
.drawn-face {
  width: var(--mini-w);
  aspect-ratio: 5 / 7;
  border-radius: 7% / 5%;
}

.deck {
  display: grid;
  place-items: center;
  background: var(--oxblood);
  color: var(--bone);
  box-shadow:
    inset 0 0 0 3px var(--bone),
    0 1px 0 color-mix(in srgb, var(--soot) 12%, transparent),
    0 6px 12px color-mix(in srgb, var(--soot) 22%, transparent);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
}

.drawn-face.is-empty {
  border: 1.5px dashed color-mix(in srgb, var(--soot) 24%, transparent);
}

.drawn-face .face.is-drawn {
  animation: draw-in 200ms var(--ease);
}

@keyframes draw-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.now-text {
  min-width: 0;
}

.result,
.status {
  margin: 0;
  font-size: 16px;
  line-height: 22px;
  text-wrap: pretty;
}

.result {
  font-weight: 600;
}

.result[data-tone="miss"] {
  color: var(--oxblood);
}

.result:not(:empty) + .status {
  display: none;
}

.status {
  font-weight: 500;
}

.meta {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 18px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.again {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 12px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--btn-radius);
  background: var(--oxblood);
  color: var(--bone);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 150ms var(--ease);
}

.again:active {
  background: color-mix(in srgb, var(--oxblood) 70%, var(--soot));
}

.result[data-tone="win"] ~ .again,
.result[data-tone="empty"] ~ .again {
  display: inline-flex;
}

.result.is-in {
  animation: reveal-in 180ms var(--ease);
}

@keyframes reveal-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

body.is-won .result {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 26px;
  font-weight: 700;
  color: var(--oxblood);
}

/* How to play */

.howto h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.howto > p {
  margin: 6px 0 0;
  font-size: 15px;
  line-height: 21px;
  text-wrap: pretty;
}

.rules {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.rules li {
  display: grid;
  grid-template-columns: 31px minmax(0, 1fr);
  column-gap: 14px;
  align-items: center;
  font-size: 15px;
  line-height: 20px;
}

.rules b {
  display: block;
  font-weight: 600;
}

.mini {
  display: grid;
  grid-template-columns: repeat(3, 9px);
  grid-template-rows: repeat(3, 12px);
  gap: 2px;
}

.mini i {
  border-radius: 2px;
}

.mini .c {
  background: color-mix(in srgb, var(--soot) 72%, var(--bone));
}

.mini .o {
  background: color-mix(in srgb, var(--soot) 26%, var(--bone));
}

.mini .s {
  box-shadow: inset 0 0 0 1.5px var(--oxblood);
}

.howto > .fine {
  margin-top: 10px;
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
}

.howto > .keyhint {
  display: none;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
  font-size: 13px;
  line-height: 26px;
  color: var(--muted);
}

.keyhint kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin: 0 1px;
  padding: 0 6px;
  border-radius: 5px;
  background: var(--chip);
  color: var(--soot);
  font: 600 13px/1 var(--font-body);
  vertical-align: middle;
}

/* The guess */

.guess-tray {
  position: fixed;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: max-content;
  max-width: min(20rem, calc(100vw - 16px));
  padding: var(--tray-pad);
  border-radius: var(--tray-radius);
  background: var(--bone);
  color: var(--soot);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--soot) 26%, transparent);
  transform-origin: top center;
  opacity: 1;
  transform: none;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}

.guess-tray[hidden] {
  display: none;
}

.guess-tray.is-instant {
  transition: none;
}

@starting-style {
  .guess-tray {
    opacity: 0;
    transform: translateY(4px) scale(0.98);
  }
}

.guess-tray.is-out {
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  pointer-events: none;
  transition-duration: 120ms;
}

.guess-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  width: 0;
  min-width: 100%;
}

.guess-prompt {
  margin: 0;
  padding: 4px 0 0 4px;
  font-size: 15px;
  font-weight: 500;
  line-height: 21px;
  text-wrap: pretty;
}

.guess-close {
  position: relative;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -4px -4px 0 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: color-mix(in srgb, var(--soot) 72%, transparent);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}

.guess-close::before {
  content: "";
  position: absolute;
  inset: -6px;
}

.guess-close svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.guess-close:active {
  background: var(--chip-press);
}

.guess-actions {
  display: flex;
  gap: 8px;
}

.guess-actions button {
  display: inline-flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: max-content;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--btn-radius);
  background: var(--oxblood);
  color: var(--bone);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 150ms var(--ease);
}

.guess-actions button:active {
  background: color-mix(in srgb, var(--oxblood) 70%, var(--soot));
}

.key {
  display: none;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--bone);
  color: var(--soot);
  font: 700 13px/1 var(--font-display);
}

/* Focus and hover */

:focus {
  outline: none;
}

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

.seat:focus-visible {
  outline-color: var(--bone);
}

@media (hover: hover) and (pointer: fine) {
  .seat[data-legal="true"]:hover {
    background: color-mix(in srgb, var(--straw) 46%, transparent);
  }

  .guess-actions button:hover {
    background: color-mix(in srgb, var(--oxblood) 84%, var(--soot));
  }

  .deal:hover {
    background: var(--chip-hover);
  }

  .guess-close:hover {
    background: var(--chip);
    color: var(--soot);
  }

  .again:hover {
    background: color-mix(in srgb, var(--oxblood) 84%, var(--soot));
  }

  .key {
    display: grid;
  }

  .howto > .keyhint {
    display: block;
  }
}

/* Portrait tweaks */

@media (max-width: 359px) {
  .lede {
    display: none;
  }
}

@media (min-width: 600px) {
  h1 {
    font-size: 34px;
  }
}

@media (max-width: 640px) {
  .guess-tray.is-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto;
    max-width: none;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -12px 32px color-mix(in srgb, var(--soot) 38%, transparent);
    transform-origin: bottom center;
    padding-bottom: calc(var(--tray-pad) + env(safe-area-inset-bottom));
    transition-duration: 220ms;
  }

  @starting-style {
    .guess-tray.is-sheet {
      opacity: 0;
      transform: translateY(16px);
    }
  }

  .guess-tray.is-sheet.is-out {
    transform: translateY(12px);
    transition-duration: 140ms;
  }
}

/* Landscape: board on the left, one paper card on the right. */

@media (min-aspect-ratio: 4/3), (min-width: 800px) and (min-aspect-ratio: 5/6) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    height: 100dvh;
    min-height: 0;
    background: url("../assets/table.jpg") center bottom / max(100%, 210vh) auto no-repeat, var(--walnut);
  }

  .app {
    --mini-w: 48px;
    --pad: clamp(16px, 4vh, 40px);
    --gap: clamp(20px, 3vw, 44px);
    --panel-min: 16rem;
    --board-w: min(
      calc((100dvh - 2 * var(--pad)) * 5 / 7),
      calc(100vw - 2 * var(--pad) - var(--gap) - var(--panel-min))
    );
    display: grid;
    grid-template-columns: var(--board-w) minmax(var(--panel-min), min(20rem, var(--board-w)));
    grid-template-rows: auto minmax(0, auto) minmax(0, 1fr);
    grid-template-areas:
      "stage brand"
      "stage panel"
      "stage .";
    column-gap: var(--gap);
    align-items: stretch;
    justify-content: center;
    height: 100dvh;
    padding: var(--pad);
  }

  .app::before {
    content: "";
    grid-column: 2;
    grid-row: 1 / 3;
    border-radius: var(--card-radius);
    background: var(--bone);
    box-shadow: var(--lift);
  }

  .brand {
    grid-area: brand;
    display: block;
    width: auto;
    height: auto;
    padding: 24px 24px 0;
    color: var(--soot);
  }

  .brand-text {
    display: block;
  }

  h1 {
    font-size: clamp(30px, 2.4vw, 36px);
    line-height: 0.95;
    letter-spacing: -0.03em;
  }

  .lede {
    display: block;
    margin-top: 6px;
    font-size: 15px;
    color: var(--muted);
  }

  .deal {
    margin-top: 14px;
  }

  .stage {
    grid-area: stage;
    align-self: start;
    width: var(--board-w);
  }

  .panel {
    grid-area: panel;
    gap: 18px;
    width: auto;
    min-height: 0;
    padding: 20px 24px 24px;
    overflow: auto;
    overscroll-behavior: contain;
    border-radius: 0 0 var(--card-radius) var(--card-radius);
  }

  .panel.is-clipped {
    -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 36px), transparent);
    mask-image: linear-gradient(to bottom, black calc(100% - 36px), transparent);
  }

  .now,
  .howto {
    padding: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
  }

  .howto {
    padding-top: 18px;
    border-top: 1px solid var(--hairline);
  }
}

@media (min-aspect-ratio: 4/3) and (max-height: 820px), (min-width: 800px) and (min-aspect-ratio: 5/6) and (max-height: 820px) {
  .brand {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 12px;
    padding: 18px 20px 0;
  }

  .lede {
    display: none;
  }

  h1 {
    font-size: 28px;
  }

  .deal {
    margin-top: 0;
  }

  .panel {
    padding: 18px 20px 20px;
  }
}

@media (min-aspect-ratio: 4/3) and (max-height: 520px) {
  .app {
    --mini-w: 40px;
  }

  .brand {
    column-gap: 8px;
    padding: 14px 16px 0;
  }

  h1 {
    font-size: 24px;
  }

  .deal {
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
  }

  .panel {
    gap: 14px;
    padding: 14px 16px 18px;
  }

  .howto {
    padding-top: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .seat,
  .face,
  .seat.is-flying .face,
  .seat.is-leaving .face,
  .face.is-dealt,
  .drawn-face .face.is-drawn,
  .guess-tray,
  .guess-actions button,
  .deal,
  .result.is-in {
    animation: none;
    transition: none;
  }
}
