/* Shared by the ordinary table and its local art room. */
main:has(#table-card-frames:not([hidden])) {
  --stage-gutter: clamp(8px, 2.4vw, 16px);
  --stage-left: max(var(--stage-gutter), env(safe-area-inset-left, 0px));
  --stage-right: max(var(--stage-gutter), env(safe-area-inset-right, 0px));
  /* Match one cqi of the shoe setup header, inside its safe-area padding. */
  --masthead-unit: calc((min(100vw, 34rem) - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) / 100);
  padding-block-start: env(safe-area-inset-top, 0px);
  padding-inline: var(--stage-left) var(--stage-right);
}
/* Both surfaces extend past main's insets to the edge of the phone. */
header:has(#table-card-frames:not([hidden])), #room[data-shoe-setup="false"] {
  margin-inline: calc(0px - var(--stage-left)) calc(0px - var(--stage-right));
}
header:has(#table-card-frames:not([hidden])) {
  --table-menu-inset: calc(4.5 * var(--masthead-unit) - var(--stage-gutter));
  grid-template: "brand code menu" auto "stage stage stage" auto / minmax(0, 1fr) auto auto;
  gap: 0;
  isolation: isolate;
  padding: calc(1.8 * var(--masthead-unit) - 1px) var(--stage-right) 0 var(--stage-left);
  border-block-end: 1px solid transparent;
  background: #0d2923;
  box-shadow: 0 2px 5px #162e232b;
  margin-bottom: 0;
}
/* Anchor one painting to the top of the whole table, including when insurance adds a row. */
header:has(#table-card-frames:not([hidden]))::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  aspect-ratio: 4 / 3;
  max-height: 100%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 52% 28% at 10% 2%, #071d16af, transparent),
    radial-gradient(ellipse 25% 25% at 23% 38%, var(--panda-light, transparent), transparent),
    radial-gradient(ellipse 25% 25% at 80% 38%, var(--tiger-light, transparent), transparent),
    url("table-scene.webp") center top / 100% auto no-repeat;
  -webkit-mask-image: linear-gradient(black 82%, transparent);
  mask-image: linear-gradient(black 82%, transparent);
}
/* Size the insurance scene from the table width, independently of the controls. */
header:has(> #table-card-frames[data-insurance-open="true"]),
header:has(#insurance-bets:not([hidden])) {
  --scene-height: min(75vw, 25.5rem);
  background: linear-gradient(#0d2923bf, #0d2923bf),
              #0d2923 url("/cut-felt.webp") center top / 93px 92px repeat;
}
header:has(> #table-card-frames[data-insurance-open="true"])::before,
header:has(#insurance-bets:not([hidden]))::before {
  inset: 0;
  aspect-ratio: auto;
  background-position: center top;
  background-size: 100% var(--scene-height);
  background-repeat: no-repeat;
  -webkit-mask-image: linear-gradient(black calc(.82 * var(--scene-height)), transparent var(--scene-height));
  mask-image: linear-gradient(black calc(.82 * var(--scene-height)), transparent var(--scene-height));
}
header:has(> #insurance-form:not([hidden])) {
  border-block-end-width: 0;
  margin-block-end: .25rem;
}
header:has(> #insurance-form:not([hidden])) > #table-card-frames {
  padding-block-end: 0;
}
header > #insurance-form {
  grid-column: 1 / -1;
  grid-row: 3;
  margin-block: 0;
  border-color: transparent;
  border-block-start: 0;
  padding-block-start: 8px;
  background: transparent;
}
header:has(#table-card-frames:not([hidden])) > h1 {
  margin-inline-start: calc(env(safe-area-inset-left, 0px) + 6.3 * var(--masthead-unit) - var(--stage-left));
}
header:has(#table-card-frames:not([hidden])) > h1 { grid-area: brand; }
main:has(> #room:not([hidden])) header:has(#table-card-frames:not([hidden])) .table-wordmark {
  width: calc(32.5 * var(--masthead-unit));
}
header:has(#table-card-frames:not([hidden])) > #header-room-code {
  grid-area: code;
  align-self: baseline;
  margin: 0;
  margin-inline-end: clamp(6px, 2vw, 12px);
  font: 650 clamp(.84rem, calc(3.5 * var(--masthead-unit)), 1.1rem)/normal "Noto Serif TC", "Songti TC", "Songti SC", "PMingLiU", serif;
  color: #fff2d9;
  text-shadow: 0 1px 3px #071913;
}
header:has(#table-card-frames:not([hidden])) #header-room-code :is(dt, dd) { font: inherit; color: inherit; }
header:has(#table-card-frames:not([hidden])) #header-room-code dd { letter-spacing: .12em; font-variant-numeric: tabular-nums; }
header:has(#table-card-frames:not([hidden])) > #room-actions-toggle {
  grid-area: menu;
  display: grid;
  align-self: baseline;
  place-content: start center;
  margin-inline-end: var(--table-menu-inset);
  min-width: 44px;
  min-height: 44px;
  padding: 0 .4rem;
  border: 0;
  background: transparent;
  color: #fff1d1;
  line-height: 1.25;
  text-decoration: underline solid #ab8b4e 1px;
  text-underline-offset: .25em;
}
header:has(#table-card-frames:not([hidden])) > #room-actions-toggle[aria-expanded="true"] {
  text-decoration-color: #ebd49b;
}
/* Keep the menu's scroll anchor and the card positions during the reveal. */
header:has(> #table-card-frames[data-hide-masthead]:not([hidden])) > :is(h1, #header-room-code, #room-actions-toggle) {
  visibility: hidden;
}
header:has(#table-card-frames:not([hidden])) > #room-header-actions {
  grid-area: stage;
  inset-inline: auto var(--table-menu-inset);
  inline-size: min(286px, 76vw, calc(100% - var(--table-menu-inset)));
  gap: 0;
  background: transparent;
}
/* Paint a shallow strip behind the full-height touch targets. */
header:has(#table-card-frames:not([hidden])) > #room-header-actions::before {
  content: "";
  position: absolute;
  inset: 50% 0 auto;
  transform: translateY(-50%);
  height: max(26px, 1.625rem);
  box-sizing: border-box;
  border: 1px solid #ab8b4e;
  border-radius: .55rem;
  background: #f7f1e2;
  pointer-events: none;
}
header:has(#table-card-frames:not([hidden])) > #room-header-actions > button {
  position: relative;
  min-block-size: 44px;
  padding-block: 0;
  line-height: 1.2;
  border: 0;
  background: transparent;
  color: #24583e;
}
header:has(#table-card-frames:not([hidden])) > #room-header-actions > #buy-insurance[aria-pressed="true"] {
  isolation: isolate;
  color: #fff7e8;
}
header:has(#table-card-frames:not([hidden])) > #room-header-actions > #buy-insurance[aria-pressed="true"]::before {
  content: "";
  position: absolute;
  inset: 50% 8% auto;
  transform: translateY(-50%);
  height: max(20px, 1.25rem);
  z-index: -1;
  border-radius: .4rem;
  background: #24583e;
  pointer-events: none;
}
header:has(#table-card-frames:not([hidden])) #shoe-history-toggle[aria-expanded="true"] {
  text-decoration: underline;
  text-underline-offset: .2em;
}
header:has(#table-card-frames:not([hidden])) > #room-header-actions > #shoe-history {
  position: absolute;
  inset-block-start: calc(100% + .25rem);
  inset-inline-end: 0;
  width: min(22rem, calc(100vw - var(--stage-left) - var(--stage-right) - var(--table-menu-inset)));
  max-block-size: 68dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: .75rem .875rem .2rem;
  border-color: #bda87a;
  background: #fffcf3;
  text-align: start;
}
#shoe-history .record-id { margin: 0; }
#shoe-proof-title { margin: 0 0 .35rem; font-size: 1.1rem; color: #214837; }
#shoe-history #selected-shoe-id { font-variant-numeric: tabular-nums; }
#shoe-result .lobby-replay-facts {
  padding-inline: .65rem;
  background: #fbf8ef var(--return-paper-art);
  color: var(--lobby-ink);
  font-family: var(--lobby-font);
}
#shoe-result .lobby-replay-facts dt:has(+ dd[hidden]) { display: none; }
#shoe-history .shoe-record-proof {
  padding: .5rem .65rem;
  background: #f3eedf;
  border-radius: .3rem;
  color: #47594c;
}
#shoe-history .shoe-record-proof small { display: block; margin-top: .4rem; }
#shoe-history #selected-hash {
  font: .8125rem/1.45 ui-monospace, monospace;
  overflow-wrap: anywhere;
}
#room-verification-history {
  margin: 0;
  --lobby-ink: #103923;
  --lobby-green: #123e29;
  --return-paper-art: none;
}
#shoe-history #shoe-result:not([hidden]) + details { border-top: 1px solid #ded4bc; }
#room-verification-history > summary {
  padding-block: .7rem;
  color: #24583e;
  font-size: .94rem;
  font-weight: 650;
  cursor: pointer;
}
#table-card-frames {
  --table-card-width: clamp(2.2rem, 12.5vw, 5.5rem);
  grid-area: stage;
  position: relative;
  isolation: isolate;
  padding: clamp(82px, 24vw, 122px) .35rem .65rem;
}
#round-title {
  grid-area: auto;
  position: absolute;
  inset: 1rem auto auto 50%;
  transform: translateX(-50%);
}
#last-round-marker, #round-net-total { color: #ffedc6; }
#last-round-marker {
  padding: 2px 5px;
}
#last-round-marker::before {
  content: "";
  position: absolute;
  inset: -3px -12px;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse closest-side, #0b2923eb 38%, #0b2923bf 65%, transparent);
}
#round-winning-bet[data-side-bet="false"] {
  /* Leave felt visible on both sides of the two-character result in the 4.5rem column. */
  font-size: min(var(--winning-score-size), 2rem);
}
#shoe-ending-notice {
  position: absolute;
  left: 50%;
  top: calc(var(--table-card-width) * 88 / 63 + var(--table-card-gap) / 2);
  transform: translate(-50%, -50%);
  display: grid;
  gap: 2px;
  padding: 3px 5px;
  border: 1px solid #ae9761;
  border-radius: 5px;
  background: #163d32;
  color: #fff6e4;
  font-size: clamp(12px, 3.6vw, 16px);
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  z-index: 5;
}
#shoe-ending-seconds { font-size: .82em; color: #edd29b; }
#table-card-frames:has(#shoe-ending-notice:not([hidden])) :is(#round-winning-bet, #last-round-marker) {
  visibility: hidden;
}
#round-id {
  display: inline-block;
  padding: 3px 12px;
  color: #e6cc93;
  font: 500 13px/1.2 "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  background: radial-gradient(ellipse closest-side, #0b2923eb 30%, transparent);
}
#round-id > span {
  display: inline-block;
  min-inline-size: 2ch;
  text-align: center;
  color: #fff6e4;
  font: 600 18px/1.1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
.table-player-label, .table-banker-label {
  margin-block-start: .45rem;
  font: 700 .84rem/1.1 Georgia, serif;
  letter-spacing: .05em;
}
.table-player-label { color: #acd8f5; }
.table-banker-label { color: #ffb9a2; }
#round-winning-bet:not([hidden]), #round-net-amount:not(:empty) {
  border-radius: .2em;
  background: #fff6df;
}
#round-net-amount[data-result=""], #round-net-amount:not([data-result]) { color: #4d6057; }
#round-countdown:not([data-pinned="true"]) { box-shadow: 0 0 0 2px #ab9259, 0 3px 8px #041713; }
/* Use the space between the two hands, directly above the first betting row. */
#round-countdown-anchor {
  top: auto;
  bottom: 0;
  height: var(--countdown-size);
  margin-block-start: 0;
}
#round-countdown {
  pointer-events: none;
}
#round-countdown[data-pinned="true"] {
  z-index: 8;
}
/* These overlays extend beyond the header over the betting board and roads. */
header:has(#round-countdown[data-pinned="true"]:not([hidden])),
header:has(> #room-header-actions:not([hidden]) > #shoe-history:not([hidden])) {
  z-index: 8;
}
#room-header-actions:has(> #shoe-history:not([hidden])) {
  z-index: 9;
}

/* Quiet corner marks become an illuminated edge only once the card has arrived. */
.table-card-frame[aria-hidden="true"]:not([data-card-peek="true"]) {
  --corner: linear-gradient(#b9a67899, #b9a67899);
  border-color: transparent;
  box-shadow: none;
  background:
    var(--corner) top left, var(--corner) top right,
    var(--corner) bottom left, var(--corner) bottom right,
    var(--corner) top left, var(--corner) top right,
    var(--corner) bottom left, var(--corner) bottom right;
  background-size: 9px 1px, 9px 1px, 9px 1px, 9px 1px, 1px 9px, 1px 9px, 1px 9px, 1px 9px;
  background-repeat: no-repeat;
  background-color: #0b201f38;
}
.table-card-frame[aria-hidden="false"], .table-card-frame[data-card-peek="true"] {
  border-color: #e3c483;
  box-shadow: 0 0 5px #d6b67863, 0 3px 6px #041713bf;
}

/* Illuminate only after the public result is actually on screen, including side-bet wins. */
header:has(#round-winning-bet:not([hidden])):has(#player-table-score[data-winning="true"]),
header:has(#round-winning-bet[data-kind="tie"]:not([hidden])) {
  --panda-light: #c1e4ed35;
}
header:has(#round-winning-bet:not([hidden])):has(#banker-table-score[data-winning="true"]),
header:has(#round-winning-bet[data-kind="tie"]:not([hidden])) {
  --tiger-light: #f3c2763d;
}
#table-card-frames:has(#round-winning-bet:not([hidden])) .table-card-side:has([data-winning="true"])::after,
#table-card-frames:has(#round-winning-bet[data-kind="tie"]:not([hidden])) .table-card-side::after {
  content: "";
  position: absolute;
  pointer-events: none;
  inset: auto var(--rail-right, 50%) .24rem var(--rail-left, .35rem);
  height: 2px;
  background: linear-gradient(var(--rail-angle, 90deg), transparent, #e7c783);
  transform-origin: var(--rail-origin, left);
  animation: lab-result-rail .55s ease-out both;
}
.table-card-side:has(#banker-table-score) {
  --rail-left: 50%;
  --rail-right: .35rem;
  --rail-origin: right;
  --rail-angle: 270deg;
}
@keyframes lab-result-rail {
  from { transform: scaleX(0); opacity: 0; }
  to { transform: scaleX(1); opacity: 1; }
}
#room[data-shoe-setup="false"] {
  --lab-rule: #c7b58c;
  --betting-felt: #1c4033;
  --main-bet-gradient-angle: 97deg;
  min-inline-size: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
}
#room[data-shoe-setup="false"],
#room[data-shoe-setup="false"] #chip-picker {
  background: radial-gradient(ellipse at 50% 45%, #32614b65, #092f2599),
              var(--betting-felt) url("/cut-felt.webp") center / 93px 92px repeat;
}
#chip-picker #custom-chip-editor label { color: #fff2d8; }
#bet-form #bet-choices {
  --odds-size: clamp(.875rem, 3.75vw, 1rem);
  --odds-line: calc(1.22 * var(--odds-size));
  --closed-label-height: 1.4rem;
  --bet-win-fill: #c9f4d6;
  --bet-win-border: #23664f;
  --ribbon-player: #c4dae9;
  --ribbon-tie: #cce2ce;
  --ribbon-banker: #edc8bd;
  --player-bet-line: #006cff;
  --tie-bet-line: #00853e;
  --banker-bet-line: #df1940;
  inline-size: 100%;
  /* Equal side-bet quarters and a main row split 22:16:22. */
  grid-template-columns: 15fr 7fr 8fr 8fr 7fr 15fr;
  grid-template-areas:
    "big-panda   player-char-siu player-char-siu banker-char-siu banker-char-siu big-tiger"
    "small-panda player-char-siu player-char-siu banker-char-siu banker-char-siu small-tiger"
    "player      player          tie             tie             banker          banker";
  gap: 0;
  padding: .45rem 0 0;
  background: linear-gradient(#0d2923, var(--betting-felt));
}
#bet-chips .chip-shortcuts {
  border-color: transparent;
  background-color: transparent;
}
#bet-chips #chip-picker-toggle {
  color: #fff2d8;
  font-weight: 400;
  background:
    linear-gradient(var(--lab-rule), var(--lab-rule)) center bottom / 85% 1px no-repeat,
    linear-gradient(var(--main-bet-gradient-angle),
      transparent calc(50% - .5px),
      var(--lab-rule) calc(50% - .5px) calc(50% + .5px),
      transparent calc(50% + .5px)) right center / 5px 18px no-repeat;
  border-color: transparent;
}
#bet-chips button[data-denomination][aria-pressed="true"] {
  --chip-face: #21634d;
  color: #fff5d9;
}
#bet-chips button[aria-pressed="true"]:is(
  [data-denomination="10000"], [data-denomination="20000"], [data-denomination="custom-plaque"]
)::before {
  box-shadow: inset 0 0 0 1px var(--chip-rim), 0 0 0 2px #e8cb85;
}
#bet-form > #bet-chips, #bet-form > .chip-details, #room[data-shoe-setup="false"] #round-advance-slot {
  margin-inline: var(--stage-left) var(--stage-right);
}
#bet-types button {
  inline-size: auto;
  justify-self: stretch;
  border-radius: 0;
}
#bet-closed-notice { border-radius: 0; }
#bet-choices:not([data-settled]) #bet-closed-notice {
  --bet-closed-tint: rgb(21 42 35 / .28);
}
#bet-closed-notice strong {
  grid-row: 1 / 3;
  display: grid;
  align-items: center;
  height: var(--closed-label-height);
  padding: 0 .65rem;
  line-height: 1;
  white-space: nowrap;
}
#bet-types button:focus-visible {
  position: relative;
  outline-offset: -3px;
}
/* Each row draws its top edge so the shared seams stay one pixel wide. */
#bet-types button:not(:is(.bet-player, .bet-tie, .bet-banker)) {
  border-color: var(--lab-rule);
  border-inline-end-width: 0;
  border-block-end-width: 0;
  background: #fcf6e8 url("/shoe-paper.webp");
}
#bet-types button.bet-player-char-siu {
  --main-bet-accent: var(--player-accent);
  color: var(--player-accent);
}
#bet-types button.bet-banker-char-siu {
  --main-bet-accent: var(--banker-accent);
  color: var(--banker-accent);
}
#bet-types button:is(.bet-big-tiger, .bet-small-tiger) {
  border-inline-end-width: 1px;
}
/* Anchor the three inner rules to the two full-height char siu cells. */
#bet-choices #bet-types :is(.bet-player-char-siu, .bet-banker-char-siu, .bet-big-tiger, .bet-small-tiger) {
  border-inline-start-color: transparent;
}
#bet-types :is(.bet-player-char-siu, .bet-banker-char-siu) { position: relative; }
#bet-types :is(.bet-player-char-siu, .bet-banker-char-siu)::before,
#bet-types .bet-banker-char-siu::after {
  content: "";
  position: absolute;
  inset-block: 20%;
  inline-size: 1px;
  background: var(--lab-rule);
  pointer-events: none;
}
#bet-types :is(.bet-player-char-siu, .bet-banker-char-siu)::before { inset-inline-start: -1px; }
#bet-types .bet-banker-char-siu::after { inset-inline-end: 0; }
/* One drawing spans the three real buttons. The winning fill reuses the
   same polygon as its normal face, including both endpoints of each seam. */
.main-bet-ribbon {
  grid-area: 3 / 1 / 4 / -1;
  position: relative;
  pointer-events: none;
}
.main-bet-ribbon svg {
  position: absolute;
  inset: .5px;
  width: calc(100% - 1px);
  height: calc(100% - 1px);
  overflow: visible;
  stroke-linejoin: round;
}
.ribbon-player { --face: var(--ribbon-player); --edge: var(--player-bet-line); }
.ribbon-tie { --face: var(--ribbon-tie); --edge: var(--tie-bet-line); }
.ribbon-banker { --face: var(--ribbon-banker); --edge: var(--banker-bet-line); }
.ribbon-light { stop-color: color-mix(in srgb, var(--face) 25%, white); }
.ribbon-dark { stop-color: var(--face); }
.ribbon-faces polygon { stroke: var(--edge); }
#main-bet-winner {
  fill: var(--bet-win-fill);
  stroke: var(--bet-win-border);
}

#bet-choices #bet-types button:is(.bet-player, .bet-tie, .bet-banker) {
  position: relative;
  appearance: none;
  border-color: transparent;
  border-inline-width: 0;
  background: transparent;
}
/* The overlay dims the whole board. A personal stake changes only its label. */
#bet-types button:disabled { opacity: 1; }
#bet-choices[data-settled] .ribbon-faces,
#bet-choices[data-settled] #bet-types button:not([data-round-win]) { opacity: .8; }
#bet-choices #bet-types button[data-round-win]:not(:is(.bet-player, .bet-tie, .bet-banker)) {
  border-color: var(--bet-win-border);
  background: var(--bet-win-fill);
  box-shadow: inset 0 0 0 1px var(--bet-win-border);
}
#bet-types button:is(.bet-player, .bet-tie, .bet-banker) > :first-child {
  font-size: clamp(1.5rem, 6.2vw, 1.8rem);
}
#bet-types button > :first-child, #room-members h3 {
  font-family: "Songti TC", "Noto Serif TC", serif;
  font-weight: 700;
}
#bet-types button > :first-child {
  display: inline-flex;
  align-items: center;
  gap: .14em;
  font-size: clamp(.98rem, 4.6vw, 1.25rem);
  line-height: 1.15;
  white-space: nowrap;
}
#bet-types .road-icon { flex: none; width: 1.24em; height: 1.24em; }
#bet-types .bet-odds {
  color: #43554a;
  font-size: var(--odds-size);
  line-height: var(--odds-line);
  font-weight: 600;
}
/* Reserve all three payout lines even when a stake replaces them. */
#bet-types :is(.bet-player-char-siu, .bet-banker-char-siu) {
  grid-template-rows: max-content var(--odds-line) calc(2 * var(--odds-line));
  /* The closed badge occupies the bottom edge between these two cells. */
  padding-block-end: var(--closed-label-height);
}
#bet-types.show-stake-label .bet-amount { max-width: 100%; }
#bet-types button:not(:is(.bet-player, .bet-tie, .bet-banker)) .bet-amount {
  font-size: clamp(.82rem, 3.75vw, 1.1rem);
}
#bet-choices #bet-types.show-stake-label .bet-amount:not([hidden]),
#insurance-bets .bet-amount[data-funded="true"]:not([hidden]) {
  display: inline-flex;
  align-items: center;
  place-self: center;
  width: max-content;
  padding: 1px 3px;
  gap: .22em;
  border-radius: 3px;
  background: #e0b95d;
  color: #271f12;
  font-weight: 700;
}

#room #big-road {
  margin-inline: 2.5%;
  padding: .2rem;
  border: 1px solid #c7b48e;
  border-radius: .6rem;
  background-color: #fffaf0;
}
#road-info, .recent-round { background-color: #fcf6e8; }
#icon-legend { display: none; }
#room-members {
  padding-block: .8rem .6rem;
  padding-inline: 5%;
  background: #fcf7ec;
  text-align: start;
}
#room-members h3 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 .25rem;
  color: #224c3b;
}
#seat-count {
  color: #516458;
  font: 500 .875rem/1.2 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
#members {
  margin: 0;
  padding-inline-start: 0;
  list-style: none;
}
#members li {
  display: grid;
  grid-template-columns: 2ch minmax(0, 1fr) auto;
  align-items: baseline;
  column-gap: .65rem;
  padding-inline: 0;
}
#members .member-rank {
  color: #516458;
  font-variant-numeric: tabular-nums;
}
#members .current-player .member-name {
  color: #224c3b;
  font-weight: 600;
}
#members .host {
  margin-inline-start: 0;
  white-space: nowrap;
}
#members li:last-child { border-bottom: 0; }

/* Insurance controls and settlement cards share the ordinary table layout. */
body > #round-countdown[data-pinned="true"] {
  z-index: 11;
  pointer-events: none;
}
body:has(> #round-countdown[data-insurance="true"]) #round-opening-notice {
  color: #ffe2a0;
}
#table-card-frames[data-insurance-open="true"] {
  .table-card-score {
    font-size: calc(var(--winning-score-size) * .8);
  }
  .table-card-score[data-insurance-side] {
    -webkit-text-stroke: 2px #10332f;
  }
  .table-card-side:has(.table-card-score[data-insurance-side="true"]:not(:empty)) {
    --label-top-gap: .45rem;
    position: relative;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    > * { grid-column: 1 / -1; }
    .table-player-label, .table-banker-label {
      grid-row: 4;
      align-self: center;
      margin-block-start: var(--label-top-gap);
    }
    .table-player-label {
      grid-column: 1;
      justify-self: end;
      margin-inline-end: 2px;
    }
    .table-banker-label {
      grid-column: 2;
      justify-self: start;
      margin-inline-start: 2px;
    }
    .table-score-insurance {
      /* Leave row sizing to the English label, including its top margin. */
      position: absolute;
      grid-area: 4 / 1 / 5 / -1;
      inset-block-start: calc(50% + var(--label-top-gap) / 2);
      inset-inline-end: calc(50% + 2px);
      transform: translateY(-50%);
      padding: 3px 5px;
      font-size: clamp(1rem, 4.4vw, 1.125rem);
      font-weight: 700;
    }
    .table-player-label ~ .table-score-insurance {
      inset-inline: calc(50% + 2px) auto;
    }
  }
}

/* These are the same cards before and after the last reveal. Use the hand
   columns from the parent grid and stack each later offer below the first. */
#table-card-frames > #insurance-bets {
  border: 0;
  padding: 0;
}
#insurance-bets .insurance-group {
  position: relative;
  align-self: start;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding-top: 6px;
}
.insurance-group:not(:has(> button:not([hidden]))) { display: none; }
.insurance-group::before {
  content: "";
  position: absolute;
  inset: 0 10% auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, #d8bd7c 25% 75%, transparent);
  pointer-events: none;
}
#insurance-bets button {
  --slip-face: #f9f1df;
  --slip-brass: #ad9569;
  --slip-edge: #786747;
  --slip-corner: #967647;
  position: relative;
  flex: none;
  box-sizing: border-box;
  width: min(100%, 8.75rem);
  min-width: 0;
  min-height: 44px;
  align-content: start;
  align-items: center;
  justify-content: stretch;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "name stage odds" "money money money";
  grid-template-rows: auto 2.25rem;
  gap: 1px 4px;
  padding: 1px 2px;
  border: 1px solid transparent;
  border-radius: 8px 3px;
  background:
    linear-gradient(var(--slip-face), var(--slip-face)) padding-box,
    linear-gradient(145deg, var(--slip-brass), var(--slip-edge) 55%, var(--slip-brass)) border-box;
  box-shadow: inset 0 0 0 1px #fff8e6, 0 1px 2px #081c1738;
  color: #423921;
  font-family: "Lobby Wallet", system-ui, sans-serif;
  font-variant-numeric: lining-nums tabular-nums;
  font-size: .81rem;
  line-height: 1.15;
}
#insurance-bets button[data-state="open"] {
  --slip-brass: #ebd29a;
  --slip-edge: #9c783f;
  --slip-corner: #ad7a24;
}
#insurance-bets button:is([data-state="closed"], [data-state="loss"],
                          [data-state="push"], [data-state="unbet"]) {
  --slip-face: #dfc2a3;
  --slip-brass: #ab835b;
  --slip-edge: #715037;
  --slip-corner: #875d39;
  box-shadow: inset 0 0 0 1px #efdbc5, 0 1px 2px #081c1738;
}
#insurance-bets button[data-state="win"] {
  --slip-face: var(--bet-win-fill);
  --slip-brass: #92d8b0;
  --slip-edge: var(--bet-win-border);
  --slip-corner: var(--bet-win-border);
  box-shadow: inset 0 0 0 1px #b1e3c5;
}
/* Meet the outside edge of the 1px border and follow its full corner radius. */
#insurance-bets button::before,
#insurance-bets button::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
  width: 24px;
  height: 13px;
  border: solid var(--slip-corner);
  pointer-events: none;
}
#insurance-bets button::before {
  inset: -1px auto auto -1px;
  border-width: 2px 0 0 2px;
  border-top-left-radius: inherit;
}
#insurance-bets button::after {
  inset: auto -1px -1px auto;
  border-width: 0 2px 2px 0;
  border-bottom-right-radius: inherit;
}
@media (forced-colors: active) {
  #insurance-bets button { border-color: ButtonText; }
}
#insurance-bets button > span:nth-child(2) { grid-area: name; white-space: nowrap; }
#insurance-bets .insurance-odds { grid-area: odds; font-size: .8rem; }
#insurance-bets .insurance-stage { grid-area: stage; align-self: center; color: #605849; }
#insurance-bets .bet-amount[data-funded]::before { content: "已投保"; }
#insurance-bets .bet-amount[data-funded]::before,
#bet-choices #bet-types.show-stake-label .bet-amount::before {
  font-size: .6875rem;
  font-weight: 500;
  line-height: 1.12;
}
#insurance-bets .bet-amount[data-funded="false"] { color: #62665f; }
/* On the ribbon the stake and net occupy the button's existing odds tracks.
   Their text must also have a size when the native button is disabled. */
#bet-types .wager-money {
  display: contents;
  font-family: "Lobby Wallet", system-ui, sans-serif;
  font-variant-numeric: lining-nums tabular-nums;
}
#bet-choices #bet-types.show-stake-label .wager-money .bet-amount:not([hidden]) {
  grid-area: 2 / 1 / 4 / 2;
  min-block-size: 0;
  padding: 0 3px;
  gap: 2px;
  font-size: var(--wager-stake-size, clamp(.875rem, 4vw, 1.375rem));
  font-weight: 750;
  line-height: 1;
}
#bet-choices #bet-types.show-stake-label button:has(.bet-net-result:not([hidden]), .bet-limit-notice[data-reason="odd"]:not([hidden])) .bet-amount:not([hidden]) {
  grid-row: 2;
  font-size: var(--wager-stake-size, clamp(.8125rem, 3.6vw, 1.0625rem));
}
#bet-types .wager-money .bet-net-result {
  grid-area: 3 / 1;
  place-self: start center;
  width: min(100%, 8.75rem);
  min-block-size: 0;
  padding-inline: 3px;
  text-align: right;
  font-size: var(--wager-net-size, clamp(.875rem, 3.8vw, 1.125rem));
  font-weight: 700;
  line-height: 1;
}
#bet-types button:has(.bet-limit-notice[data-reason="limit"]:not([hidden])) .wager-money {
  display: none;
}

#bet-types button .wager-money:has(.bet-amount:not([hidden])),
#insurance-bets .wager-money {
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-family: "Lobby Wallet", system-ui, sans-serif;
  font-variant-numeric: lining-nums tabular-nums;
  --wager-stake-cap: min(1.5rem, 85cqh);
  /* The label, gap and padding are reserved before fitting the actual tabular digits. */
  --stake-fit: calc((100cqi - var(--wager-label-space, 2.625rem) - 1px) / var(--stake-digits, 5) / .60);
  --wager-stake-size: min(var(--stake-fit), calc(min(var(--wager-stake-cap), (100cqi - var(--wager-label-space, 2.625rem)) / var(--wager-digits-em, 3.2)) * .875));
  --wager-net-size: min(1.375rem, var(--wager-net-height, 60cqh), 22cqi);
}
#bet-types button .wager-money:has(.bet-net-result:not([hidden])),
#insurance-bets .wager-money:has(.bet-net-result:not([hidden])) {
  --wager-stake-cap: min(1.125rem, 42cqh);
}
/* Fit both amounts inside the existing odds rows; keep the betting target and title in place. */
#bet-types button .wager-money:has(.bet-amount:not([hidden])) {
  grid-area: 2 / 1 / 4 / 2;
  place-self: center;
  width: min(calc(100% - var(--stake-seam, 0%)), 8.75rem);
  margin-inline-start: var(--stake-seam, 0%);
  height: min(100%, 2.25rem);
  --wager-label-space: 1.875rem;
}
/* In the 600-unit ribbon each diagonal enters the cell on its right by 12 units. */
#bet-types .bet-tie {
  --stake-seam: calc(100% * 12 / 160);
  --main-track: 160;
}
#bet-types .bet-banker {
  --stake-seam: calc(100% * 12 / 220);
}
#bet-types :is(.bet-player, .bet-tie, .bet-banker) .wager-money:has(.bet-net-result[hidden]) {
  /* All three amounts use the tie's safe 148-unit span, less the button's horizontal padding. */
  width: min(8.75rem, calc((100% + .25rem) * 148 / var(--main-track, 220) - .25rem));
  --wager-stake-size: min(100cqh, var(--stake-fit));
}
/* The side bets fit four stake digits beside the label in a quarter-width cell. */
#bet-types button:not(:is(.bet-player, .bet-tie, .bet-banker)) .wager-money {
  --wager-digits-em: 2.5;
  /* Leave a full label line and the gap above the net even in the shorter tiger/panda cells. */
  --wager-net-height: min(60cqh, calc(100cqh - .85rem));
}
#bet-types .bet-banker .bet-limit-notice[data-reason="odd"] {
  color: #fff7df;
  background: #26211b;
  border: 1px solid #f4cc74;
  border-radius: .3rem;
  padding: 1px .25em;
  font-weight: 700;
  max-width: 100%;
  white-space: normal;
  text-align: center;
}
#bet-types .bet-banker:has(.bet-limit-notice[data-reason="odd"]:not([hidden])) .wager-money {
  grid-row: 2;
}
#insurance-bets .wager-money {
  grid-area: money;
  place-self: stretch;
}
#insurance-bets .wager-money .bet-net-result[hidden] {
  display: none !important;
}
#insurance-bets .wager-money .bet-amount[data-funded]:not([hidden]) {
  display: flex;
  align-items: center;
  width: min(100%, 8.75rem);
  min-block-size: 0;
  padding: 0 3px;
  justify-content: space-between;
  gap: 2px;
  font-size: var(--wager-stake-size);
  font-weight: 750;
  line-height: 1;
}
#insurance-bets .wager-money .bet-amount[data-funded="true"]:not([hidden]) {
  width: max-content;
  max-width: 100%;
}
#insurance-bets .wager-money .bet-net-result {
  width: min(100%, 8.75rem);
  min-block-size: 0;
  padding-inline: 3px;
  text-align: right;
  font-size: var(--wager-net-size);
  font-weight: 700;
  line-height: 1;
}

/* All eight pixels below the controls are painted by the header itself. */
header:has(#insurance-bets:not([hidden])) {
  padding-block-end: 8px;
  margin-block-end: 0;
  border-bottom: 0;
  box-shadow: none;
}
header:has(#insurance-bets:not([hidden])) ~ #room {
  padding-block-start: 0;
}
header:has(#insurance-bets:not([hidden])) ~ #room #bet-choices {
  padding-block-start: 0;
}

#insurance-form {
  position: relative;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 0 .25rem;
}
#insurance-art-caption {
  grid-column: 1 / -1;
  place-self: end start;
  position: relative;
  margin-block-end: 2px;
  padding-inline: 1.45rem .2rem;
  color: #f6ecd8;
  font-family: "Lobby Wallet", system-ui, sans-serif;
  font-size: .875rem;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: .06em;
  white-space: nowrap;
}
#insurance-art-caption::before,
#insurance-art-caption::after {
  content: "";
  position: absolute;
  inset-block-start: .675em;
  background: #c8aa70;
}
#insurance-art-caption::before {
  inset-inline-start: .28rem;
  width: .75rem;
  height: 1px;
}
#insurance-art-caption::after {
  inset-inline-start: .9rem;
  width: 4px;
  height: 4px;
  transform: translateY(-50%) rotate(45deg);
}
#insurance-art-caption[data-funded="true"] {
  color: #f1cd80;
}
#insurance-active-quote {
  /* Anchor to the caption row without contributing to its height. */
  position: absolute;
  grid-area: 1 / 7 / 2 / -1;
  inset-block-end: 0;
  inset-inline-end: 0;
  margin-block-end: 2px;
  color: #f6ecd8;
  font: 500 .8125rem/1.35 "Lobby Wallet", system-ui, sans-serif;
  white-space: nowrap;
}
#insurance-active-odds {
  margin-inline-start: .15rem;
  color: #f1cd80;
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
#insurance-form .insurance-art-preset {
  grid-row: 2;
  grid-column: span 3;
  position: relative;
  isolation: isolate;
  min-height: 50px;
  padding: 5px 6px 7px;
  border: 0;
  background-clip: content-box;
  gap: .15rem;
  line-height: 1.1;
}
/* Shape the rim and face separately so the whole button remains tappable. */
#insurance-form .insurance-art-preset::before,
#insurance-form .insurance-art-preset::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  clip-path: polygon(6px 0, calc(100% - 6px) 0, 100% 6px, 100% calc(100% - 6px),
                     calc(100% - 6px) 100%, 6px 100%, 0 calc(100% - 6px), 0 6px);
}
#insurance-form .insurance-art-preset::before {
  background: linear-gradient(160deg, #ebd393, #a58a50 54%, #715329 80%);
}
#insurance-form .insurance-art-preset::after {
  inset: 1px 1px 3px;
  background-color: inherit;
  box-shadow: inset 0 1px 0 #fff9;
}
#insurance-form .insurance-art-preset > span:first-child {
  font-size: .78rem;
  font-weight: 550;
  letter-spacing: .04em;
}
#insurance-form .insurance-art-preset strong {
  font-family: "Lobby Wallet", system-ui, sans-serif;
  font-size: clamp(1.06rem, 4.8vw, 1.25rem);
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 359px) {
  #insurance-form { padding-inline: .1rem; column-gap: .18rem; }
  #insurance-form .insurance-art-preset strong { font-size: 1rem; }
}
#insurance-form .insurance-art-preset:is(:enabled:active, [data-pressed="true"]) {
  opacity: 1;
}
#insurance-form .insurance-art-preset:is(:enabled:active, [data-pressed="true"])::after {
  inset-block: 3px 1px;
  box-shadow: inset 0 3px 5px #51380e70;
}
#insurance-form .insurance-art-preset:is(:enabled:active, [data-pressed="true"]) > * {
  transform: translateY(2px);
}
#insurance-form .insurance-art-preset:focus-visible {
  outline: 2px solid #fff1c8;
  outline-offset: 1px;
}
#insurance-form :is(#insurance-clear, #insurance-preset-0) {
  grid-row: 3;
  margin-block-start: .45rem;
  height: 2.9rem;
  font-size: clamp(.75rem, 3.5vw, .8125rem);
  line-height: 1.1;
}
#insurance-form :is(#insurance-clear, #insurance-preset-0):is(:enabled:active, [data-pressed="true"]) {
  transform: translateY(2px);
}
#insurance-preset-0 { grid-column: 1 / 9; }
#insurance-clear { grid-column: 9 / -1; }
#insurance-form #insurance-clear:disabled {
  --key-top: #3a5046; --key-bottom: #2e3e37; --key-edge: #4d6055;
  --key-rim: #53665a; --key-ink: #c4cfc5;
}
main:has(#table-card-frames[data-insurance-open="true"]) #bet-closed-notice strong {
  padding: .2rem .6rem;
  background: #384d43;
  color: #f2f0e2;
  font-size: .81rem;
  font-weight: 550;
  line-height: 1.2;
}
