:root {
  --felt: #0d3327;
  --felt-light: #14503c;
  --line: rgba(255, 255, 255, 0.13);
  --ink: #f3efe2;
  --dim: rgba(243, 239, 226, 0.62);
  --gold: #e6b84c;
  --mine: #57b6ff;
  --theirs: #ff9a4a;
  --card: #fbf8ef;
  --black: #1d2530;
  --red: #c8323c;
  /* Seven rows of cards, two hands and the bars have to fit the height. */
  --card-w: min(15.5vw, 6.1vh, 86px);
  --card-h: calc(var(--card-w) * 1.4);
  --gap: calc(var(--card-w) * 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: radial-gradient(ellipse at 50% 35%, var(--felt-light), var(--felt) 70%) fixed;
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.panel {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px 24px;
  background: rgba(6, 26, 20, 0.72);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: 0.01em;
}

h1 {
  font-size: 2.3rem;
}

h1 span {
  color: var(--gold);
  font-style: italic;
  font-weight: 400;
}

h2 {
  font-size: 1.6rem;
}

h3 {
  margin: 14px 0 4px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}

p {
  margin: 0;
  color: var(--dim);
}

.tagline {
  margin-bottom: 10px;
}

/* The first screens scroll when a small phone can't hold them. */
#home,
#waiting {
  justify-content: flex-start;
  overflow-y: auto;
}

#home .panel,
#waiting .panel {
  margin: auto 0;
}

/* One of a few, side by side. */
.choice {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}

.choice button {
  padding: 9px 4px;
  font-weight: 500;
}

.choice button[aria-checked="true"] {
  background: rgba(230, 184, 76, 0.2);
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 700;
}

#recent {
  text-align: left;
}

.recent {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.recent button {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  font-weight: 500;
  text-align: left;
}

.good {
  color: #9be0a0;
}

.bad {
  color: #ffa596;
}

button.round {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
}

.panel.rules {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  text-align: left;
}

.rules h2 {
  text-align: center;
}

.scroll {
  overflow-y: auto;
  padding-right: 6px;
}

.scroll p + p {
  margin-top: 8px;
}

.scroll ol {
  margin: 0;
  padding-left: 1.3em;
  color: var(--dim);
}

.scroll li + li {
  margin-top: 6px;
}

.scroll b {
  color: var(--ink);
}

/* The cards of a stack, laid out side by side. */
.spread {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
  padding: 6px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font-size: 0.85rem;
  color: var(--dim);
}

input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font: inherit;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button {
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.09);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #2a1d00;
}

button.primary:hover:not(:disabled) {
  background: #f1c964;
}

button.quiet {
  background: none;
  border-color: transparent;
  color: var(--dim);
  font-weight: 500;
}

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

.join input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
}

.code {
  font: 700 3rem/1.1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.25em;
  padding-left: 0.25em;
  color: var(--gold);
}

/* ------------------------------------------------------------------ game */

#game {
  justify-content: space-between;
  gap: var(--gap);
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
}

.side {
  width: min(100%, max(calc(var(--card-w) * 5 + var(--gap) * 6 + 24px), 400px));
  display: flex;
  align-items: center;
  gap: 10px;
}

.side.theirs {
  justify-content: space-between;
}

.side.mine {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.who {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.name::before {
  content: "";
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  margin-right: 0.45em;
  border-radius: 50%;
  background: var(--theirs);
}

.note {
  font-size: 0.8rem;
  color: var(--dim);
}

.backs {
  display: flex;
}

.back,
.deck {
  background: repeating-linear-gradient(45deg, #7a2030, #7a2030 4px, #8d2a3b 4px, #8d2a3b 8px);
  border: 2px solid var(--card);
  border-radius: calc(var(--card-w) * 0.1);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
}

.back {
  width: calc(var(--card-w) * 0.5);
  height: calc(var(--card-h) * 0.5);
  margin-left: calc(var(--card-w) * -0.2);
}

.back:first-child {
  margin-left: 0;
}

.deck {
  flex: none;
  width: calc(var(--card-w) * 0.72);
  height: calc(var(--card-h) * 0.72);
  display: grid;
  place-items: center;
  color: var(--card);
  font-weight: 700;
  font-size: calc(var(--card-w) * 0.28);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.deck.empty {
  background: none;
  border-style: dashed;
  border-color: var(--line);
  box-shadow: none;
  color: var(--dim);
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
}

.status {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status.yours {
  color: var(--gold);
}

.actions {
  display: flex;
  gap: 6px;
}

.actions button {
  padding: 8px 12px;
}

.tray {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
}

.hand {
  display: flex;
  gap: var(--gap);
  min-height: var(--card-h);
}

/* ----------------------------------------------------------------- board */

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, var(--card-w));
  grid-template-rows: repeat(7, var(--card-h));
  gap: var(--gap);
  padding: var(--gap);
  border: 1px solid var(--line);
  border-radius: calc(var(--card-w) * 0.2);
  background: rgba(0, 0, 0, 0.16);
}

.cell {
  position: relative;
  border-radius: calc(var(--card-w) * 0.1);
  border: 1px dashed rgba(255, 255, 255, 0.1);
}

.cell.middle {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.18);
}

/* Whoever holds a lane's advantage attacks across its middle. */
.cell.middle.adv-mine {
  border-color: var(--mine);
  box-shadow: inset 0 0 0 1px var(--mine);
}

.cell.middle.adv-theirs {
  border-color: var(--theirs);
  box-shadow: inset 0 0 0 1px var(--theirs);
}

.advantage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--card-w) * 0.4);
  line-height: 1;
  pointer-events: none;
}

.adv-mine .advantage {
  color: var(--mine);
}

.adv-theirs .advantage {
  color: var(--theirs);
}

/* Over the cards swept into the middle, the arrow is a badge on the corner. */
.cell.stacked .advantage {
  inset: auto auto calc(var(--card-w) * -0.1) calc(var(--card-w) * -0.1);
  z-index: 4;
  width: calc(var(--card-w) * 0.36);
  height: calc(var(--card-w) * 0.36);
  border: 1.5px solid var(--card);
  border-radius: 50%;
  color: var(--black);
  font-size: calc(var(--card-w) * 0.19);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.cell.stacked.adv-mine .advantage {
  background: var(--mine);
}

.cell.stacked.adv-theirs .advantage {
  background: var(--theirs);
}

.cell.target {
  border-color: transparent;
  background: rgba(230, 184, 76, 0.2);
  cursor: pointer;
}

/* Where the card in hand can go. The ring is drawn over the cards, so that
   it shows as well on a stack as on an empty row. */
.ring {
  position: absolute;
  inset: -2px;
  z-index: 3;
  border: 3px solid var(--gold);
  border-radius: calc(var(--card-w) * 0.14);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5), 0 0 14px 4px rgba(230, 184, 76, 0.85),
    inset 0 0 10px rgba(230, 184, 76, 0.55);
  pointer-events: none;
  animation: beckon 1.1s ease-in-out infinite;
}

.cell.covering .ring {
  background: rgba(230, 184, 76, 0.34);
}

.cell.hinted .ring {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5), 0 0 14px 4px rgba(243, 239, 226, 0.8);
}

@keyframes beckon {
  50% {
    transform: scale(1.05);
  }
}

/* While a card is in hand, everything it can't go on steps back. */
.board.choosing .cell:not(.target) .card {
  filter: brightness(0.5) saturate(0.6);
}

.board.choosing .won,
.board.choosing .cell:not(.target) .count {
  opacity: 0.45;
}

/* How many cards are in a stack; tap it to see them. */
button.count {
  position: absolute;
  top: calc(var(--card-w) * -0.1);
  right: calc(var(--card-w) * -0.1);
  z-index: 4;
  min-width: calc(var(--card-w) * 0.36);
  height: calc(var(--card-w) * 0.36);
  padding: 0 calc(var(--card-w) * 0.08);
  border: 1.5px solid var(--card);
  border-radius: 999px;
  background: var(--black);
  color: var(--card);
  font-size: calc(var(--card-w) * 0.22);
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

button.count:hover:not(:disabled) {
  background: #36414f;
}

/* A bigger place to tap than the badge is to look at. */
button.count::before {
  content: "";
  position: absolute;
  inset: -8px;
}

.cell .card {
  position: absolute;
  /* Cards lower in a stack peek out above the one on top of them. */
  top: calc(var(--depth, 0) * var(--card-h) * -0.045);
  left: 0;
}

.won {
  grid-row: 1 / -1;
  display: grid;
  place-items: center;
  border-radius: calc(var(--card-w) * 0.1);
  writing-mode: vertical-rl;
  letter-spacing: 0.2em;
  font-weight: 700;
  font-size: calc(var(--card-w) * 0.24);
  text-transform: uppercase;
}

.won.mine {
  background: linear-gradient(rgba(87, 182, 255, 0.08), rgba(87, 182, 255, 0.32));
  color: var(--mine);
  border: 1px solid var(--mine);
}

.won.theirs {
  background: linear-gradient(rgba(255, 154, 74, 0.32), rgba(255, 154, 74, 0.08));
  color: var(--theirs);
  border: 1px solid var(--theirs);
}

/* ----------------------------------------------------------------- cards */

.card {
  position: relative;
  flex: none;
  width: var(--card-w);
  height: var(--card-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--card-w) * 0.1);
  background: var(--card);
  color: var(--black);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  user-select: none;
}

.card.red {
  color: var(--red);
}

.card .rank {
  font-size: calc(var(--card-w) * 0.46);
  font-weight: 700;
}

.card .suit {
  font-size: calc(var(--card-w) * 0.4);
}

/* A bar on the edge nearest the player who played the card. */
.card.mine {
  box-shadow: inset 0 calc(var(--card-w) * -0.07) 0 var(--mine), 0 2px 5px rgba(0, 0, 0, 0.4);
}

.card.theirs {
  box-shadow: inset 0 calc(var(--card-w) * 0.07) 0 var(--theirs), 0 2px 5px rgba(0, 0, 0, 0.4);
}

.card.pending {
  outline: 2px solid var(--gold);
  opacity: 0.85;
}

/* The cards the last move put down. */
.card.last::before {
  content: "";
  position: absolute;
  top: 7%;
  left: 9%;
  width: 17%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.35), 0 0 6px 1px rgba(230, 184, 76, 0.9);
}

/* The opponent's hand, face up, in a game watched again. */
.card.mini {
  width: calc(var(--card-w) * 0.5);
  height: calc(var(--card-h) * 0.5);
  margin-left: 2px;
}

.card.mini .rank {
  font-size: calc(var(--card-w) * 0.25);
}

.card.mini .suit {
  font-size: calc(var(--card-w) * 0.2);
}

.hand .card {
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
}

.hand .card.unplayable {
  opacity: 0.45;
  cursor: default;
}

.hand .card.selected {
  transform: translateY(calc(var(--card-h) * -0.16));
  outline: 3px solid var(--gold);
}

@media (hover: hover) {
  .hand .card:not(.unplayable):not(.selected):hover {
    transform: translateY(calc(var(--card-h) * -0.07));
  }
}

/* ---------------------------------------------------------------- replay */

/* Watching a game again puts more under the board, so the cards give way. */
#game.watching {
  --card-w: min(15.5vw, 5.2vh, 86px);
  --card-h: calc(var(--card-w) * 1.4);
  --gap: calc(var(--card-w) * 0.12);
}

#replay-more {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#replay-more .actions {
  justify-content: space-between;
}

#replay-more button {
  padding: 7px 10px;
  white-space: nowrap;
}

/* What the move was; long names take a second line. */
#replay-caption {
  font-size: 0.85rem;
  line-height: 1.2;
  white-space: normal;
}

.steps button {
  width: 34px;
  padding: 6px 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.graph {
  position: relative;
  height: 36px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
  cursor: pointer;
}

.graph svg {
  display: block;
  width: 100%;
  height: 100%;
}

.graph span {
  position: absolute;
  top: 2px;
  left: 6px;
  font-size: 0.68rem;
  color: var(--dim);
  pointer-events: none;
}

.graph * {
  vector-effect: non-scaling-stroke;
}

.graph .half {
  stroke: var(--line);
  stroke-dasharray: 3 3;
}

.graph .area {
  fill: rgba(87, 182, 255, 0.14);
}

.graph .chance {
  fill: none;
  stroke: var(--mine);
  stroke-width: 2;
  stroke-linejoin: round;
}

.graph .turn {
  stroke: var(--gold);
  stroke-width: 2;
  stroke-dasharray: 2 3;
}

.graph .now {
  stroke: var(--ink);
  stroke-width: 2;
}

#flights {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

#flights .card {
  position: fixed;
}

/* --------------------------------------------------------------- overlay */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 14, 10, 0.6);
  backdrop-filter: blur(3px);
  z-index: 10;
  animation: fade 0.3s;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--card-h) + 90px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(10, 10, 10, 0.88);
  border: 1px solid var(--line);
  font-weight: 600;
  text-align: center;
  z-index: 20;
  animation: fade 0.2s;
}

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