:root {
  color-scheme: light;
  --paper: #f6f3ee;
  --paper-strong: #fffdf8;
  --ink: #2b2b2b;
  --ink-soft: #6b6b64;
  --rule: #d8d2c4;
  --rule-strong: #aaa394;
  --vermilion: #9b1c1c;
  --vermilion-dark: #751313;
  --green: #2e6b4e;
  --green-soft: #dce8df;
  --brass: #c9a44a;
  --oak: #dcc9a6;
  --blotter: #20292b;
  --blue: #547ba0;
  --shadow-paper: 0 7px 16px rgba(43, 43, 43, 0.16);
  --shadow-lifted: 0 14px 24px rgba(31, 24, 18, 0.23);
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-ui: Aptos, "Segoe UI", Arial, sans-serif;
  --cut: 6px;
  --focus: 0 0 0 2px var(--paper-strong), 0 0 0 4px var(--vermilion);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--oak);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background-color: var(--oak);
  background-image: url("assets/visual/pale-oak-texture.png");
  background-size: 720px 720px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  min-width: 0;
  font: 600 0.78rem/1.15 var(--font-ui);
}

button,
select {
  cursor: pointer;
}

button {
  letter-spacing: 0.025em;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

input,
select {
  min-height: 38px;
  border: 1px solid var(--rule-strong);
  border-radius: 0;
  background: rgba(255, 253, 248, 0.78);
  color: var(--ink);
  padding: 0 11px;
}

input::placeholder {
  color: #817c72;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) 250px;
  gap: 8px;
  width: min(100%, 1600px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 8px;
}

.topbar,
.table-core,
.seat-card,
.ledger-panel,
.reaction-panel,
.game-card,
.action-toast,
.final-results {
  background-color: var(--paper);
  background-image: url("assets/visual/paper-texture.png");
  background-size: 620px 620px;
}

.topbar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(225px, 1fr) auto minmax(225px, 1fr);
  align-items: center;
  min-width: 0;
  border: 1px solid var(--rule-strong);
  padding: 8px 14px;
  clip-path: polygon(var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}

.brand {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.65rem);
  font-weight: 600;
  letter-spacing: 0.035em;
  line-height: 1;
  text-transform: uppercase;
}

.brand p {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
}

.phase-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  min-width: 300px;
  border-inline: 1px solid var(--rule);
}

.phase-strip > div {
  display: grid;
  gap: 1px;
  padding: 2px 18px;
  border-right: 1px solid var(--rule);
}

.phase-strip > div:last-child {
  border-right: 0;
}

.phase-strip span {
  color: var(--ink-soft);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.phase-strip strong {
  font-family: var(--font-display);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.primary-button,
.ghost-button,
.card-action,
.reaction-actions button,
.chat-form button,
.quick-amounts button {
  min-height: 38px;
  border: 1px solid var(--rule-strong);
  border-radius: 0;
  padding: 0 15px;
  text-transform: uppercase;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.primary-button,
.card-action,
.chat-form button {
  border-color: var(--vermilion-dark);
  background: var(--vermilion);
  color: var(--paper-strong);
}

.ghost-button,
.quick-amounts button {
  background: rgba(255, 253, 248, 0.6);
  color: var(--ink);
}

.primary-button:not(:disabled):hover,
.card-action:not(:disabled):hover,
.chat-form button:not(:disabled):hover {
  background: var(--vermilion-dark);
  transform: translateY(-1px);
}

.ghost-button:not(:disabled):hover,
.quick-amounts button:not(:disabled):hover {
  border-color: var(--ink);
  background: var(--paper-strong);
  transform: translateY(-1px);
}

.top-actions .primary-button {
  border-color: var(--rule-strong);
  background: transparent;
  color: var(--ink);
}

.top-actions .primary-button:hover {
  border-color: var(--vermilion);
  background: transparent;
  color: var(--vermilion);
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.table-scene {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(65, 49, 36, 0.6);
  background-color: var(--oak);
  background-image: url("assets/visual/pale-oak-texture.png");
  background-size: 760px 760px;
}

.table-scene::after {
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(62, 47, 35, 0.22);
  content: "";
  pointer-events: none;
}

.table-core {
  position: absolute;
  z-index: 2;
  top: 86px;
  right: 184px;
  bottom: 70px;
  left: 184px;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule-strong);
  padding: 18px 24px;
  text-align: center;
  box-shadow: var(--shadow-paper);
  clip-path: polygon(var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}

.seal {
  position: relative;
  display: grid;
  width: 70px;
  height: 70px;
  flex: 0 0 auto;
  place-items: center;
  margin-bottom: 7px;
}

.seal img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 5px 4px rgba(55, 22, 17, 0.22));
}

.seal span {
  position: relative;
  z-index: 1;
  color: transparent;
  font-size: 0;
}

.turn-notice {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper-strong);
  padding: 0 15px;
  font-family: var(--font-display);
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.turn-notice[data-tone="urgent"],
.turn-notice[data-tone="finished"] {
  border-color: var(--vermilion-dark);
  background: var(--vermilion);
}

.turn-notice[data-tone="negotiation"],
.turn-notice[data-tone="reaction"] {
  border-color: var(--green);
  background: var(--green);
}

.table-core h2 {
  max-width: 760px;
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 2.5vw, 2.6rem);
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.05;
}

.table-core > p {
  max-width: 660px;
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.92rem;
  line-height: 1.35;
}

.effect-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 720px);
  max-height: 42%;
  gap: 0 18px;
  margin-top: 13px;
  overflow: auto;
  text-align: left;
  scrollbar-width: thin;
}

.effect-stack:has(.join-form) {
  min-height: 96px;
}

.effect-pill {
  min-width: 0;
  border-top: 1px solid var(--rule);
  padding: 8px 2px;
  color: var(--ink-soft);
  font-size: 0.72rem;
  line-height: 1.3;
}

.effect-pill strong {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 0.88rem;
}

.effect-pill.error {
  grid-column: 1 / -1;
  border: 1px solid var(--vermilion);
  color: var(--vermilion-dark);
  padding: 9px 11px;
}

.connection-pill[data-status="online"]::before,
.connection-pill[data-status="offline"]::before,
.connection-pill[data-status="connecting"]::before,
.connection-pill[data-status="authenticating"]::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--green);
  content: "";
}

.connection-pill[data-status="offline"]::before,
.connection-pill[data-status="connecting"]::before,
.connection-pill[data-status="authenticating"]::before {
  background: var(--brass);
}

.join-form {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
}

.join-form + .join-form {
  grid-template-columns: minmax(84px, 0.7fr) minmax(0, 1.2fr) auto;
  margin-top: 10px;
}

.lobby-actions {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.transfer-panel {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: minmax(150px, 0.7fr) minmax(0, 1.5fr);
  gap: 10px 14px;
  border-top: 1px solid var(--ink);
  padding-top: 10px;
}

.transfer-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.transfer-copy strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.transfer-copy span {
  color: var(--ink-soft);
  font-size: 0.68rem;
}

.transfer-form {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 78px auto;
  gap: 7px;
}

.quick-amounts {
  display: grid;
  grid-column: 2;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.quick-amounts button {
  min-height: 29px;
  padding: 0 7px;
  font-size: 0.65rem;
}

.seat-rail {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}

.seat-card {
  position: absolute;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  width: 172px;
  min-height: 62px;
  border: 1px solid var(--rule-strong);
  padding: 8px 9px;
  box-shadow: var(--shadow-paper);
  pointer-events: auto;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  clip-path: polygon(var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}

.seat-card::after {
  position: absolute;
  top: 0;
  right: 8px;
  width: 48px;
  height: 3px;
  background: transparent;
  content: "";
}

.seat-card.active {
  border-color: var(--vermilion);
  box-shadow: 0 0 0 2px rgba(155, 28, 28, 0.12), var(--shadow-lifted);
}

.seat-card.active::after {
  background: var(--vermilion);
}

.seat-card.regent .seat-token {
  border-color: var(--vermilion);
  color: var(--vermilion);
}

.seat-card.winner {
  border-color: var(--brass);
}

.seat-token {
  align-self: stretch;
  display: grid;
  min-height: 36px;
  place-items: center;
  border-right: 1px solid var(--rule);
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.67rem;
  font-variant-numeric: tabular-nums;
}

.seat-card > div:nth-child(2) {
  min-width: 0;
  padding-inline: 8px;
}

.seat-card strong {
  display: block;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-meta {
  overflow: hidden;
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 0.59rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.coin {
  position: relative;
  display: grid;
  min-width: 44px;
  justify-items: end;
  padding-left: 7px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.coin::before {
  position: absolute;
  top: 3px;
  left: -3px;
  width: 9px;
  height: 9px;
  border: 1px double #80621f;
  border-radius: 50%;
  background: var(--brass);
  content: "";
}

.coin span {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
}

.coin em {
  color: var(--ink-soft);
  font-size: 0.48rem;
  font-style: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.coin small {
  position: absolute;
  right: 0;
  bottom: -14px;
  color: var(--green);
  font-size: 0.64rem;
  font-weight: 800;
}

.seat-card.coin-loss .coin small {
  color: var(--vermilion);
}

.standing-place {
  color: var(--vermilion);
  font-size: 0.55rem;
}

.seat-rail[data-count="1"] .seat-card:nth-child(1) { top: 18px; left: 18px; }

.seat-rail[data-count="2"] .seat-card:nth-child(1) { top: 14px; left: 30%; transform: translateX(-50%); }
.seat-rail[data-count="2"] .seat-card:nth-child(2) { top: 14px; right: 30%; transform: translateX(50%); }

.seat-rail[data-count="3"] .seat-card:nth-child(1) { top: 14px; left: 50%; transform: translateX(-50%); }
.seat-rail[data-count="3"] .seat-card:nth-child(2) { top: 50%; left: 18px; transform: translateY(-50%); }
.seat-rail[data-count="3"] .seat-card:nth-child(3) { top: 50%; right: 18px; transform: translateY(-50%); }

.seat-rail[data-count="4"] .seat-card:nth-child(1) { top: 14px; left: 50%; transform: translateX(-50%); }
.seat-rail[data-count="4"] .seat-card:nth-child(2) { top: 50%; left: 18px; transform: translateY(-50%); }
.seat-rail[data-count="4"] .seat-card:nth-child(3) { top: 50%; right: 18px; transform: translateY(-50%); }
.seat-rail[data-count="4"] .seat-card:nth-child(4) { bottom: 14px; left: 50%; transform: translateX(-50%); }

.seat-rail[data-count="5"] .seat-card:nth-child(1),
.seat-rail[data-count="7"] .seat-card:nth-child(1) { top: 14px; left: 50%; transform: translateX(-50%); }
.seat-rail[data-count="5"] .seat-card:nth-child(2),
.seat-rail[data-count="7"] .seat-card:nth-child(2) { top: 16%; left: 18px; }
.seat-rail[data-count="5"] .seat-card:nth-child(3),
.seat-rail[data-count="7"] .seat-card:nth-child(3) { top: 16%; right: 18px; }
.seat-rail[data-count="5"] .seat-card:nth-child(4),
.seat-rail[data-count="7"] .seat-card:nth-child(4) { bottom: 16%; left: 18px; }
.seat-rail[data-count="5"] .seat-card:nth-child(5),
.seat-rail[data-count="7"] .seat-card:nth-child(5) { right: 18px; bottom: 16%; }
.seat-rail[data-count="7"] .seat-card:nth-child(6) { bottom: 14px; left: 39%; transform: translateX(-50%); }
.seat-rail[data-count="7"] .seat-card:nth-child(7) { right: 39%; bottom: 14px; transform: translateX(50%); }

.seat-rail[data-count="6"] .seat-card:nth-child(1),
.seat-rail[data-count="8"] .seat-card:nth-child(1) { top: 14px; left: 39%; transform: translateX(-50%); }
.seat-rail[data-count="6"] .seat-card:nth-child(2),
.seat-rail[data-count="8"] .seat-card:nth-child(2) { top: 14px; right: 39%; transform: translateX(50%); }
.seat-rail[data-count="6"] .seat-card:nth-child(3),
.seat-rail[data-count="8"] .seat-card:nth-child(3) { top: 50%; left: 18px; transform: translateY(-50%); }
.seat-rail[data-count="6"] .seat-card:nth-child(4),
.seat-rail[data-count="8"] .seat-card:nth-child(4) { top: 50%; right: 18px; transform: translateY(-50%); }
.seat-rail[data-count="6"] .seat-card:nth-child(5),
.seat-rail[data-count="8"] .seat-card:nth-child(5) { bottom: 14px; left: 39%; transform: translateX(-50%); }
.seat-rail[data-count="6"] .seat-card:nth-child(6),
.seat-rail[data-count="8"] .seat-card:nth-child(6) { right: 39%; bottom: 14px; transform: translateX(50%); }
.seat-rail[data-count="8"] .seat-card:nth-child(7) { bottom: 14px; left: 18px; }
.seat-rail[data-count="8"] .seat-card:nth-child(8) { right: 18px; bottom: 14px; }

.reaction-panel {
  position: absolute;
  z-index: 12;
  top: 50%;
  left: 50%;
  width: min(540px, calc(100% - 370px));
  border: 1px solid var(--vermilion);
  padding: 24px 26px;
  text-align: center;
  box-shadow: var(--shadow-lifted);
  transform: translate(-50%, -50%);
  clip-path: polygon(var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}

.reaction-heading {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 28px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 9px;
}

.reaction-heading h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 500;
}

.reaction-heading strong {
  color: var(--vermilion);
  font-family: var(--font-display);
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.reaction-progress {
  width: 100%;
  height: 3px;
  margin: 12px 0 18px;
  overflow: hidden;
  background: var(--rule);
}

.reaction-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--vermilion);
  transition: width 1s linear;
}

.reaction-panel > p {
  margin: 0 0 10px;
  font-family: var(--font-display);
  line-height: 1.45;
}

.reaction-status {
  color: var(--ink-soft);
  font-family: var(--font-ui) !important;
  font-size: 0.72rem;
}

.reaction-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 17px;
}

.reaction-actions button {
  min-height: 48px;
  background: var(--paper-strong);
  color: var(--ink);
}

.reaction-actions .support:not(:disabled) {
  border-color: var(--green);
  color: var(--green);
}

.reaction-actions .support:not(:disabled):hover {
  background: var(--green);
  color: var(--paper-strong);
}

.reaction-actions .oppose:not(:disabled) {
  border-color: var(--vermilion);
  color: var(--vermilion);
}

.reaction-actions .oppose:not(:disabled):hover {
  background: var(--vermilion);
  color: var(--paper-strong);
}

.reaction-actions .abstain:not(:disabled):hover {
  border-color: var(--ink);
}

.ledger-panel {
  display: grid;
  grid-template-rows: minmax(170px, 1fr) 225px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--rule-strong);
  clip-path: polygon(var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}

.panel-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  padding: 14px 16px;
}

.panel-section + .panel-section {
  border-top: 1px solid var(--rule-strong);
}

.panel-section h2 {
  margin: 0 0 9px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 7px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.log-list,
.chat-log {
  min-height: 0;
  margin: 0;
  overflow-y: auto;
  scrollbar-color: var(--rule-strong) transparent;
  scrollbar-width: thin;
}

.log-list {
  padding: 0;
  list-style: none;
}

.log-list li {
  border-bottom: 1px solid var(--rule);
  padding: 7px 0;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.72rem;
  line-height: 1.35;
}

.chat-box {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-line {
  border-bottom: 1px solid var(--rule);
  padding: 6px 0;
  font-size: 0.69rem;
  line-height: 1.35;
}

.chat-line strong {
  color: var(--vermilion-dark);
  font-family: var(--font-display);
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  margin-top: 8px;
}

.chat-form input {
  min-height: 35px;
}

.chat-form button {
  min-height: 35px;
  padding-inline: 10px;
}

.hand-drawer {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #111718;
  background: var(--blotter);
  color: var(--paper);
  padding: 11px 14px 13px;
}

.hand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 14px;
  border-bottom: 1px solid rgba(246, 243, 238, 0.24);
  padding-bottom: 9px;
}

.hand-header > div:first-child {
  display: grid;
  min-width: 0;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 2px 10px;
}

.hand-header span {
  color: #c8c8c0;
  font-size: 0.59rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.hand-header strong {
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hand-header small {
  grid-column: 1 / -1;
  overflow: hidden;
  color: #aeb2ad;
  font-size: 0.65rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hand-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hand-actions .ghost-button {
  border-color: rgba(246, 243, 238, 0.5);
  background: transparent;
  color: var(--paper);
}

.hand-toggle {
  display: none;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink);
  padding: 0;
}

.hand-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  transition: transform 180ms ease;
}

.hand-cards {
  display: grid;
  grid-auto-columns: minmax(205px, 1fr);
  grid-auto-flow: column;
  gap: 11px;
  min-width: 0;
  min-height: 0;
  padding: 10px 1px 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scrollbar-color: #6d7676 transparent;
  scrollbar-width: thin;
}

.game-card {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--rule-strong);
  border-top: 4px solid var(--blue);
  padding: 11px 12px 10px;
  color: var(--ink);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  scroll-snap-align: start;
  transition: transform 170ms ease, box-shadow 170ms ease, opacity 170ms ease;
  clip-path: polygon(var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}

.game-card.intrigue {
  border-top-color: var(--vermilion);
}

.game-card.reaction {
  border-top-color: var(--green);
}

.game-card.available:hover {
  z-index: 2;
  box-shadow: var(--shadow-lifted);
  transform: translateY(-6px);
}

.game-card.unavailable {
  filter: grayscale(0.35);
  opacity: 0.62;
}

.card-family {
  color: var(--ink-soft);
  font-size: 0.54rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.game-card h3 {
  margin: 4px 0 6px;
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 500;
  line-height: 1.05;
}

.card-text {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 0.75rem;
  line-height: 1.3;
}

.card-hint {
  margin: 6px 0;
  border-top: 1px solid var(--rule);
  padding-top: 5px;
  color: var(--ink-soft);
  font-size: 0.57rem;
  line-height: 1.22;
}

.target-select {
  width: 100%;
  min-height: 31px;
  margin-bottom: 6px;
  font-size: 0.68rem;
}

.target-warning {
  margin-bottom: 6px;
  color: var(--vermilion);
  font-size: 0.62rem;
  font-weight: 700;
}

.card-action {
  width: 100%;
  min-height: 34px;
  padding-inline: 8px;
  font-size: 0.68rem;
}

.hand-cards.final-state {
  grid-auto-columns: minmax(280px, 520px);
  justify-content: center;
}

.hand-cards:has(> .game-card:only-child) {
  grid-auto-columns: minmax(280px, 520px);
  justify-content: center;
}

.final-hand-summary {
  min-height: 150px;
}

.final-results {
  grid-column: 1 / -1;
  width: 100%;
  border: 1px solid var(--rule-strong);
  padding: 11px;
}

.winner-summary {
  display: grid;
  justify-items: center;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
  text-align: center;
}

.winner-summary span {
  color: var(--ink-soft);
  font-size: 0.55rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.winner-summary strong {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 500;
}

.winner-summary p {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 0.66rem;
}

.standings-list {
  margin: 7px 0 0;
  padding: 0;
  list-style: none;
}

.standing-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--rule);
  padding: 5px 3px;
}

.standing-row.winner {
  color: var(--vermilion-dark);
}

.standing-row.viewer {
  background: rgba(201, 164, 74, 0.13);
}

.standing-position,
.standing-coin {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
}

.standing-house strong {
  font-family: var(--font-display);
}

.standing-house small {
  display: block;
  color: var(--ink-soft);
  font-size: 0.54rem;
}

.tie-break-note {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 0.55rem;
  text-align: center;
}

.action-toast {
  position: fixed;
  z-index: 100;
  top: 16px;
  left: 50%;
  width: min(520px, calc(100% - 28px));
  border: 1px solid var(--green);
  padding: 12px 44px 12px 16px;
  box-shadow: var(--shadow-lifted);
  color: var(--green);
  font-size: 0.75rem;
  transform: translateX(-50%);
  clip-path: polygon(var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}

.action-toast[data-tone="error"] {
  border-color: var(--vermilion);
  color: var(--vermilion-dark);
}

.is-busy button:not(:disabled) {
  cursor: wait;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-rows: 64px minmax(0, 1fr) 258px;
  }

  .game-grid {
    grid-template-columns: minmax(0, 1fr) 270px;
  }

  .table-core {
    right: 152px;
    left: 152px;
    padding-inline: 17px;
  }

  .seat-card {
    width: 145px;
  }

  .reaction-panel {
    width: min(500px, calc(100% - 300px));
  }
}

@media (max-height: 760px) and (min-width: 641px) {
  .app-shell {
    grid-template-rows: 56px minmax(0, 1fr) 255px;
  }

  .topbar {
    padding-block: 5px;
  }

  .table-core {
    top: 66px;
    bottom: 56px;
    padding-block: 10px;
  }

  .seal {
    width: 50px;
    height: 50px;
    margin-bottom: 3px;
  }

  .turn-notice {
    min-height: 21px;
    margin-bottom: 4px;
  }

  .table-core h2 {
    font-size: clamp(1.45rem, 2.2vw, 2rem);
  }

  .table-core > p {
    margin-top: 4px;
    font-size: 0.8rem;
  }

  .effect-stack {
    margin-top: 8px;
  }

  .hand-drawer {
    padding-block: 8px 10px;
  }

  .hand-cards {
    padding-top: 8px;
  }

  .game-card {
    padding: 8px 10px 8px;
  }

  .game-card h3 {
    margin-block: 3px 4px;
    font-size: 1rem;
  }

  .card-text {
    font-size: 0.68rem;
    line-height: 1.18;
  }

  .card-hint {
    margin-block: 3px;
    padding-top: 3px;
    font-size: 0.52rem;
    line-height: 1.1;
  }

  .target-select,
  .card-action {
    min-height: 28px;
  }

  .target-select {
    margin-bottom: 4px;
  }
}

@media (max-width: 940px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-rows: auto auto auto;
  }

  .topbar {
    grid-template-columns: minmax(190px, 1fr) auto;
    row-gap: 8px;
  }

  .phase-strip {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .game-grid {
    grid-template-columns: 1fr;
  }

  .table-scene {
    min-height: 660px;
  }

  .ledger-panel {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 260px;
  }

  .panel-section + .panel-section {
    border-top: 0;
    border-left: 1px solid var(--rule-strong);
  }

  .hand-drawer {
    min-height: 265px;
  }
}

@media (max-width: 640px) {
  body {
    overflow-x: hidden;
    background-color: var(--paper);
    background-image: url("assets/visual/paper-texture.png");
    background-size: 560px 560px;
  }

  .app-shell {
    display: block;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 0;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    border-width: 0 0 1px;
    padding: 12px 14px 9px;
    clip-path: none;
  }

  .brand h1 {
    font-size: 1.18rem;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
  }

  .brand p {
    display: none;
  }

  .top-actions .primary-button,
  .top-actions .ghost-button {
    min-height: 32px;
    padding-inline: 9px;
    font-size: 0.61rem;
  }

  .top-actions {
    grid-column: 2;
    grid-row: 1;
  }

  .phase-strip {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    border-inline: 0;
    border-top: 1px solid var(--rule);
  }

  .phase-strip > div {
    padding: 7px 8px 0;
  }

  .phase-strip span {
    font-size: 0.5rem;
  }

  .phase-strip strong {
    font-size: 0.86rem;
  }

  .game-grid {
    display: block;
  }

  .table-scene {
    min-height: 550px;
    overflow: visible;
    border-width: 0 0 1px;
    background-color: var(--paper);
    background-image: url("assets/visual/paper-texture.png");
    background-size: 560px 560px;
  }

  .table-scene::after {
    display: none;
  }

  .seat-rail {
    position: relative;
    z-index: 4;
    inset: auto;
    display: flex;
    min-height: 77px;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 12px 6px;
    scroll-snap-type: x proximity;
  }

  .seat-card,
  .seat-rail[data-count] .seat-card:nth-child(n) {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    width: 158px;
    min-width: 158px;
    min-height: 59px;
    box-shadow: 0 3px 8px rgba(43, 43, 43, 0.12);
    scroll-snap-align: start;
    transform: none;
  }

  .table-core {
    position: relative;
    inset: auto;
    width: calc(100% - 24px);
    min-height: 435px;
    margin: 4px 12px 18px;
    justify-content: flex-start;
    padding: 20px 14px 24px;
    box-shadow: none;
  }

  .seal {
    width: 78px;
    height: 78px;
  }

  .table-core h2 {
    max-width: 100%;
    font-size: clamp(1.7rem, 8vw, 2.1rem);
    overflow-wrap: anywhere;
  }

  .table-core > p {
    max-width: 100%;
    font-size: 0.82rem;
    overflow-wrap: anywhere;
  }

  .effect-stack {
    grid-template-columns: 1fr;
    width: 100%;
    max-height: none;
    margin-top: 16px;
    overflow: visible;
  }

  .effect-pill {
    padding-block: 9px;
  }

  .join-form,
  .join-form + .join-form,
  .lobby-actions,
  .transfer-panel,
  .transfer-form {
    grid-template-columns: 1fr;
  }

  .join-form > *,
  .transfer-form > * {
    width: 100%;
    max-width: 100%;
  }

  .quick-amounts {
    grid-column: 1;
  }

  .reaction-panel {
    position: absolute;
    z-index: 15;
    top: 82px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: 455px;
    overflow-y: auto;
    padding: 18px 15px;
    transform: none;
  }

  .reaction-heading {
    display: grid;
    gap: 2px;
  }

  .reaction-heading h3 {
    font-size: 1.35rem;
  }

  .reaction-heading strong {
    font-size: 2.2rem;
  }

  .reaction-actions {
    grid-template-columns: 1fr;
  }

  .reaction-actions button {
    min-height: 44px;
  }

  .ledger-panel {
    display: block;
    border-width: 0 0 1px;
    clip-path: none;
  }

  .panel-section {
    min-height: 230px;
    max-height: 280px;
  }

  .panel-section + .panel-section {
    border-top: 1px solid var(--rule-strong);
    border-left: 0;
  }

  .hand-drawer {
    position: sticky;
    z-index: 60;
    bottom: 0;
    width: 100%;
    min-height: 0;
    max-height: 410px;
    border-width: 1px 0 0;
    background-color: var(--paper);
    background-image: url("assets/visual/paper-texture.png");
    background-size: 560px 560px;
    color: var(--ink);
    padding: 0;
    transition: max-height 180ms ease;
  }

  body:has(.table-scene[data-phase="idle"]) .hand-drawer,
  body:has(.table-scene[data-phase="lobby"]) .hand-drawer {
    position: relative;
  }

  .hand-header {
    min-height: 58px;
    border-bottom: 1px solid var(--rule);
    padding: 9px 12px;
  }

  .hand-header span {
    color: var(--ink-soft);
  }

  .hand-header strong {
    color: var(--ink);
  }

  .hand-header small {
    display: none;
  }

  .hand-actions .ghost-button {
    min-height: 36px;
    border-color: var(--rule-strong);
    background: var(--paper-strong);
    color: var(--ink);
    padding-inline: 9px;
    font-size: 0.61rem;
  }

  .hand-toggle {
    display: grid;
    flex: 0 0 auto;
  }

  .hand-cards {
    grid-auto-columns: minmax(270px, 86vw);
    max-height: 352px;
    gap: 10px;
    padding: 10px 12px 14px;
  }

  .game-card {
    min-height: 270px;
    padding: 15px;
  }

  .game-card h3 {
    font-size: 1.45rem;
  }

  .card-text {
    font-size: 0.88rem;
  }

  .card-hint {
    font-size: 0.68rem;
  }

  .hand-collapsed .hand-drawer {
    max-height: 58px;
  }

  .hand-collapsed .hand-cards,
  .hand-collapsed #passTurn {
    display: none;
  }

  .hand-collapsed .hand-toggle svg {
    transform: rotate(180deg);
  }

  .final-results {
    padding: 10px 6px;
  }

  .standing-row {
    grid-template-columns: 22px minmax(0, 1fr) auto;
  }

  .action-toast {
    top: 10px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .seat-card.turn-enter {
    animation: turnArrival 480ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .seat-card.coin-gain {
    animation: coinGain 660ms ease-out;
  }

  .seat-card.coin-loss {
    animation: coinLoss 660ms ease-out;
  }

  .turn-notice.phase-enter {
    animation: phaseReveal 420ms ease-out;
  }

  .game-card.is-playing {
    animation: cardCommit 260ms ease-in forwards;
  }

  .reaction-panel:not(.hidden) {
    animation: reactionRise 300ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .reaction-heading strong.urgent {
    animation: urgentBeat 850ms ease-in-out infinite;
  }

  .log-enter {
    animation: logReveal 380ms ease-out;
  }

  .action-toast.show {
    animation: toastDrop 300ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .table-scene.finished .winner-summary {
    animation: victoryReveal 620ms cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  .table-scene.finished .standing-row {
    animation: standingReveal 420ms ease-out both;
  }

  .table-scene.finished .standing-row:nth-child(2) { animation-delay: 80ms; }
  .table-scene.finished .standing-row:nth-child(3) { animation-delay: 140ms; }
  .table-scene.finished .standing-row:nth-child(4) { animation-delay: 200ms; }
  .table-scene.finished .standing-row:nth-child(n + 5) { animation-delay: 260ms; }

  @keyframes turnArrival {
    from { opacity: 0.45; transform: translateY(-8px) scale(0.97); }
    to { opacity: 1; }
  }

  @keyframes coinGain {
    50% { border-color: var(--green); background-color: var(--green-soft); }
  }

  @keyframes coinLoss {
    50% { border-color: var(--vermilion); background-color: #f1dcdc; }
  }

  @keyframes phaseReveal {
    from { opacity: 0; transform: translateY(-7px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes cardCommit {
    from { opacity: 1; transform: translateY(0) rotate(0); }
    to { opacity: 0; transform: translateY(-34px) rotate(-1deg) scale(0.97); }
  }

  @keyframes reactionRise {
    from { opacity: 0; transform: translate(-50%, calc(-50% + 14px)) scale(0.98); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  }

  @keyframes urgentBeat {
    50% { opacity: 0.58; transform: scale(1.04); }
  }

  @keyframes logReveal {
    from { opacity: 0; transform: translateX(8px); }
    to { opacity: 1; transform: translateX(0); }
  }

  @keyframes toastDrop {
    from { opacity: 0; transform: translate(-50%, -12px); }
    to { opacity: 1; transform: translate(-50%, 0); }
  }

  @keyframes victoryReveal {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }

  @keyframes standingReveal {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
  }
}

@media (max-width: 640px) and (prefers-reduced-motion: no-preference) {
  .reaction-panel:not(.hidden) {
    animation: mobileReactionRise 300ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes mobileReactionRise {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
