/* Subset of Libertinus Sans for suits — served from the jdh8.github.io
   origin (see /fonts/SUITS-README.md), shared by all card sites.  No suits
   appear here, but the body font stack stays identical to the other games. */
@font-face {
  font-family: "Libertinus Suits";
  font-weight: 1 1000;
  font-style: oblique -90deg 90deg;
  src: url("https://jdh8.github.io/fonts/suits.woff2") format("woff2");
  /* Only the four filled suits.  Lacking U+0020, this face is never the first
     available font, so line boxes keep the fallback's metrics instead of
     Libertinus's short ascent, which would hoist every baseline. */
  unicode-range: U+2660, U+2663, U+2665-2666;
}

/* The kitchen-table look of the other games: flat felt, gold action buttons,
   no gradients or gloss.  The cards are the real thing — narrow strips of
   dyed stock with the piece printed in black — so their colours are paper
   colours, not ink.  The felt is blue here, not the usual green, because
   green is one of the four suits. */

:root {
  --felt: #24507a;
  --paper: #fdfdf7;
  --ink: #1b1b1b;
  --gold: #f5c518;
  --red: #d9534f;
  --yellow: #f0c541;
  --green: #4caf7d;
  --white: #fdfdf7;
  --back: #8a4b2a;
  --card-w: 1.75rem;
  --card-h: 4.5rem;
  /* The cards you only read: melds on the table, discards, waits. */
  --small-w: 1.1rem;
  --small-h: 2.8rem;
  --small-font: 0.9rem;
}

* { box-sizing: border-box; }

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

header {
  grid-area: header;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: baseline;
  gap: 1rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}
h1 { font-size: 1.2rem; margin: 0; white-space: nowrap; }
.scores { display: flex; gap: 0.8rem; opacity: 0.9; font-variant-numeric: tabular-nums; }
.scores span { white-space: nowrap; }
.scores .dealer::after { content: "莊"; color: var(--gold); font-size: 0.75rem; margin-left: 0.15rem; }
.scores .me { font-weight: 700; }

/* Quiet header controls — not game actions, so styled apart from the gold
   action buttons.  `#new` carries the auto margin that pushes the trailing
   group to the header's right edge. */
.quiet {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 5px;
  background: transparent;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
#new { margin-left: auto; }
.quiet:hover { background: rgba(255, 255, 255, 0.12); }

main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  max-width: 60rem;
  width: 100%;
  margin: 0 auto;
}
.middle {
  display: grid;
  grid-template-columns: minmax(6rem, 1fr) minmax(0, 3fr) minmax(6rem, 1fr);
  gap: 0.6rem;
  align-items: center;
}

/* Opponents: a name, a face-down row for the concealed count, exposed melds. */
.opp { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; }
.opp .name { opacity: 0.85; font-weight: 600; }
.opp .name.acting { color: var(--gold); }
.opp .name .dealer { color: var(--gold); font-size: 0.75rem; margin-left: 0.2rem; }
.hu { margin-left: 0.5rem; font-size: 0.85rem; font-weight: 400; opacity: 0.85; }
.fan { display: flex; }
.fan .card { margin-left: calc(var(--card-w) * -0.6); box-shadow: -1px 1px 2px rgba(0, 0, 0, 0.3); }
.fan .card:first-child { margin-left: 0; }
.melds { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; }
.meld { display: flex; gap: 0.15rem; padding: 0.2rem; border-radius: 6px; background: rgba(0, 0, 0, 0.18); }
.side .fan .card, .side .meld .card, .top .fan .card, .top .meld .card {
  --card-w: var(--small-w); --card-h: var(--small-h); font-size: var(--small-font);
}

/* Centre of the table: the card on offer, the discard pile, the draw pile. */
.table {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-height: calc(var(--card-h) * 2.6);
  padding: 0.5rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.12);
}
.offer { display: flex; align-items: center; gap: 0.6rem; min-height: calc(var(--card-h) + 0.6rem); }
.offer .card { box-shadow: 0 0 0 3px var(--gold); }
.offer .who { font-size: 0.9rem; opacity: 0.9; }
.discards { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.2rem; max-width: 100%; }
.discards .card { --card-w: var(--small-w); --card-h: var(--small-h); font-size: var(--small-font); opacity: 0.85; }
.pile { font-size: 0.85rem; opacity: 0.8; }

/* You: status line, exposed melds, the hand, and the claim buttons. */
section.me { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
.status { min-height: 1.4rem; font-weight: 600; }
.status.acting { color: var(--gold); }
/* The bottom padding keeps room for the hint's grades under the cards.
   The hand never wraps: its cards narrow to fit one row instead, and the
   piece shrinks with them, by `--n`, the cards in hand (set in app.js). */
.hand {
  --n: 21;
  container-type: inline-size;
  align-self: stretch;
  display: flex;
  justify-content: center;
  padding: 0.8rem 0 1rem;
}
.hand .group, .hand .card { flex: 0 1 auto; min-width: 0; }
.hand .group + .group { margin-left: min(0.9rem, 1.5cqw); }
.hand .card { flex-basis: var(--card-w); font-size: min(1.25rem, 80cqw / var(--n)); }
/* A discard that leaves you waiting. */
.card.tenpai::before {
  content: "聽";
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  translate: -50% 0;
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--gold);
}
.hand .group { display: flex; gap: min(0.25rem, 0.4cqw); }
.exposed { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; }
/* Your waits, sized like the melds on the table so they do not read as
   your hand; the 胡 and the copies left under each card. */
.waits { display: flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.4rem; border-radius: 6px; background: rgba(0, 0, 0, 0.18); }
.waits:empty { display: none; }
.waits.reserve { display: flex; min-height: calc(var(--small-h) + 1.8rem); }
.waits.reserve:empty { background: none; }
.waits .wait { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; font-size: 0.65rem; line-height: 1.2; text-align: center; font-variant-numeric: tabular-nums; }
.waits .wait.gone { opacity: 0.5; }
.waits .card { --card-w: var(--small-w); --card-h: var(--small-h); font-size: var(--small-font); }

/* Cards: dyed strips, piece in black. */
.card {
  width: var(--card-w);
  height: var(--card-h);
  background: var(--paper);
  color: var(--ink);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  flex: none;
  position: relative;
}
/* Generals carry the coin printed on the real card.  Not dots: two dots are
   the horse's ornament. */
.card[data-code$="K"]::after {
  content: "";
  position: absolute;
  top: calc(50% + 0.6em);
  left: 50%;
  width: 0.4em;
  height: 0.4em;
  translate: -50% 0;
  rotate: 45deg;
  box-sizing: border-box;
  border: 0.06em solid currentColor;
  border-radius: 50%;
  /* the square hole, standing on its corner */
  background: linear-gradient(currentColor, currentColor) center / 35% 35% no-repeat;
  pointer-events: none;
}
.card.red { background: var(--red); }
.card.yellow { background: var(--yellow); }
.card.green { background: var(--green); }
.card.white { background: var(--white); }
.card.back {
  background-color: var(--back);
  background-image: repeating-linear-gradient(
    45deg, rgba(255, 255, 255, 0.18) 0 4px, transparent 4px 8px);
  border: 2px solid #fff;
}
.card.clickable { cursor: pointer; transition: transform 0.08s; }
.card.clickable:hover { transform: translateY(-0.4rem); }
.card.locked { opacity: 0.5; }
.hint { outline: 3px solid var(--gold); outline-offset: 2px; }
.card.hint { transform: translateY(-0.4rem); }
/* Picked by a first tap; the second plays it. */
.card.picked { transform: translateY(-0.6rem); box-shadow: 0 0 0 2px #fff; }
/* The hint's grade of each move: under a card, after a button's label. */
.grade { font-size: 0.65rem; font-weight: 400; font-variant-numeric: tabular-nums; margin-left: 0.3rem; }
.card .grade {
  position: absolute;
  top: calc(100% + 2px);
  left: 50%;
  translate: -50% 0;
  margin: 0;
  color: var(--gold);
  white-space: nowrap;
}
.card.new { animation: pulse 0.9s ease; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); }
  30% { box-shadow: 0 0 0 3px var(--gold); }
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 2.6rem;
}
button.action {
  font: inherit;
  padding: 0.35rem 0.9rem;
  border: 0;
  border-radius: 6px;
  background: var(--gold);
  color: #222;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
button.action:hover { background: #ffd83a; }
button.action:disabled { opacity: 0.45; cursor: not-allowed; background: var(--gold); }
button.action .card { --card-w: 0.95rem; --card-h: 2.4rem; font-size: 0.85rem; box-shadow: none; }
/* Claims are outlined so their gold and white cards stand out; 過 and 提示 keep the gold. */
button.action.claim { background: transparent; color: inherit; border: 1px solid rgba(255, 255, 255, 0.35); }
button.action.claim:enabled:hover { background: rgba(255, 255, 255, 0.12); }

/* The result sheet: a plain card of paper over the felt. */
.result {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: min(26rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 1rem 1.2rem;
  background: var(--paper);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}
/* `display: flex` above would beat the `hidden` attribute's UA rule. */
.result[hidden] { display: none; }
.result h2 { margin: 0; font-size: 1.1rem; }
.result .melds { justify-content: center; }
.result .meld { background: rgba(0, 0, 0, 0.06); }
.result .meld .card { --card-w: var(--small-w); --card-h: var(--small-h); font-size: var(--small-font); }

/* The help sheet: the same paper, as a native modal <dialog>. */
.rules {
  width: min(30rem, calc(100vw - 2rem));
  padding: 1rem 1.2rem;
  background: var(--paper);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.rules::backdrop { background: rgba(0, 0, 0, 0.4); }
.rules h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }
.rules ul { margin: 0 0 0.8rem; padding-left: 1.2rem; }
.rules table { border-collapse: collapse; width: 100%; }
.rules th, .rules td { padding: 0.25rem 0.4rem; border-bottom: 1px solid rgba(0, 0, 0, 0.12); text-align: left; }
.rules td:last-child, .rules th:last-child { text-align: right; white-space: nowrap; }
.rules .card { display: inline-flex; margin-right: 0.15rem; --card-w: var(--small-w); --card-h: var(--small-h); font-size: var(--small-font); }
.rules p { font-size: 0.85rem; opacity: 0.8; }
.rules form { text-align: center; }
.rules .setting { margin: 0 0 0.8rem; }
.rules select { font: inherit; }

.log {
  grid-area: log;
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.18);
  overflow-y: auto;
  max-height: 100vh;
  font-size: 0.85rem;
}
.log h2 { font-size: 0.8rem; letter-spacing: 0.05em; opacity: 0.7; margin: 0.3rem 0; }
.log div { padding: 0.1rem 0; opacity: 0.9; }

/* Hidden by default: drop the panel and reclaim its grid column. */
body.log-hidden {
  grid-template-columns: 1fr;
  grid-template-areas: "header" "main";
}
body.log-hidden .log { display: none; }

/* A phone.  The page is exactly one screen: the table in the middle takes
   what room is left and scrolls by itself when the melds outgrow it, so the
   hand and the buttons never leave the screen.  The cards you only read
   turn from strips to stubs. */
@media (max-width: 40rem) {
  :root {
    --card-h: 3rem;
    --small-w: 1rem;
    --small-h: 1.7rem;
    --small-font: 0.8rem;
  }
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "header" "main" "log";
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }
  header { flex-wrap: wrap; gap: 0.3rem 0.5rem; padding: 0.3rem 0.5rem; }
  /* The title and the buttons share a row; the scores take the next. */
  .scores { gap: 0.6rem; order: 1; flex-basis: 100%; }
  .quiet { padding: 0.2rem 0.4rem; }
  main { gap: 0.4rem; padding: 0.4rem 0.5rem; min-height: 0; }
  .middle {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
    gap: 0.3rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    align-content: safe center;
  }
  .table { min-height: 0; }
  .pile { text-align: center; }
  .melds { gap: 0.2rem; }
  .meld { gap: 1px; padding: 2px; }
  /* Backs only count, so they close up; a hand shown at the end wraps. */
  .fan { flex-wrap: wrap; justify-content: center; max-width: 100%; }
  .fan .card:not(.back) { margin-left: 0; }
  .fan .card.back:not(:first-child) { margin-left: calc(var(--card-w) * -0.85); }
  .card.back { border-width: 1px; }
  button.action .card { --card-h: 1.6rem; }
  .log { max-height: 8rem; }
}
