:root {
  font-family: system-ui, sans-serif;
  color: #f0f6ef;
  background: #111d1b;
  color-scheme: dark;
  --surface: #1b2b27;
  --raised: #243831;
  --line: #3e5950;
  --muted: #bacdc3;
  --accent: #f6d477;
  --ink: #172422;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, p { margin: 0; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

button {
  min-height: 44px;
  padding: .6rem .85rem;
  color: inherit;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: .65rem;
  font-weight: 650;
}
button:not(:disabled):hover { filter: brightness(1.13); }
button.primary { color: var(--ink); background: var(--accent); border-color: var(--accent); }
button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
button.bomb { background: #603b35; border-color: #a06b60; }

.shell { width: min(100%, 48rem); margin: 0 auto; padding: 0 .8rem; }
.topbar, .top-actions, .room-info, .totals { display: flex; align-items: center; }
.topbar, .room-info { justify-content: space-between; gap: .55rem; }
.topbar { min-height: 4rem; border-bottom: 1px solid var(--line); }
.topbar h1 { font: 700 2.35rem/.95 Georgia, serif; letter-spacing: -.08em; }
.topbar h1 span { color: var(--accent); }
.top-actions { gap: .3rem; }
#connection { color: var(--muted); font-size: .875rem; }
#connection.online { color: #a2e2ba; }
main { padding-top: .8rem; }
.notice { padding: .65rem .8rem; border: 1px solid #bd8074; border-radius: .65rem; background: #4d302d; margin-bottom: .65rem; }

.lobby {
  width: min(100%, 28rem);
  margin: clamp(1.25rem, 8vh, 5rem) auto;
  padding: clamp(1rem, 4vw, 2rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1.15rem;
}
.lobby h2 { font: 700 clamp(1.9rem, 8vw, 2.65rem)/1.05 Georgia, serif; }
.mode { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin: 1.15rem 0; }
.mode [aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
form { display: grid; gap: .95rem; }
form > label, .choice { display: grid; gap: .3rem; font-size: .875rem; font-weight: 600; }
form input:not([type="radio"]), select {
  width: 100%;
  min-height: 44px;
  padding: .5rem .65rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  color: #f0f6ef;
  background: var(--ink);
  font-size: 1rem;
}
#code { text-transform: uppercase; letter-spacing: .16em; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { margin-bottom: .4rem; font-size: .875rem; font-weight: 600; }
.seat-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; }
.seat-team { display: grid; gap: .35rem; }
.team-label { color: var(--muted); font-size: .875rem; }
.seat-choice {
  display: flex;
  align-items: center;
  gap: .35rem;
  min-height: 44px;
  padding: .35rem .45rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  font-size: .875rem;
  overflow-wrap: anywhere;
}
.seat-choice:has(:checked) { border-color: var(--accent); }
.seat-choice:has(:disabled) { opacity: .65; }
.seat-choice input { accent-color: var(--accent); margin: 0; flex: 0 0 auto; }

#room { display: grid; gap: .55rem; padding-bottom: max(.8rem, env(safe-area-inset-bottom)); }
.room-code { font-size: 1rem; letter-spacing: .05em; white-space: nowrap; }
.totals { flex-wrap: wrap; justify-content: flex-end; gap: .25rem .65rem; color: var(--accent); font-size: .875rem; }
.players { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem; }
.player {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .2rem .5rem;
  padding: .45rem .5rem;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: var(--surface);
  min-width: 0;
}
.player.active-player { border-color: var(--accent); }
.identity, .player-detail { display: grid; gap: .05rem; min-width: 0; }
.player-name { overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: .875rem; }
.call { color: var(--accent); font-size: .875rem; }

.felt {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: .4rem;
  min-height: 8.8rem;
  padding: .75rem .5rem;
  text-align: center;
  background: radial-gradient(ellipse at 50% 30%, #245b47, #173f33 80%);
  border: 1px solid #467865;
  border-radius: 1rem;
}
.felt h2 { font: 700 clamp(1.35rem, 5vw, 1.9rem)/1.1 Georgia, serif; overflow-wrap: anywhere; }
.wish { color: var(--accent); font-size: .875rem; }
.trick { display: flex; flex-wrap: wrap; justify-content: center; gap: .2rem; }
.round-score { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem 1rem; color: var(--accent); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.controls > .choices, .play-actions { width: 100%; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(8.5rem, 100%), 1fr)); gap: .35rem; }
.choice { min-width: 0; overflow-wrap: anywhere; }
.play-actions { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: .4rem; }

.hand-area {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin-top: .15rem;
  padding: .45rem .35rem max(.35rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .75rem;
}
.hand-area h2 { font-size: .875rem; margin: 0 .16rem .35rem; }
#selection-count { color: var(--muted); font-weight: 400; margin-left: .25rem; }
.hand { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .25rem; }
.card {
  display: grid;
  place-content: center;
  justify-items: center;
  min-width: 0;
  min-height: 48px;
  padding: .12rem;
  border: 2px solid #d4dacb;
  border-radius: .45rem;
  background: #f3f4eb;
  color: #203633;
  font-weight: 750;
  line-height: 1.05;
}
.trick .card { width: 2.15rem; min-height: 2.4rem; }
.card .rank { font-size: clamp(.82rem, 3.7vw, 1.15rem); }
.card .mark { font-size: .86rem; }
.card .mark:empty { display: none; }
.card.jade { color: #176144; }
.card.pagoda { color: #8d4e22; }
.card.star { color: #3a538c; }
.card.dragon { color: #952f32; }
.card.phoenix { color: #693f81; }
.card[aria-pressed="true"] { border-color: #c08b22; background: #fae1a2; box-shadow: inset 0 0 0 1px #c08b22; }

@media (min-width: 42rem) {
  .shell { padding: 0 1.1rem; }
  .players { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .felt { min-height: 14rem; }
  .hand { grid-template-columns: repeat(14, minmax(0, 1fr)); }
  .card { min-height: 62px; }
  .trick .card { width: 2.8rem; min-height: 3.2rem; }
}

@media (max-width: 350px) {
  .hand { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
