/* Hand Cards: the Live Hand Seeker strip under the South Rack and the Hands reference. */

.hand-seeker {
  --hs-ivory: #f4ecd6;
  --hs-ivory-edge: #cbbd98;
  --hs-ink: #1f3a2e;
  --hs-ink-soft: rgba(31, 58, 46, 0.66);
  --hs-gold: #e2bf63;
  --hs-gold-deep: #9a7426;
  --hs-ghost: rgba(236, 232, 216, 0.72);
  --hs-gap: 0.5rem;
  --hs-card-h: 4.15rem;
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-width: 0;
}

.hand-seeker[hidden] {
  display: none;
}

.hs-strip {
  position: relative;
  grid-column: 1;
  grid-row: 1;
  display: grid;
  width: 0;
  min-width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--hs-gap);
  min-height: var(--hs-card-h);
  margin: 0;
  padding: 0;
  list-style: none;
}

.hs-strip:has(> .hs-card:nth-child(4):not(.is-leaving)) {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.hs-note {
  grid-column: 1;
  grid-row: 1;
  justify-self: center;
  margin: 0;
  color: rgba(232, 238, 230, 0.48);
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.hs-note[hidden] {
  display: none;
}

.hs-card {
  --c: 0.5;
  position: relative;
  min-width: 0;
  container-type: inline-size;
  transition:
    translate 0.46s cubic-bezier(0.22, 0.8, 0.24, 1),
    opacity 0.38s ease,
    transform 0.38s cubic-bezier(0.22, 0.8, 0.24, 1);
}

.hs-card.is-entering {
  opacity: 0;
  transform: translateY(10px) scale(0.9);
  transition: none;
}

.hs-card.is-leaving {
  position: absolute;
  margin: 0;
  pointer-events: none;
  animation: hs-leave 0.42s ease forwards;
}

.hs-card-body {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "name bonus"
    "pips pips"
    "progress away";
  align-content: center;
  gap: 0.26rem 0.4rem;
  box-sizing: border-box;
  width: 100%;
  height: var(--hs-card-h);
  margin: 0;
  padding: 0.42rem 0.6rem 0.46rem;
  overflow: hidden;
  border: 1px dashed rgba(244, 236, 214, 0.26);
  border-radius: 0.62rem;
  background: rgba(244, 236, 214, calc(0.03 + 0.08 * var(--c)));
  color: var(--hs-ghost);
  font: inherit;
  text-align: left;
  cursor: pointer;
  opacity: calc(0.42 + 0.58 * var(--c));
  filter: saturate(calc(0.35 + 0.65 * var(--c)));
  transform: translateY(calc((1 - var(--c)) * 2px)) scale(calc(0.95 + 0.05 * var(--c)));
  transition:
    background-color 0.45s ease,
    border-color 0.45s ease,
    color 0.45s ease,
    box-shadow 0.45s ease,
    opacity 0.45s ease,
    filter 0.45s ease,
    transform 0.45s cubic-bezier(0.22, 0.8, 0.24, 1);
  -webkit-tap-highlight-color: transparent;
}

.hs-card-body:focus-visible {
  outline: 2px solid var(--hs-gold);
  outline-offset: 2px;
}

.hs-card-head,
.hs-card-foot {
  display: contents;
}

.hs-card-name {
  grid-area: name;
  min-width: 0;
  overflow: hidden;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  line-height: 1.1;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.hs-card-bonus {
  grid-area: bonus;
  font-size: 0.9rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1;
}

.hs-card-suit {
  display: none;
}

.hs-pips {
  grid-area: pips;
  display: flex;
  gap: 2px;
  min-width: 0;
  height: 0.3rem;
}

.hs-pip {
  flex: 1 1 0;
  min-width: 0;
  max-width: 1.6rem;
  border-radius: 999px;
  background: rgba(244, 236, 214, 0.16);
  transition: background-color 0.45s ease;
}

.hs-pip.is-on {
  background: rgba(244, 236, 214, 0.62);
}

.hs-card-progress,
.hs-card-away {
  min-width: 0;
  overflow: hidden;
  font-size: 0.62rem;
  font-weight: 650;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hs-card-progress {
  grid-area: progress;
  opacity: 0.86;
}

.hs-card-away {
  grid-area: away;
  font-weight: 800;
  text-align: right;
}

.hs-card-check {
  position: absolute;
  top: 0.34rem;
  right: 0.42rem;
  display: grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: var(--hs-ink);
  color: var(--hs-gold);
  font-size: 0.7rem;
  font-weight: 900;
  line-height: 1;
  opacity: 0;
  transform: scale(0.3) rotate(-20deg);
  transition: opacity 0.2s ease, transform 0.32s cubic-bezier(0.3, 1.6, 0.5, 1);
}

/* Tiers: a speculative Hand is a ghost; a strong one is card stock; ready and complete glow gold. */

.hs-card[data-tier="possible"] .hs-card-body {
  border-style: solid;
  border-color: rgba(244, 236, 214, 0.32);
}

.hs-card:is([data-tier="strong"], [data-tier="ready"], [data-tier="complete"]) .hs-card-body {
  border: 1px solid var(--hs-ivory-edge);
  background: var(--hs-ivory);
  color: var(--hs-ink);
  opacity: 1;
  filter: none;
  transform: translateY(-2px);
  box-shadow:
    0 3px 0 var(--hs-ivory-edge),
    0 8px 16px rgba(5, 16, 11, 0.34);
}

.hs-card:is([data-tier="strong"], [data-tier="ready"], [data-tier="complete"]) :is(.hs-card-progress) {
  color: var(--hs-ink-soft);
}

.hs-card:is([data-tier="strong"], [data-tier="ready"], [data-tier="complete"]) .hs-card-bonus {
  color: var(--hs-gold-deep);
}

.hs-card:is([data-tier="strong"], [data-tier="ready"], [data-tier="complete"]) .hs-pip {
  background: rgba(31, 58, 46, 0.14);
}

.hs-card:is([data-tier="strong"], [data-tier="ready"], [data-tier="complete"]) .hs-pip.is-on {
  background: #377159;
}

.hs-card[data-tier="ready"] .hs-card-body {
  border-color: var(--hs-gold);
  box-shadow:
    0 3px 0 #c9a44c,
    0 0 0 1px rgba(226, 191, 99, 0.6),
    0 8px 20px rgba(226, 191, 99, 0.22);
  animation: hs-ready 2.4s ease-in-out infinite;
}

.hs-card[data-tier="ready"] .hs-pip.is-on {
  background: #c9a44c;
}

.hs-card[data-tier="complete"] .hs-card-body,
.hs-card.is-resolved .hs-card-body {
  border-color: #c9a44c;
  background: #f1d886;
  color: var(--hs-ink);
  box-shadow:
    0 3px 0 #b48c35,
    0 0 0 1px rgba(255, 226, 122, 0.7),
    0 10px 24px rgba(226, 191, 99, 0.3);
}

.hs-card[data-tier="complete"] .hs-card-bonus,
.hs-card.is-resolved .hs-card-bonus {
  color: var(--hs-ink);
}

.hs-card[data-tier="complete"] .hs-pip.is-on,
.hs-card.is-resolved .hs-pip.is-on {
  background: var(--hs-ink);
}

.hs-card.is-resolved .hs-card-check {
  opacity: 1;
  transform: none;
}

.hs-card.is-resolved .hs-card-bonus {
  margin-right: 1.3rem;
}

.hs-card.is-won:not(.is-resolved) .hs-card-body {
  animation: none;
}

.hs-card.is-surge .hs-card-body {
  animation: hs-surge 0.82s cubic-bezier(0.22, 0.8, 0.24, 1);
}

.hs-card.is-surge .hs-card-body::after,
.hs-card.is-stamp .hs-card-body::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 34%;
  background: rgba(255, 252, 238, 0.42);
  transform: translateX(-120%) skewX(-16deg);
  animation: hs-sheen 0.8s ease-out forwards;
  pointer-events: none;
}

.hs-card.is-stamp .hs-card-body {
  animation: hs-stamp 0.5s cubic-bezier(0.3, 1.5, 0.5, 1);
}

@media (hover: hover) and (pointer: fine) {
  .hs-card-body:hover {
    opacity: calc(0.62 + 0.38 * var(--c));
  }

  .hs-card:is([data-tier="strong"], [data-tier="ready"], [data-tier="complete"]) .hs-card-body:hover {
    transform: translateY(-4px);
  }
}

/* Narrower cards stack the name under the multiplier. */

@container (max-width: 11.5rem) {
  .hs-card-body {
    grid-template-areas:
      "bonus away"
      "name name"
      "pips pips";
    gap: 0.24rem 0.3rem;
  }

  .hs-card-name {
    font-size: 0.6rem;
    letter-spacing: 0.05em;
  }

  .hs-card-progress {
    display: none;
  }

  .hs-card-away {
    align-self: center;
    font-size: 0.58rem;
  }
}

@container (max-width: 8.5rem) {
  .hs-card-body {
    grid-template-areas:
      "bonus suit"
      "name name"
      "pips pips";
    gap: 0.2rem 0.3rem;
    padding: 0.3rem 0.4rem 0.36rem;
    border-radius: 0.5rem;
  }

  .hs-card-name {
    display: -webkit-box;
    font-size: 0.54rem;
    letter-spacing: 0.04em;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  .hs-card-bonus {
    font-size: 0.78rem;
  }

  .hs-card-suit {
    grid-area: suit;
    display: block;
    justify-self: end;
    align-self: center;
    font-size: 0.54rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.8;
  }

  .hs-card-suit[hidden],
  .hs-card.is-resolved .hs-card-suit {
    display: none;
  }

  .hs-card-away {
    display: none;
  }

  .hs-pips {
    height: 0.24rem;
  }

  .hs-card-check {
    top: 0.26rem;
    right: 0.3rem;
    width: 0.95rem;
    height: 0.95rem;
    font-size: 0.58rem;
  }
}

/* Hands button */

.hs-open {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.28rem;
  min-width: 3rem;
  height: var(--hs-card-h);
  margin: 0 0 0 var(--hs-gap);
  padding: 0 0.5rem;
  border: 1px solid rgba(244, 236, 214, 0.18);
  border-radius: 0.62rem;
  background: rgba(12, 22, 18, 0.5);
  color: rgba(244, 236, 214, 0.86);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.hs-open:hover,
.hs-open:focus-visible {
  border-color: rgba(226, 191, 99, 0.6);
  background: rgba(12, 22, 18, 0.72);
}

.hs-open:focus-visible {
  outline: 2px solid var(--hs-gold);
  outline-offset: 2px;
}

.hs-open-icon {
  position: relative;
  width: 1.05rem;
  height: 1.3rem;
}

.hs-open-icon::before,
.hs-open-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.5px solid currentColor;
  border-radius: 0.2rem;
}

.hs-open-icon::before {
  opacity: 0.5;
  transform: translate(-3px, 2px) rotate(-9deg);
}

.hs-open-icon::after {
  background: rgba(12, 22, 18, 0.9);
  transform: translate(2px, -1px) rotate(6deg);
}

.hs-open-label {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Placement around the table */

@media (min-width: 1408px) {
  .table-frame.has-seeker {
    --south-y: clamp(4.9rem, 8.6vmin, 5.6rem);
    grid-template-rows: var(--top-chrome) auto var(--south-y);
  }

  .table-frame.has-seeker .table {
    width: min(
      calc(100cqw - (2 * var(--id-x))),
      calc(100cqh - var(--top-chrome) - var(--south-y) - var(--shadow-room))
    );
  }

  .table-frame.has-seeker .player-id[data-seat="south"] {
    grid-area: auto;
    grid-column: 1;
    grid-row: 3;
    justify-self: end;
    align-self: center;
    margin: 0.55rem 0.5rem 0 0;
  }

  .table-frame.has-seeker .hand-seeker {
    grid-column: 2 / 4;
    grid-row: 3;
    grid-template-columns: subgrid;
    align-self: center;
    margin-top: 0.55rem;
  }
}

@media (max-width: 1407px) {
  .hand-seeker {
    --hs-card-h: 3.75rem;
    --hs-gap: 0.4rem;
  }

  .table-frame.has-seeker .player-id[data-seat="south"] {
    justify-self: start;
  }

  .table-frame.has-seeker .hand-seeker {
    grid-area: id-south;
    justify-self: stretch;
    align-self: center;
    margin-left: 6.4rem;
    padding-right: var(--play-bar-pad-x, 1rem);
  }

  .hs-card-body {
    padding: 0.36rem 0.5rem 0.4rem;
  }
}

@media (max-width: 900px) {
  .hand-seeker {
    --hs-card-h: 3.55rem;
    --hs-gap: 0.3rem;
  }

  .table-frame.has-seeker .player-id[data-seat="south"] {
    padding-left: 0.7rem;
    padding-right: 0.4rem;
  }

  .table-frame.has-seeker .player-id[data-seat="south"] .player-id-copy {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .table-frame.has-seeker .hand-seeker {
    margin-left: 2.9rem;
    padding-right: 0.6rem;
  }

  .hs-open {
    min-width: 2.3rem;
    padding: 0 0.3rem;
  }

  .hs-open-label {
    font-size: 0.5rem;
    letter-spacing: 0.04em;
  }

  .hs-note {
    font-size: 0.66rem;
    text-align: center;
  }
}

/* Scoring reveal: each bonus row resolves like a Hand Card. */

.winning-score-bonus-check {
  display: inline-grid;
  place-items: center;
  width: 0.95rem;
  height: 0.95rem;
  margin-right: 0.32rem;
  border-radius: 50%;
  background: #f1d886;
  color: #1f3a2e;
  font-size: 0.58rem;
  font-weight: 900;
  vertical-align: 0.06em;
}

.winning-score-bonus.is-in .winning-score-bonus-check {
  animation: hs-check-in 0.36s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.winning-score-bonus-mult {
  margin-right: 0.42rem;
  color: rgba(245, 222, 154, 0.78);
  font-size: 0.64rem;
  font-weight: 800;
}

@keyframes hs-check-in {
  from {
    transform: scale(0.2) rotate(-25deg);
    opacity: 0;
  }
}

/* Hands reference */

.hs-sheet {
  --hs-ivory: #f4ecd6;
  --hs-ink: #1f3a2e;
  --hs-gold: #e2bf63;
  --hs-gold-deep: #9a7426;
  width: min(46rem, calc(100vw - 2rem));
  max-width: none;
  max-height: min(88vh, 54rem);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(244, 236, 214, 0.14);
  border-radius: 1rem;
  background: #141d18;
  color: rgba(244, 240, 228, 0.94);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  font-family: "Google Sans Flex", Inter, system-ui, sans-serif;
}

.hs-sheet::backdrop {
  background: rgba(5, 10, 8, 0.62);
}

.hs-sheet[open] {
  animation: hs-sheet-in 0.26s cubic-bezier(0.22, 0.8, 0.24, 1);
}

.hs-sheet-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: inherit;
}

.hs-sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem 0.9rem;
  border-bottom: 1px solid rgba(244, 236, 214, 0.1);
}

.hs-sheet-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.hs-sheet-lede {
  max-width: 34rem;
  margin: 0.35rem 0 0;
  color: rgba(232, 238, 230, 0.66);
  font-size: 0.8rem;
  font-weight: 550;
  line-height: 1.45;
}

.hs-sheet-close {
  flex: none;
  min-height: 2rem;
  padding: 0.2rem 0.85rem;
  border: 1px solid rgba(244, 236, 214, 0.22);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 750;
  cursor: pointer;
}

.hs-sheet-close:focus-visible {
  outline: 2px solid var(--hs-gold);
  outline-offset: 2px;
}

.hs-ref-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 1rem 1.25rem 1.35rem;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}

.hs-ref {
  position: relative;
  display: grid;
  align-content: start;
  gap: 0.4rem;
  padding: 0.85rem 0.9rem 0.9rem;
  border: 1px solid #cbbd98;
  border-radius: 0.8rem;
  background: var(--hs-ivory);
  color: var(--hs-ink);
  box-shadow: 0 3px 0 #cbbd98;
  scroll-margin: 1rem;
}

.hs-ref.is-focus {
  border-color: var(--hs-gold);
  box-shadow:
    0 3px 0 #c9a44c,
    0 0 0 2px rgba(226, 191, 99, 0.75);
}

.hs-ref-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}

.hs-ref-name {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 850;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.hs-ref-bonus {
  display: grid;
  justify-items: end;
  margin: 0;
}

.hs-ref-mult {
  color: var(--hs-gold-deep);
  font-size: 1.15rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.hs-ref-points {
  color: rgba(31, 58, 46, 0.6);
  font-size: 0.62rem;
  font-weight: 700;
}

.hs-ref-summary,
.hs-ref-detail,
.hs-ref-tag,
.hs-ref-live {
  margin: 0;
}

.hs-ref-summary {
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.3;
}

.hs-ref-detail {
  color: rgba(31, 58, 46, 0.72);
  font-size: 0.76rem;
  font-weight: 550;
  line-height: 1.4;
}

.hs-ref-example {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.42rem;
  margin-top: 0.2rem;
}

.hs-ref-group {
  display: inline-flex;
  gap: 1px;
}

.hs-tile {
  display: block;
  width: 1.1rem;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.hs-ref-tag {
  justify-self: start;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: rgba(31, 58, 46, 0.08);
  color: rgba(31, 58, 46, 0.72);
  font-size: 0.64rem;
  font-weight: 750;
}

.hs-ref-live {
  order: -1;
  justify-self: start;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
  background: #377159;
  color: #f4ecd6;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.hs-ref-live:is([data-tier="ready"], [data-tier="complete"]) {
  background: #c9a44c;
  color: var(--hs-ink);
}

.hs-ref-empty {
  grid-column: 1 / -1;
  color: rgba(232, 238, 230, 0.6);
  font-size: 0.82rem;
}

@media (max-width: 640px) {
  .hs-sheet {
    width: 100vw;
    max-height: 86vh;
    margin: auto 0 0;
    border-radius: 1rem 1rem 0 0;
    border-bottom: 0;
  }

  .hs-sheet[open] {
    animation-name: hs-sheet-up;
  }

  .hs-sheet-head {
    padding: 0.95rem 1rem 0.75rem;
  }

  .hs-ref-list {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.6rem;
    padding: 0.8rem 1rem max(1.2rem, env(safe-area-inset-bottom));
  }

  .hs-tile {
    width: 1.18rem;
  }

  .hs-sheet-lede {
    font-size: 0.74rem;
  }
}

@keyframes hs-surge {
  0% {
    transform: translateY(0) scale(1);
  }
  35% {
    transform: translateY(-5px) scale(1.06);
  }
  100% {
    transform: translateY(-2px) scale(1);
  }
}

@keyframes hs-sheen {
  to {
    transform: translateX(320%) skewX(-16deg);
  }
}

@keyframes hs-stamp {
  0% {
    transform: scale(1);
  }
  40% {
    transform: translateY(-4px) scale(1.08);
  }
  100% {
    transform: translateY(-2px) scale(1);
  }
}

@keyframes hs-ready {
  0%,
  100% {
    box-shadow:
      0 3px 0 #c9a44c,
      0 0 0 1px rgba(226, 191, 99, 0.6),
      0 8px 20px rgba(226, 191, 99, 0.16);
  }
  50% {
    box-shadow:
      0 3px 0 #c9a44c,
      0 0 0 2px rgba(226, 191, 99, 0.85),
      0 8px 26px rgba(226, 191, 99, 0.34);
  }
}

@keyframes hs-leave {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.9);
  }
}

@keyframes hs-sheet-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

@keyframes hs-sheet-up {
  from {
    transform: translateY(30%);
    opacity: 0.6;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hs-card,
  .hs-card-body,
  .hs-card-check,
  .hs-pip {
    transition: none;
  }

  .hs-card[data-tier="ready"] .hs-card-body,
  .winning-score-bonus.is-in .winning-score-bonus-check,
  .hs-card.is-surge .hs-card-body,
  .hs-card.is-stamp .hs-card-body,
  .hs-sheet[open] {
    animation: none;
  }
}
