@font-face {
  font-family: "Source Han Suits";
  font-weight: 1 1000;
  font-style: oblique -90deg 90deg;
  src: url("https://jdh8.github.io/fonts/suits.woff2") format("woff2");
}

/* A deliberately plain kitchen-table look: deep felt, flat card faces, and a
   cheap patterned back. */

:root {
  --felt: #236a57;
  --felt-dark: #174f42;
  --card-bg: #fdfdf7;
  --red: #c0392b;
  --black: #1b1b1b;
  --green: #1e7a45;
  --blue: #1a74d9;
  --back: #b23a3a;
  --gold: #f1cb4b;
  --card-w: 2.7rem;
  --card-h: 3.8rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: #f6f5ed;
  background: var(--felt);
  font: 15px/1.4 "Source Han Suits", system-ui, sans-serif;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 18rem);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "header header" "main log";
}

header {
  grid-area: header;
  min-width: 0;
  padding: 0.55rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.22);
  background: rgba(0, 0, 0, 0.06);
}

h1 { margin: 0; font-size: 1.22rem; letter-spacing: 0.02em; }
.score { opacity: 0.9; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.broken {
  color: rgba(255, 255, 255, 0.24);
  font-size: 1.25rem;
  line-height: 1;
  filter: grayscale(1);
  transition: color 0.2s, filter 0.2s, text-shadow 0.2s;
}
.broken.lit { color: #ff756d; filter: none; text-shadow: 0 0 0.55rem rgba(255, 80, 70, 0.7); }

.difficulty,
.quiet {
  flex: none;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 5px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.24rem 0.62rem;
  cursor: pointer;
}
.difficulty { margin-left: auto; }
.difficulty:hover, .quiet:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
.difficulty option { color: #222; }
.quiet:disabled { opacity: 0.42; cursor: default; }

main {
  grid-area: main;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 1rem 1.2rem;
}

.game-table {
  position: relative;
  width: min(100%, 67rem);
  height: clamp(31rem, calc(100vh - 10rem), 43rem);
  min-height: 31rem;
}

.opponent {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
}
.north { top: 0; left: 50%; transform: translateX(-50%); }
.west { left: 0; top: 45%; transform: translateY(-50%); }
.east { right: 0; top: 45%; transform: translateY(-50%); }
.seat-label { display: flex; align-items: center; justify-content: center; gap: 0.45rem; z-index: 2; }
.seat-name { font-weight: 700; }
.trick-count { font-size: 0.74rem; opacity: 0.74; }
.seat-badge {
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 750;
  padding: 0.07rem 0.42rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.fan { display: flex; justify-content: center; min-width: var(--card-w); min-height: var(--card-h); }
.fan .card { margin-left: -1.5rem; box-shadow: -1px 1px 2px rgba(0, 0, 0, 0.3); }
.fan .card:first-child { margin-left: 0; }

.trick {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  width: calc(var(--card-w) * 3.7);
  height: calc(var(--card-h) * 3.15);
}
.trick-slot { position: absolute; width: var(--card-w); height: var(--card-h); transition: filter 0.2s; }
.trick-north { left: 50%; top: 0; transform: translateX(-50%); }
.trick-west { left: 0; top: 50%; transform: translateY(-50%); }
.trick-east { right: 0; top: 50%; transform: translateY(-50%); }
.trick-south { left: 50%; bottom: 0; transform: translateX(-50%); }
.trick-slot.winning { filter: drop-shadow(0 0 0.32rem var(--gold)); }
.pass-pot {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(var(--card-w) * 1.15);
  height: calc(var(--card-h) * 0.8);
  border: 1px dashed rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.7rem;
  display: grid;
  place-items: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.pass-pot[hidden] { display: none; }
.trick.passing .trick-slot { opacity: 0.2; }

.you {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(100%, 48rem);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.you-label { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.1rem; font-weight: 700; }
.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 0.3rem;
  width: 100%;
  padding-top: 0.72rem;
  min-height: calc(var(--card-h) + 1.1rem);
}

/* Cards. Faces are buttons so keyboard focus and card clicks share one target. */
.card {
  width: var(--card-w);
  height: var(--card-h);
  margin: 0;
  padding: 0.2rem 0.3rem;
  flex: none;
  border: 0;
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--black);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font: inherit;
  font-weight: 600;
}
.card.red { color: var(--red); }
.card.black { color: var(--black); }
.card.green { color: var(--green); }
.card.blue { color: var(--blue); }
.card .rank { align-self: flex-start; }
.card .suit { align-self: flex-end; font-size: 1.2rem; }

.card.back {
  border: 2px solid #fff;
  background-color: var(--back);
  background-image: repeating-linear-gradient(
    45deg, rgba(255, 255, 255, 0.18) 0 5px, transparent 5px 10px);
}
.card.slot { border: 2px dashed rgba(255, 255, 255, 0.2); background: transparent; box-shadow: none; }

button.card:disabled { opacity: 1; }
.hand .card.clickable { cursor: pointer; transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s; }
.hand .card.clickable:disabled { pointer-events: auto; }
.hand .card.clickable:hover,
.hand .card.clickable:focus-visible { transform: translateY(-0.45rem); box-shadow: 0 5px 9px rgba(0, 0, 0, 0.35); outline: none; }
.hand .card.illegal { opacity: 0.42; filter: saturate(0.55); }
.hand .card.selected { transform: translateY(-0.85rem); box-shadow: 0 0 0 3px var(--gold), 0 5px 9px rgba(0, 0, 0, 0.35); }
.hand .card.received::after { content: "received"; align-self: center; color: #926c00; font-size: 0.5rem; font-weight: 800; letter-spacing: 0.04em; }
.hand .card.received { background: #fff9d9; box-shadow: 0 0 0 2px rgba(241, 203, 75, 0.72), 0 1px 3px rgba(0, 0, 0, 0.42); }

.ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  transition: transform 0.35s ease, opacity 0.35s ease;
}
.ghost.sweeping { transition-timing-function: cubic-bezier(.4, 0, .8, .5); }

.actions {
  min-height: 2.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.62rem;
  flex-wrap: wrap;
  text-align: center;
}
.prompt { font-weight: 650; }
.muted { opacity: 0.72; font-style: italic; }
.banner { font-size: 1.05rem; font-weight: 750; }
button:not(.card):not(.quiet) {
  border: 0;
  border-radius: 6px;
  background: var(--gold);
  color: #242116;
  padding: 0.42rem 0.95rem;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}
button:not(.card):not(.quiet):hover:not(:disabled) { background: #ffdf68; }
button:disabled { cursor: default; opacity: 0.45; }

.hint {
  width: min(27rem, 100%);
  max-height: 12rem;
  overflow-y: auto;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.19);
  padding: 0.55rem 0.75rem;
  font-size: 0.84rem;
}
.hint h2, .log h2 {
  margin: 0 0 0.3rem;
  font-size: 0.77rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.72;
}
.hint-note { margin: 0 0 0.45rem; font-size: 0.77rem; opacity: 0.72; }
.hint-row { display: grid; grid-template-columns: minmax(0, 1fr) 5rem 5.5rem; gap: 0.8rem; padding: 0.16rem 0.38rem; border-radius: 4px; font-variant-numeric: tabular-nums; }
.hint-row span:not(:first-child) { text-align: right; }
.hint-head { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.65; }
.hint-row.best { background: rgba(241, 203, 75, 0.23); font-weight: 750; }

.log {
  grid-area: log;
  min-height: 0;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  padding: 0.7rem 1rem;
  background: rgba(0, 0, 0, 0.17);
  font-size: 0.84rem;
}
.log div { padding: 0.1rem 0; opacity: 0.88; }
body.log-hidden { grid-template-columns: minmax(0, 1fr); grid-template-areas: "header" "main"; }
body.log-hidden .log { display: none; }

.showdown {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(10, 28, 23, 0.62);
  backdrop-filter: blur(2px);
}
.showdown[hidden] { display: none; }
.showdown-sheet {
  width: min(34rem, 100%);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  border-radius: 9px;
  background: var(--card-bg);
  color: #242622;
  padding: 1rem 1.15rem;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.42);
  text-align: center;
}
.showdown h2 { margin: 0 0 0.65rem; font-size: 1.2rem; }
.moon { margin: 0 0 0.7rem; border-radius: 6px; background: #f7e7a8; padding: 0.45rem; font-weight: 800; color: #734b00; }
.winner { margin-bottom: 0.7rem; color: #9c2724; font-size: 1.45rem; font-weight: 850; }
.round-result { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.35rem; margin: 0 0 0.8rem; }
.round-result span { display: flex; flex-direction: column; border-radius: 5px; background: #efeee7; padding: 0.32rem; font-variant-numeric: tabular-nums; }
.round-result b { font-size: 0.72rem; }
.showdown table { width: 100%; border-collapse: collapse; margin-bottom: 0.9rem; font-variant-numeric: tabular-nums; }
.showdown caption { margin-bottom: 0.3rem; font-weight: 750; }
.showdown th, .showdown td { border-bottom: 1px solid #d9d7ce; padding: 0.25rem 0.38rem; text-align: right; }
.showdown th:first-child { text-align: left; }

@media (max-width: 48rem) {
  body { grid-template-columns: 1fr; grid-template-rows: auto auto auto; grid-template-areas: "header" "main" "log"; }
  header { gap: 0.5rem; flex-wrap: wrap; }
  h1 { font-size: 1.05rem; }
  .score { order: 2; width: 100%; font-size: 0.78rem; }
  .difficulty { margin-left: auto; }
  main { padding-inline: 0.4rem; }
  .game-table { height: 32rem; min-height: 32rem; }
  .west { left: 0.15rem; }
  .east { right: 0.15rem; }
  .west .seat-label, .east .seat-label { flex-direction: column; gap: 0.06rem; }
  .west .trick-count, .east .trick-count { display: none; }
  .log { max-height: 11rem; }
}

@media (max-width: 28rem) {
  :root { --card-w: 2.7rem; --card-h: 3.82rem; }
  .quiet, .difficulty { font-size: 0.76rem; padding: 0.2rem 0.45rem; }
  .game-table { height: 28.5rem; min-height: 28.5rem; }
  .trick { top: 43%; transform: translate(-50%, -50%) scale(0.9); }
  .fan .card { margin-left: -1.9rem; }
  .round-result { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .ghost, .hand .card.clickable, .broken { transition-duration: 0.01ms; }
}
