:root {
  color-scheme: dark;
  --page: #1b1512;
  --panel: #2b211b;
  --panel-raised: #352820;
  --control: #3a2a21;
  --ink: #f9f1dc;
  --muted: #d3c4b2;
  --gold: #f1cb80;
  --line: #e7c9a32e;
  --line-strong: #d6b38b69;
  --card-ratio: 8 / 15;
  --card-back: url("./assets/cards/back.webp");
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scrollbar-gutter: stable; }

body {
  min-width: 280px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 0%, #3b2b21, var(--page) 74%);
}

button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid #fff4d2; outline-offset: 3px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  width: min(100% - 2rem, 54rem);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem) 0 max(1.25rem, env(safe-area-inset-bottom));
}

.masthead, .brand {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.masthead {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.masthead h1 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: clamp(2.15rem, 6vw, 3rem);
  font-weight: 700;
  letter-spacing: -.055em;
  line-height: 1.05;
}

.brand-mark {
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  font-size: clamp(1.85rem, 5vw, 2.45rem);
  line-height: 1;
}

.difficulty-control { position: relative; }

.header-actions {
  display: flex;
  align-items: center;
  gap: .45rem;
}

.difficulty-control select:disabled { opacity: .8; cursor: default; }

.difficulty-control::after {
  position: absolute;
  top: 50%;
  right: .82rem;
  width: .38rem;
  height: .38rem;
  border: solid var(--gold);
  border-width: 0 2px 2px 0;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
  content: "";
}

.difficulty-control select {
  appearance: none;
  min-height: 2.75rem;
  width: 6rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  padding: .3rem 1.65rem .3rem .6rem;
  background: var(--control);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}

.table {
  min-width: 0;
}

.room-panel {
  display: grid;
  justify-items: start;
  gap: .8rem;
  max-width: 36rem;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: clamp(1rem, 4vw, 1.65rem);
  background: var(--panel);
}

.room-panel h2 { margin: 0; font: 700 clamp(1.7rem, 5vw, 2.25rem)/1.1 Georgia, serif; }
.room-detail, .room-error { margin: 0; color: var(--muted); line-height: 1.4; }
.room-detail:empty { display: none; }
.room-error { font-size: .9375rem; color: #ffceaa; }

.room-form, .room-link, .room-seats { width: 100%; }
.room-form { display: grid; justify-items: start; gap: .7rem; }
.room-field { display: grid; gap: .35rem; width: 100%; }
.room-link { display: flex; align-items: center; gap: .4rem; }

.room-input {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  border: 1px solid var(--line-strong);
  border-radius: .55rem;
  padding: .5rem .65rem;
  background: var(--page);
  color: var(--ink);
}

.room-seats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.room-seats li {
  display: grid;
  gap: .25rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  padding: .55rem .65rem;
  background: var(--panel-raised);
  overflow-wrap: anywhere;
}

.room-seats .room-detail { font-size: .875rem; }

.game-status {
  display: grid;
  gap: .75rem;
  margin-top: .75rem;
  border: 1px solid var(--line);
  border-radius: .85rem;
  padding: .7rem .8rem .85rem;
  background: var(--panel);
}

.departure-notice {
  position: fixed;
  z-index: 4;
  inset-inline: max(.75rem, env(safe-area-inset-left)) max(.75rem, env(safe-area-inset-right));
  inset-block-end: max(.75rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .85rem;
  max-width: 32rem;
  margin-inline: auto;
  border: 1px solid var(--gold);
  border-radius: .85rem;
  padding: .8rem 1rem;
  background: #39281d;
  box-shadow: 0 .45rem 1.4rem #100a07bf;
}

.departure-notice[hidden] { display: none; }
.departure-notice h2 { margin: 0; color: var(--gold); font: 700 1.3rem/1.1 Georgia, serif; }
.departure-notice p { margin: .35rem 0 0; line-height: 1.35; overflow-wrap: anywhere; }

.chat-toggle, .room-chat {
  position: fixed;
  z-index: 3;
  inset-inline-end: max(.75rem, env(safe-area-inset-right));
  inset-block-end: max(.75rem, env(safe-area-inset-bottom));
  box-shadow: 0 .45rem 1.4rem #100a07bf;
}

.chat-toggle[hidden], .room-chat[hidden], .chat-unread[hidden] { display: none; }
.chat-toggle { border-radius: 2rem; }
.chat-unread {
  min-width: 1.2rem;
  border-radius: 1rem;
  padding: .08rem .25rem;
  background: #422e22;
  color: #fff3d8;
  font-size: .75rem;
  line-height: 1.2;
  text-align: center;
}

.shell:has(:where(.chat-toggle:not([hidden]), .room-chat:not([hidden]))) {
  padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
}

.room-chat {
  inset-block-end: calc(var(--chat-inset, 0px) + max(.75rem, env(safe-area-inset-bottom)));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(24rem, calc(100vw - 1.5rem - env(safe-area-inset-left) - env(safe-area-inset-right)));
  height: min(25rem, calc(var(--chat-viewport, 100dvh) - 1.5rem));
  border: 1px solid var(--line-strong);
  border-radius: .85rem;
  background: var(--panel);
}

.chat-header, .chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .45rem;
  padding: .5rem .65rem;
}

.chat-header { border-bottom: 1px solid var(--line); }
.chat-header h2 { margin: 0; font: 700 1.28rem/1.1 Georgia, serif; }
.chat-header .button { padding-inline: .55rem; font-size: .875rem; }

.chat-history {
  overflow: auto;
  overscroll-behavior: contain;
  padding: .6rem .65rem;
  scrollbar-width: thin;
}

.chat-empty { margin: 0; color: var(--muted); font-size: .875rem; }
.chat-messages { display: grid; gap: .45rem; margin: 0; padding: 0; list-style: none; }
.chat-message {
  justify-self: start;
  max-width: 92%;
  min-width: min(8rem, 100%);
  border: 1px solid var(--line);
  border-radius: .65rem;
  padding: .4rem .55rem;
  background: var(--panel-raised);
  overflow-wrap: anywhere;
}

.chat-message--own { justify-self: end; background: #463221; }
.chat-meta { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.chat-meta strong { color: var(--gold); font-size: .78rem; }
.chat-meta time { flex: none; color: var(--muted); font-size: .72rem; }
.chat-message p { margin: .12rem 0 0; white-space: pre-wrap; font-size: .9375rem; line-height: 1.35; }
.chat-form { border-top: 1px solid var(--line); }
.chat-form input { font-size: 1rem; }
.chat-form .button:disabled { opacity: .55; }
.chat-error { grid-column: 1 / -1; }

.game-status-bar, .game-phase, .game-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem .65rem;
  min-width: 0;
}

.game-status-bar {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: .6rem;
}

.phase-label, .round-indicator { font-size: .875rem; overflow-wrap: anywhere; }
.phase-label { color: var(--ink); font-weight: 700; }
.round-indicator { color: var(--muted); }
.game-chips { gap: .3rem; }

.bid-history {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bid-history li {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .3rem;
  border: 1px solid var(--line);
  border-radius: .4rem;
  padding: .25rem .4rem;
  font-size: .875rem;
}

.bid-player { color: var(--muted); }
.bid-value { color: var(--gold); font-weight: 700; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-width: 0;
  border-radius: 1.5rem;
  padding: .28rem .6rem;
  background: #422e22;
  color: #f0eedb;
  font-size: .875rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.chip--trump { background: #f3ead4; color: var(--panel); font-weight: 700; }
.chip--multiplier { background: #44351ce0; color: #ffe1a3; font-weight: 700; }
.chip--timer { background: var(--page); white-space: nowrap; }
.chip--timer-low { background: #513420; color: #ffe1a3; }
.countdown { font-weight: 750; font-variant-numeric: tabular-nums; }
.chip .suit { width: 1.15rem; height: 1.15rem; }

.table-surface {
  --table-edge: clamp(.45rem, 1.55vw, .95rem);
  --table-pad-top: clamp(.65rem, 2vw, 1.15rem);
  --table-pad-bottom: clamp(.85rem, 3vw, 1.65rem);
  /* Move padding from both ends into the trick row. */
  --table-space: clamp(.3rem, 1.3vw, .55rem);
  --side-seat-offset: clamp(.12rem, .9vw, .55rem);
  --top-seat-row: clamp(3.9rem, 11vw, 4.7rem);
  --trick-row: clamp(8.15rem, 38vw, 13rem);
  --played-width: clamp(2.75rem, 12vw, 4.3rem);
  --hand-card-width: clamp(2.85rem, 16.3vw, 5.6rem);
  --hand-row: calc(var(--hand-card-width) * 1.875 + 1.8rem);
  --own-score-row: 3.6rem;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template:
    "top top top" var(--top-seat-row)
    "left center right" calc(var(--trick-row) + 2 * var(--table-space))
    "bottom bottom bottom" calc(var(--hand-row) + var(--own-score-row))
    / minmax(0, 1fr) minmax(0, 57%) minmax(0, 1fr);
  column-gap: clamp(.2rem, 1.5vw, .85rem);
  row-gap: .35rem;
  align-items: center;
  border: var(--table-edge) solid transparent;
  border-radius: clamp(1rem, 3.3vw, 1.875rem);
  padding: calc(var(--table-pad-top) - var(--table-space)) clamp(.1rem, .8vw, .55rem)
    calc(var(--table-pad-bottom) - var(--table-space));
  background: radial-gradient(ellipse 72% 66% at 50% 47%,
    #94684f, #855b45 28%, #694839 65%, #483127) border-box;
  box-shadow: 0 .65rem 1.65rem #100a079e;
}

.seat {
  display: grid;
  justify-items: center;
  gap: .35rem;
  min-width: 0;
  text-align: center;
}

.seat--top { grid-area: top; position: relative; z-index: 1; }
.seat--left { grid-area: left; translate: calc(-1 * var(--side-seat-offset)) 0; }
.seat--right { grid-area: right; translate: var(--side-seat-offset) 0; }
.seat--bottom {
  grid-area: bottom;
  grid-template-rows: var(--hand-row) var(--own-score-row);
  align-self: stretch;
  align-items: center;
  gap: 0;
}

.seat--bottom .player { grid-row: 2; }

.player {
  position: relative;
  display: grid;
  align-content: center;
  grid-template-columns: minmax(0, 1fr);
  gap: .14rem .5rem;
  width: fit-content;
  max-width: 100%;
  max-block-size: 100%;
  border: 1px solid #eed6b647;
  border-radius: .55rem;
  padding: .3rem .55rem;
  background: #2b1e17f5;
  box-shadow: 0 .15rem .35rem #25140e70;
  font-size: .9375rem;
  line-height: 1.1;
}

.seat--top .player, .seat--bottom .player {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
}

.player--active { border-color: #e3b970; background: #432d20; }
.player--winner { border-color: #ffe197; background: #523a25; box-shadow: 0 0 .85rem #ffd37135; }
.player--sitting-out { filter: grayscale(1); opacity: .72; }
.player-name, .player-score { font-weight: 700; overflow-wrap: anywhere; }

.activity-dot {
  display: none;
  width: .38rem;
  height: .38rem;
  margin: 0 .26rem .08rem 0;
  border-radius: 50%;
  background: var(--gold);
}

.player--active .activity-dot { display: inline-block; }
.player-score { color: var(--gold); font-variant-numeric: tabular-nums; }
.score-unit, .player-role { color: var(--muted); font-size: .8125rem; font-weight: 450; }
.player-role { grid-column: 1 / -1; line-height: 1.25; overflow-wrap: anywhere; }
.player-dealer, .player-bid {
  display: inline-block;
  border-radius: .24rem;
  padding: .04rem .26rem;
  background: #efc87d;
  color: #2b261b;
  font-size: .72rem;
  font-weight: 750;
  line-height: 1.15;
}

.player-bid {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-end: calc(100% + .23rem);
  min-width: 1.55rem;
  padding: .18rem .34rem;
  border-radius: .32rem;
  font-size: .95rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translateY(-50%);
  box-shadow: 0 .1rem .25rem #25140e70;
}

.seat--left .player-bid, .seat--right .player-bid {
  inset-block: auto calc(100% + .23rem);
  inset-inline: 50% auto;
  transform: translateX(-50%);
}

.player-bid--pass { background: #dbc5a9; }

.player-delta { grid-column: 1 / -1; color: #b7e7b5; font-size: .8125rem; overflow-wrap: anywhere; }
.player-delta--penalty { color: #ffb79b; }

.seat-backs {
  display: flex;
  justify-content: center;
  width: 100%;
  padding: .05rem 0;
}

.seat-backs:empty { display: none; }
.mini-back, .deck-back, .cut-packet, .deal-card {
  aspect-ratio: var(--card-ratio);
  background: #e9e3d2 var(--card-back) center / cover no-repeat;
}

.mini-back {
  width: clamp(.65rem, 2.4vw, .9rem);
  border: 1px solid #dfd6bf;
  border-radius: .15rem;
  box-shadow: 0 .12rem .25rem #152317b0;
  transform: rotate(-6deg);
}

.mini-back + .mini-back { margin-inline-start: clamp(-.63rem, -1.6vw, -.34rem); }

.table-center {
  position: relative;
  grid-area: center;
  display: grid;
  align-self: stretch;
  min-width: 0;
}

.game-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .65rem;
  min-width: 0;
  text-align: center;
}

.game-message {
  display: grid;
  justify-items: center;
  gap: .4rem;
  min-width: 0;
  max-width: 100%;
}

.game-heading h2 {
  margin: 0;
  font: 700 clamp(1.34rem, 4vw, 2rem)/1.12 Georgia, serif;
  letter-spacing: -.03em;
}

.game-status--reviewing .game-heading h2 { color: #ffe2a3; }

.game-heading p {
  margin: .25rem 0 0;
  color: var(--muted);
  line-height: 1.35;
  text-wrap: pretty;
}

.deck-back {
  position: absolute;
  visibility: hidden;
  inset-block-start: clamp(.75rem, 2vw, 1.55rem);
  inset-inline-end: clamp(1.2rem, 5vw, 3.3rem);
  width: clamp(1.75rem, 6vw, 2.85rem);
  border: 1px solid #dfd6bf;
  border-radius: .35rem;
  transform: rotate(9deg);
  box-shadow: .14rem .18rem 0 #ad9567, .3rem .42rem .45rem #14291e;
  pointer-events: none;
}

button.deck-back { padding: 0; pointer-events: auto; }
button.deck-back::before { position: absolute; inset: -.5rem; content: ""; }
.deck-back--cutting { visibility: hidden; }

.deal-layer {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
}

.deal-card {
  position: absolute;
  border: 1px solid #dfd6bf;
  border-radius: .2rem;
  box-shadow: .14rem .3rem .6rem #14291e;
  opacity: 0;
}

.table-cards, .reveal-cards {
  display: flex;
  justify-content: center;
  align-items: start;
  gap: clamp(.25rem, 1.6vw, .65rem);
  max-width: 100%;
}

.trick-cards {
  position: absolute;
  inset: 0;
  width: min(100%, 19rem);
  margin-inline: auto;
}

.played {
  position: absolute;
  top: var(--y);
  left: var(--x);
  transform: translate(-50%, -50%) rotate(var(--angle));
}

.played--top {
  --x: calc(50% - var(--played-width) * .48);
  --y: max(30%, var(--played-width) * .9375 + .34rem);
  --angle: 2deg;
}

.played--right { --x: calc(100% - var(--played-width) * .5); --y: 43%; --angle: 6deg; }
.played--left { --x: calc(var(--played-width) * .5); --y: 57%; --angle: -6deg; }

.played--bottom {
  --x: calc(50% + var(--played-width) * .48);
  --y: min(70%, 100% - var(--played-width) * .9375 - .34rem);
  --angle: -3deg;
}

.table-center .card { width: var(--played-width); }
.played--winner { z-index: 1; }
.played--winner .card { outline: 2px solid #ffe197; outline-offset: 3px; }

.cut-stack { display: grid; place-items: center; }

.cut-packet {
  grid-area: 1 / 1;
  width: var(--played-width);
  border: 1px solid #e1d7bc;
  border-radius: .35rem;
  transform: translate(.6rem, .35rem) rotate(8deg);
  box-shadow: .14rem .18rem 0 #ad9567, .3rem .42rem .45rem #14291e;
}

.cut-reveal {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: .3rem;
  color: #fff9ec;
  font-size: .875rem;
  font-weight: 650;
  text-align: center;
}

.reveal-name {
  margin: 0;
  color: #e3eddd;
  font-size: .875rem;
}

.reveals { display: flex; flex-wrap: wrap; justify-content: center; gap: .65rem 1rem; max-width: 100%; }
.reveal { display: grid; justify-items: center; gap: .35rem; max-width: 100%; }

.notes {
  display: grid;
  gap: .2rem;
  color: #f6e1aa;
  font-size: .875rem;
}

.notes p { margin: 0; }

.actions {
  display: flex;
  flex: none;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: .45rem;
  max-width: 100%;
}

.choice-slot {
  display: grid;
  justify-items: center;
  width: min(100%, 26.5rem);
  min-height: 3rem;
}

.choice-slot:has(> .actions--bids > .button:nth-child(5)) { width: min(100%, 40rem); }

.choice-slot .actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, min(6.3rem, calc((100% - 1.35rem) / 4)));
  align-items: stretch;
  width: 100%;
}

.choice-slot .actions--bids:has(> .button:nth-child(5)) {
  grid-auto-columns: minmax(0, 6.3rem);
  gap: clamp(.16rem, 1vw, .45rem);
}

.choice-slot > .actions.actions--docked {
  position: fixed;
  z-index: 2;
  inset-inline: max(.45rem, env(safe-area-inset-left)) max(.45rem, env(safe-area-inset-right));
  inset-block-end: max(.45rem, env(safe-area-inset-bottom));
  justify-content: center;
  width: auto;
  max-width: 27.1rem;
  margin-inline: auto;
  border: 1px solid var(--line-strong);
  border-radius: .75rem;
  padding: .3rem;
  background: var(--panel);
  box-shadow: 0 .45rem 1.4rem #100a07bf;
}

.choice-slot > .actions--bids.actions--docked:has(> .button:nth-child(5)) { max-width: 40.6rem; }
.shell:has(.actions--docked) .chat-toggle {
  inset-block-end: calc(8rem + env(safe-area-inset-bottom));
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  border: 1px solid #e8c585;
  border-radius: .55rem;
  padding: .45rem .8rem;
  background: #efc87d;
  color: #2b261b;
  font-size: .9375rem;
  font-weight: 750;
  line-height: 1.15;
}

.button--secondary { border-color: #c9aa8359; background: var(--control); color: #fff3d8; }
.actions--bids .button, .button--suit { min-width: 0; min-height: 3rem; }
.actions--bids .button { padding-inline: .12rem; font-size: clamp(.6875rem, 3.75vw, .9375rem); }
.button--suit { border-color: #f0d7a4; background: #fff1d2; color: #25372a; }

@media (hover: hover) {
  .button:hover { background: #ffe2a4; }
  .button--secondary:hover { background: #503a2c; }
  .button--suit:hover { background: #fff9eb; }
  .hand-cards .card:not(:disabled, .card--picked):hover { --fan-lift: -.25rem; }
}

.hand-panel {
  grid-row: 1;
  align-self: start;
  min-width: 0;
}

.hand-selection, .hand-warning {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  color: #e3eddd;
  font-size: .875rem;
  text-align: center;
}

.hand-warning {
  border: 1px solid #ffc08e7a;
  border-radius: .6rem;
  padding: .4rem .65rem;
  background: #472b22;
  color: #ffe5c7;
  font-weight: 650;
}

.hand-cards {
  display: flex;
  justify-content: center;
  align-items: start;
  margin: 0 auto;
  padding: .35rem .15rem .65rem;
}

.hand-cards .card {
  --fan-lift: 0rem;
  flex: none;
  width: var(--hand-card-width);
  transform: translateY(calc(var(--fan-drop) * var(--fan-curve, 1) + var(--fan-lift))) rotate(var(--fan-tilt));
  transform-origin: 50% 88%;
}

.hand-cards .card + .card { margin-inline-start: clamp(-.75rem, -1.7vw, -.35rem); }
.hand-cards .card--picked { --fan-lift: -.62rem; }
.hand-cards .card:focus-visible { z-index: 1; }

.card {
  display: block;
  position: relative;
  width: min(100%, 5.1rem);
  min-width: 0;
  aspect-ratio: var(--card-ratio);
  border: 1px solid #e5dfc8;
  border-radius: .35rem;
  padding: 0;
  background: #f8f6e8;
  box-shadow: 0 .18rem .35rem #14241885;
}

.card-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  pointer-events: none;
}

.card--small { width: clamp(2.1rem, 9.5vw, 3.35rem); }
.card--picked { outline: 2px solid #f2c877; outline-offset: 2px; }

.suit {
  display: block;
  flex: none;
  width: 1.35rem;
  height: 1.35rem;
  object-fit: contain;
}

.guide { max-width: 48rem; }

.guide-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .6rem;
  margin-bottom: .85rem;
}

.guide-bar .brand strong {
  font: 700 1.4rem/1 Georgia, serif;
  letter-spacing: -.04em;
}

.guide-bar .button { text-decoration: none; }
.guide-dismiss { display: none; }

.help-dialog {
  width: min(100% - .8rem, 49rem);
  max-width: none;
  max-height: min(100dvh - .8rem, 58rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: .95rem;
  background: var(--panel);
  color: var(--ink);
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.help-dialog::backdrop { background: #130d09d4; }
body:has(.help-dialog[open]) { overflow: hidden; }
.help-dialog .guide { width: 100%; max-width: none; padding: 0; }
.help-dialog .guide-return { display: none; }
.help-dialog .guide-dismiss { display: block; }

.help-dialog .guide-bar {
  position: sticky;
  z-index: 1;
  top: 0;
  margin-bottom: .65rem;
  border-bottom: 1px solid var(--line);
  padding: .5rem .65rem;
  background: var(--panel);
}

.help-dialog .guide > section { margin-inline: .65rem; }
.help-dialog .guide-panel { scroll-margin-block-start: 4.6rem; }
.guide h1, .guide h2, .guide h3 { margin: 0; font-family: Georgia, serif; }

.guide-intro, .guide-panel {
  border: 1px solid var(--line);
  border-radius: .95rem;
  padding: clamp(.9rem, 3.5vw, 1.55rem);
  margin-bottom: .75rem;
  background: var(--panel-raised);
}

.guide-intro {
  background: radial-gradient(ellipse at 18% 0, #50382b, var(--panel-raised) 82%);
}

.guide-intro h1 { font-size: clamp(2rem, 6vw, 3.25rem); letter-spacing: -.045em; }
.guide-panel h2 { font-size: clamp(1.38rem, 4vw, 1.8rem); letter-spacing: -.02em; }
.guide-example h3 { font-size: 1.18rem; }
.guide p { margin: .55rem 0 0; line-height: 1.48; }
.guide p strong, .guide-steps strong { color: #ffe0a2; }

.guide-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .9rem;
}

.guide-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: .3rem .46rem;
  border: 1px solid var(--line-strong);
  border-radius: .45rem;
  color: #fff3d8;
  background: var(--control);
  font-size: .875rem;
  font-weight: 650;
  text-decoration: none;
}

.guide-panel { scroll-margin-block-start: .55rem; }
.guide-steps { display: grid; gap: .65rem; margin: .75rem 0; padding-inline-start: 1.35rem; line-height: 1.48; }
.guide-steps li::marker { color: var(--gold); font-weight: 750; }

.guide-ranks {
  margin-top: .85rem;
  border: 1px solid #e6bb6e42;
  border-radius: .65rem;
  padding: .6rem .7rem;
  background: #46371e7d;
}

.guide-ranks p { margin-top: .32rem; }

.guide-examples {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: .65rem;
  margin-top: .75rem;
}

.guide-example {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: .65rem;
  padding: .65rem;
  background: var(--panel);
}

.guide-example-heading { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.guide-hand { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; margin-top: .65rem; }

.guide-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: .32rem;
  min-width: 0;
  padding: .33rem .15rem;
  border: 1px solid var(--line-strong);
  border-radius: .5rem;
  background: var(--control);
  color: #fff3d8;
  font-size: .875rem;
  font-weight: 650;
}

.guide-card img {
  width: min(100%, 3.15rem);
  height: auto;
  border-radius: .25rem;
}

.guide-card:hover { border-color: var(--gold); }
.guide-card[data-result="correct"] { background: #5c4327; border-color: var(--gold); }
.guide-card[data-result="retry"] { background: #503329; border-color: #eabb97; }
.guide-feedback:empty { margin: 0; }
.guide-feedback { color: #ffe1a3; }

.guide-score {
  width: 100%;
  margin-top: .65rem;
  border-collapse: collapse;
  text-align: start;
}

.guide-score th, .guide-score td { padding: .45rem .3rem; border-bottom: 1px solid var(--line); }
.guide-score th[scope="row"] { font-weight: 450; }
.guide-score th:last-child, .guide-score td { text-align: end; white-space: nowrap; }
.guide-score td { color: var(--gold); font-weight: 750; }

.guide-details {
  margin-top: .9rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  padding: 0 .65rem;
}

.guide-details summary { padding: .65rem 0; cursor: pointer; font-weight: 700; }
.guide-details dl { margin: 0 0 .65rem; line-height: 1.48; }
.guide-details dt { margin-top: .45rem; font-weight: 700; }
.guide-details dd { margin: .12rem 0 0; color: var(--muted); }

@media (max-width: 34rem) {
  .button--suit { flex-direction: column; gap: .1rem; padding: .25rem .4rem; }
  .button--suit .suit { width: 1.15rem; height: 1.15rem; }
}

@media (max-width: 27rem) {
  .shell { width: calc(100% - .9rem); padding-top: max(.45rem, env(safe-area-inset-top)); }
  .masthead { flex-wrap: wrap; gap: .3rem; margin-bottom: .45rem; }
  .brand { gap: .22rem; }
  .masthead h1 { font-size: clamp(1.16rem, 5.75vw, 1.7rem); }
  .brand-mark { font-size: 1.29rem; }
  .header-actions { gap: .22rem; margin-inline-start: auto; }
  .header-actions .button { font-size: .875rem; padding-inline: .36rem; }
  .difficulty-control:has(select:disabled) { display: none; }
  .difficulty-control::after { right: .55rem; width: .32rem; height: .32rem; }
  .difficulty-control select { width: 4.85rem; padding-inline: .35rem 1rem; font-size: .875rem; }

  .game-status { gap: .5rem; margin-top: .5rem; padding: .5rem .55rem .65rem; }
  .game-status-bar { padding-bottom: .4rem; }
  .game-prompt { gap: .45rem; }
  .bid-history { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
  .bid-history li { flex: none; flex-wrap: nowrap; }

  .table-surface {
    --table-pad-top: .43rem;
    --table-pad-bottom: .5rem;
    --top-seat-row: 3.05rem;
    --trick-row: clamp(7rem, 33vw, 9.15rem);
    --played-width: clamp(2.26rem, 11.8vw, 3.3rem);
    --hand-row: calc(var(--hand-card-width) * 1.875 + 1.5rem);
    --own-score-row: 3.3rem;
    --fan-curve: .72;
    row-gap: .3rem;
  }

  .seat--top { display: flex; align-items: center; justify-self: center; }
  .seat--top .seat-backs { width: auto; flex: none; }
  .player { padding: .3rem .28rem; font-size: .875rem; }
  .player-role { font-size: .75rem; }
  .activity-dot { width: .3rem; height: .3rem; margin-right: .18rem; }
  .seat--left .score-unit, .seat--right .score-unit { font-size: .7rem; }
}

@media (max-width: 19rem) {
  .masthead { gap: .15rem; }
  .masthead h1 { font-size: 1rem; }
  .brand-mark { font-size: 1rem; }
  .header-actions { gap: .15rem; }
  .header-actions .button { padding-inline: .24rem; }
  .difficulty-control select { width: 4.32rem; padding-inline-end: .82rem; }
  .difficulty-control::after { right: .43rem; }
}

@media (min-width: 40rem) {
  .game-prompt {
    flex-direction: row;
    justify-content: space-between;
    text-align: start;
  }

  .game-message { flex: 1; justify-items: start; }
  .game-prompt .actions { flex-shrink: 1; justify-content: end; }
  .hand-selection, .hand-warning { margin-inline: 0; }
}

@media (min-width: 48rem) and (max-height: 60rem) and (hover: hover) and (pointer: fine) {
  .shell:has(.table-surface) {
    --desktop-table-height: clamp(21rem, calc(100dvh - 16.25rem), 39rem);
    width: min(100% - 10rem, max(41rem, calc(var(--desktop-table-height) * 1.38)));
    padding-block: clamp(.65rem, 1.8dvh, 1.25rem) .65rem;
  }

  .shell:has(.table-surface) .masthead { margin-bottom: .5rem; }
  .shell:has(.table-surface) .masthead h1 { font-size: clamp(1.7rem, 4.8dvh, 2.75rem); }
  .shell:has(.table-surface) .brand-mark { font-size: clamp(1.5rem, 4dvh, 2.2rem); }

  .table-surface {
    --table-edge: clamp(.45rem, 1.5dvh, .95rem);
    --table-pad-top: clamp(.65rem, 1.75dvh, 1.15rem);
    --table-pad-bottom: clamp(.65rem, 1.9dvh, 1.65rem);
    --top-seat-row: clamp(3.1rem, calc(var(--desktop-table-height) * .12), 4.7rem);
    --played-width: clamp(2.4rem, calc(var(--desktop-table-height) * .11), 4.3rem);
    --hand-card-width: clamp(3.1rem, calc(var(--desktop-table-height) * .144), 5.6rem);
    --hand-row: calc(var(--hand-card-width) * 1.875 + 1.5rem);
    --own-score-row: 3.4rem;
    height: var(--desktop-table-height);
    grid-template-rows: var(--top-seat-row) minmax(0, 1fr) calc(var(--hand-row) + var(--own-score-row));
    row-gap: .27rem;
  }

  .seat--top { display: flex; align-items: center; justify-self: center; }
  .seat--top .seat-backs { width: auto; flex: none; }
  .game-status { gap: .45rem; margin-top: .5rem; padding: .55rem .7rem; }
  .game-status-bar { padding-bottom: .35rem; }
  .game-prompt:has(> .choice-slot, > .actions > .button:nth-child(2)) {
    display: grid;
    grid-template-columns: minmax(10rem, 1fr) minmax(0, 2fr);
  }
  .game-heading h2 { font-size: clamp(1.3rem, 3.6dvh, 1.85rem); }
  .reveal-cards .card { width: min(2.5rem, 5dvh); }
}

@media (min-width: 62rem) and (max-height: 50rem) and (hover: hover) and (pointer: fine) {
  .shell:has(.table-surface) {
    --desktop-table-height: clamp(21rem, calc(100dvh - 5.5rem), 39rem);
    width: min(100% - 10rem, 76rem);
  }

  .table {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(17rem, 24vw, 22rem);
    align-items: start;
    gap: .75rem;
  }

  .game-status { min-width: 0; margin-top: 0; }
  .game-prompt, .game-prompt:has(> .choice-slot, > .actions > .button:nth-child(2)) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .game-prompt .actions { justify-content: center; }
}

@media (prefers-reduced-motion: no-preference) {
  .card, .button { transition: transform 110ms ease, background-color 110ms ease; }
}
