:root {
  --cinnabar: #e7625f;
  --freesia: #e2b850;
  --blue: #1f6cb0;
  --rose: #e24c60;
  --ink: #172735;
  --muted: #475b6b;
  --line: #ccd8e0;
  --paper: #f5f7f9;
  font: 16px/1.4 system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
main { max-width: 57rem; margin: auto; padding: 1rem clamp(.7rem, 3vw, 2rem) 2rem; }
h1, h2, p { margin: 0 0 .7rem; }
h1 { font-size: clamp(1.65rem, 5vw, 2.25rem); }
h2 { font-size: 1.05rem; }
a { color: var(--blue); }
button, input, select { font: inherit; }
button {
  min-height: 2.65rem;
  padding: .45rem .85rem;
  border: 1px solid transparent;
  border-radius: .5rem;
  color: #fff;
  background: var(--blue);
  font-weight: 650;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(.91); }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}
button.secondary { color: var(--blue); border-color: var(--line); background: #fff; }
button.compact { min-height: 2.4rem; font-size: .88rem; }
button.throw { color: var(--ink); background: #fff; border-color: var(--cinnabar); }
input, select {
  min-height: 2.65rem;
  padding: .5rem .65rem;
  border: 1px solid #a8baca;
  border-radius: .5rem;
  color: var(--ink);
  background: #fff;
  width: 100%;
}
form { display: grid; gap: .75rem; }
label { display: grid; gap: .3rem; font-weight: 600; }
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem clamp(.85rem, 4vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.brand { color: var(--ink); font-size: 1.24rem; font-weight: 800; text-decoration: none; }
.masthead-actions { display: flex; align-items: center; gap: .65rem; }
.brand span, .suits { color: var(--blue); }
.suits { font-size: 1.45rem; letter-spacing: .2em; }
.suits span { color: var(--rose); }
.surface { background: #fff; border: 1px solid var(--line); border-radius: .85rem; }
.entry, .lobby, .rules { padding: clamp(.9rem, 4vw, 1.65rem); margin: clamp(.6rem, 4vw, 2rem) auto; }
.entry, .lobby { max-width: 29rem; }
.switch, .invite { display: flex; gap: .5rem; margin-bottom: .95rem; }
.switch button { flex: 1; }
.switch button[aria-pressed="true"] { color: var(--ink); border-color: var(--blue); background: #eaf4fb; }
.invite { align-items: end; }
.invite label { flex: 1; min-width: 0; }
.invite input { font-size: .87rem; }
.lobby-teams { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin: 1rem 0; }
.lobby-teams > div { border-radius: .5rem; background: var(--paper); padding: .65rem .8rem; }
.lobby-teams ul { margin: 0; padding: 0; list-style: none; overflow-wrap: anywhere; }
.quiet, .match-meta, .vote small { color: var(--muted); }
.error, .connection { background: #fff; border: 1px solid var(--rose); border-radius: .5rem; padding: .55rem .7rem; margin-top: .75rem; }
.connection { border-color: var(--freesia); }
.scoreboard { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
.score { display: flex; justify-content: space-between; gap: .4rem; padding: .55rem .65rem; align-items: center; border-top: 3px solid var(--blue); }
.score.team-1 { border-color: var(--rose); border-left: 1px solid var(--line); }
.score span { display: block; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.score-numbers { text-align: right; min-width: 2.9rem; }
.score-numbers strong { display: block; font-size: 1.6rem; line-height: 1.05; font-variant-numeric: tabular-nums; }
.score small { white-space: nowrap; }
.match-meta { min-height: 3rem; display: flex; align-items: center; justify-content: space-between; gap: .4rem; font-size: .84rem; }
.felt {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: auto minmax(7rem, auto) auto;
  grid-template-areas: ". partner ." "left status right" ". you .";
  min-height: min(48vh, 22rem);
  padding: .55rem .35rem;
  gap: .25rem;
  background: #eaf3fa;
  border: 1px solid #bbd0df;
  border-radius: .85rem;
}
.station { display: flex; align-items: center; flex-direction: column; gap: .22rem; min-width: 0; }
.position-0 { grid-area: you; flex-direction: column-reverse; justify-content: flex-start; }
.position-1 { grid-area: left; justify-content: center; }
.position-2 { grid-area: partner; }
.position-3 { grid-area: right; justify-content: center; }
.nameplate { text-align: center; padding: .23rem .36rem; border: 2px solid transparent; border-radius: .5rem; background: #f9fcfe; overflow-wrap: anywhere; max-width: 100%; }
.nameplate small { display: block; font-size: .71rem; color: var(--muted); }
.nameplate strong { font-size: .88rem; }
.nameplate.current { background: var(--rose); border-color: #b83148; color: #101820; }
.nameplate.current small { color: inherit; }
.table-status { grid-area: status; align-self: center; text-align: center; font-weight: 750; }
.played-slot:empty { display: none; }
.played {
  display: flex;
  width: clamp(2rem, 9vw, 3.6rem);
  border-radius: .28rem;
  box-shadow: 0 1px 4px #1f314751;
  animation: card-arrive 180ms ease-out both;
}
.played img, .hand img, .review-cards img { display: block; width: 100%; height: auto; border-radius: inherit; }
.winning { outline: 3px solid var(--freesia); outline-offset: 2px; }
@keyframes card-arrive {
  from { opacity: 0; transform: translateY(.55rem) scale(.94); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .played { animation: none; }
}
@media (min-width: 700px) {
  .felt { --played-width: clamp(4.5rem, 11vh, 6.25rem); }
  .played-slot { width: var(--played-width); }
  .felt:is([data-phase="play"], [data-phase="review"]) .played-slot {
    display: block;
    aspect-ratio: 203 / 288;
  }
  .played { width: var(--played-width); }
  .felt .position-1 { flex-direction: row; justify-content: flex-end; gap: .5rem; }
  .felt .position-3 { flex-direction: row-reverse; justify-content: flex-end; gap: .5rem; }
}
.moves { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; margin: .6rem 0; }
.moves:empty, .hand:empty { display: none; }
.hand { display: flex; justify-content: center; gap: clamp(.22rem, 1.3vw, .6rem); margin: .65rem auto .8rem; }
.hand button {
  width: min(15%, 5.4rem);
  display: block;
  border: 1px solid var(--line);
  border-radius: .42rem;
  padding: 0;
  background: white;
  box-shadow: 0 1px 3px #1f314731;
}
.hand button:disabled { opacity: 1; }
.hand button.unavailable { opacity: .48; }
.hand button:not(:disabled) { outline: 2px solid var(--blue); outline-offset: 1px; }
.hand button:focus-visible { outline: 4px solid var(--blue); }
.hand-score { padding: .45rem; font-weight: 700; text-align: center; }
.vote { display: flex; align-items: center; gap: .65rem; padding: .55rem; }
.vote button { flex: none; }
.history { margin-top: .65rem; padding: .65rem .9rem; }
summary { cursor: pointer; font-weight: 650; }
table { border-collapse: collapse; margin: .7rem 0; }
th, td { padding: .25rem .6rem; vertical-align: top; text-align: left; border-bottom: 1px solid var(--line); }
.history table { width: 100%; }
dialog { color: var(--ink); border: 1px solid var(--line); border-radius: .85rem; padding: 1rem; width: min(92vw, 31rem); }
dialog::backdrop { background: #17273591; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .45rem; }
.dialog-head h2 { margin: 0; }
.review-cards { display: flex; justify-content: center; gap: .7rem; }
.review-cards figure { margin: .15rem 0; width: min(22%, 5.1rem); padding: .2rem; font-size: .74rem; border-radius: .35rem; overflow-wrap: anywhere; }
.rules h2 { margin-top: 1.3rem; }
.rules h3 { font-size: 1rem; }
.rules li + li { margin-top: .3rem; }
@media (max-width: 420px) {
  .score { padding: .48rem; }
  .table-status { font-size: .88rem; }
  .felt { min-height: 16rem; }
  .vote { align-items: start; }
  .invite button { padding-inline: .5rem; }
  .nameplate strong { font-size: .8rem; }
}
