:root {
  color-scheme: dark;
  --bg: #101a16;
  --panel: #182620;
  --panel-raised: #1e2f27;
  --line: #35473c;
  --text: #f6f1e5;
  --muted: #b6c4b7;
  --gold: #e7c782;
  --gold-bright: #f4d99d;
  --ink: #231d12;
  --radius: 14px;
  font: 16px/1.55 "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Meiryo", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100dvh; background: radial-gradient(ellipse at 49% 0, #233429 0, var(--bg) 59%); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 3px; }
h1, h2, h3, p, dl, figure { margin: 0; }
h1 { font: 700 clamp(2rem, 4.1vw, 3.2rem)/1.15 "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", Georgia, serif; overflow-wrap: anywhere; }
h2 { font-size: 1.13rem; font-weight: 700; }
h3 { font-size: 1rem; }
strong { overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: .9rem; }
.full { width: 100%; }
.mobile-only, .short-deputy-label { display: none; }
.sr-only { border: 0; clip-path: inset(50%); height: 1px; overflow: hidden; padding: 0; position: absolute; white-space: nowrap; width: 1px; }

.topbar { border-bottom: 1px solid #3a483b; background: #111d17; }
.topbar.has-game-tools { position: sticky; top: 0; z-index: 6; }
html:has(.topbar.has-game-tools) { scroll-padding-top: 80px; }
.topbar-inner { max-width: 1440px; min-height: 70px; padding: 0 clamp(16px, 3.8vw, 52px); margin: auto; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.wordmark { display: flex; align-items: center; gap: 10px; color: var(--gold-bright); font: 700 .99rem Georgia, serif; letter-spacing: .21em; }
.wordmark span { width: 31px; height: 31px; display: grid; place-items: center; font-size: 1.3rem; letter-spacing: 0; border: 1px solid #958156; border-radius: 8px; }
nav, .actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
nav { justify-content: flex-end; }
.topbar.has-game-tools nav { margin-left: auto; }
.game-tools { display: flex; flex: 0 0 auto; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 8px; }
#account-toggle { max-width: min(23vw, 210px); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wrap { max-width: 1440px; margin: 0 auto; padding: 36px clamp(16px, 3.8vw, 52px) 42px; }
.surface { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.button { border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; min-height: 42px; color: var(--text); background: transparent; font-weight: 650; line-height: 1.35; }
.compact { min-height: 36px; padding: 7px 11px; font-size: .87rem; }
.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.primary:hover:not(:disabled) { background: var(--gold-bright); border-color: var(--gold-bright); }
.secondary { background: #21332a; border-color: #516458; }
.secondary:hover:not(:disabled), .quiet:hover:not(:disabled) { background: #344b3e; border-color: #66796a; }
.quiet { color: #d9dfd5; border-color: transparent; }
.button[aria-pressed="true"] { border-color: #a18b54; color: var(--gold-bright); }
.button:disabled { opacity: .47; }
form { display: grid; gap: 8px; }
label { font-size: .9rem; font-weight: 650; }
input:not([type="range"]), select {
  width: 100%; min-height: 43px; padding: 8px 12px; border: 1px solid #53675a; border-radius: 8px;
  background: #101d17; color: var(--text); min-width: 0;
}
select { appearance: none; padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: right 16px center, right 11px center; background-size: 5px 5px; background-repeat: no-repeat; }
input::placeholder { color: #91a296; }
input[type="range"] { accent-color: var(--gold); }
form > .primary { margin-top: 8px; }

.entrance { min-height: min(710px, calc(100dvh - 160px)); display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(290px, .85fr); align-items: center; gap: clamp(32px, 9vw, 110px); max-width: 1065px; margin: auto; padding: 42px 8px; }
.intro h1 { color: var(--gold-bright); font-size: clamp(3rem, 7.3vw, 6.5rem); letter-spacing: -.04em; }
.intro p { margin-top: 20px; color: var(--muted); }
.card-spread { height: clamp(168px, 26vw, 258px); position: relative; margin: 0 0 35px; isolation: isolate; min-width: 260px; }
.hero-card { position: absolute; bottom: 8%; width: clamp(110px, 17vw, 172px); border-radius: 8px; box-shadow: 4px 18px 30px #050b08b5; }
.hero-card img { display: block; }
.hero-back { left: 9%; transform: rotate(-23deg); }
.hero-red { left: 47%; transform: rotate(17deg); }
.hero-ace { left: 27%; transform: translateY(-7%) rotate(-4deg); }
.login-panel { padding: clamp(22px, 4vw, 38px); background: #1a2a22; box-shadow: 0 15px 50px #08110d78; }
.login-panel h2 { font-size: 1.4rem; margin-bottom: 22px; }
.login-panel > button { margin-top: 12px; }

.page-heading { margin-bottom: 24px; }
.page-heading p { color: var(--muted); margin-top: 7px; }
.room-heading { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 16px; }
.lobby-layout, .game-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(245px, 315px); align-items: start; gap: 20px; }
.lobby-rooms, .create-room, .waiting-panel, .result-panel { padding: clamp(16px, 2vw, 25px); }
.create-room h2 { margin-bottom: 17px; }
.create-room label:not(:first-child) { margin-top: 7px; }
.section-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 9px; }
.lobby-rooms .section-head { margin-bottom: 11px; }
.room-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 13px; padding: 15px 0; border-top: 1px solid #3b5144; }
.row-meta { margin-top: 3px; overflow-wrap: anywhere; }
.chip { display: inline-block; border: 1px solid #64745d; border-radius: 30px; color: #dbebce; padding: 3px 9px; font-size: .84rem; white-space: nowrap; }
.status-playing { border-color: #947b46; color: #f0d69d; }
.status-finished { color: var(--muted); }
.empty-state { padding: 25px 15px; text-align: center; border: 1px dashed #456051; border-radius: 8px; color: var(--muted); }
.waiting-seats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin: 20px 0; }
.waiting-seat { min-height: 148px; display: grid; align-content: start; justify-items: start; gap: 7px; padding: 14px; border: 1px solid #455b4c; background: #1d2f25; border-radius: 9px; }
.waiting-seat.self { border-color: #9f8a54; }
.waiting-seat .button { margin-top: 6px; }
.cpu-level { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; font-size: .85rem; }
.cpu-level select { width: auto; min-height: 2rem; }
.seat-index { color: var(--gold); font-size: .83rem; }
.waiting-controls { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px; border-top: 1px solid var(--line); padding-top: 16px; }
.waiting-hint { margin-top: 12px; }
.inline-form { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.inline-form > .primary { margin-top: 0; }
.inline-form input, .inline-form select { width: auto; min-height: 37px; }
.inline-form input { width: 82px; }
.bid-field, .bid-actions { display: contents; }

.game-main, .table-sidebar { display: grid; gap: 14px; min-width: 0; }
.table {
  --played-card-width: clamp(45px, 7vw, 61px);
  --played-card-height: calc(var(--played-card-width) * 1.4);
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--played-card-width) minmax(0, 1.2fr) var(--played-card-width) minmax(0, 1fr);
  grid-template-rows: auto var(--played-card-height) minmax(var(--played-card-height), auto) var(--played-card-height) auto;
  grid-template-areas:
    ". north north north contract"
    ". . north-card . ."
    "west west-card core east-card east"
    ". . south-card . ."
    ". south south south .";
  align-items: center; gap: 10px; padding: 23px 20px;
  border: 1px solid #a68a52; border-radius: clamp(30px, 7vw, 78px);
  background: radial-gradient(ellipse, #255b44 0, #194b36 68%, #133b2b 100%);
  box-shadow: inset 0 0 0 6px #172b20, inset 0 0 0 7px #7e744a, 0 10px 28px #090f0c64;
}
.table.preparation {
  min-height: 340px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: auto minmax(110px, 1fr) auto;
  grid-template-areas: ". north contract" "west core east" ". south .";
}
.table-trump-mark {
  position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%);
  width: clamp(78px, 22%, 146px); aspect-ratio: 1; object-fit: contain;
  filter: brightness(0) invert(.94) sepia(.35); opacity: .23; pointer-events: none;
}
.table-contract {
  grid-area: contract; justify-self: end; align-self: start;
  margin-block-start: 11px; margin-inline-end: 11px;
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 6px;
  border: 1px solid #a68a52; border-radius: 7px; background: #f4e5be; color: var(--ink);
  line-height: 1.15; font-variant-numeric: tabular-nums;
}
.table-contract-icon { display: grid; place-items: center; width: 1.1em; height: 1.1em; }
.table-contract-icon img { width: 100%; height: 100%; object-fit: contain; }
.table-contract-icon.no-trump::before {
  content: ""; width: .55em; height: .55em; border: 1.5px solid currentColor; transform: rotate(45deg);
}
.table-seat { position: relative; width: max-content; min-width: min(100%, 129px); max-width: 100%; padding: 7px 10px; text-align: center; border: 1px solid #58836b; border-radius: 8px; background: #17392c; }
.table-seat.current { border-color: var(--gold); background: #253d2a; box-shadow: 0 0 0 2px #d8bd7640; }
.table-seat.trick-winner { border-color: var(--gold-bright); background: #3b3925; box-shadow: 0 0 0 2px #dec28163; }
.table-seat.north { grid-area: north; justify-self: center; }
.table-seat.south { grid-area: south; justify-self: center; }
.table-seat.west { grid-area: west; justify-self: end; }
.table-seat.east { grid-area: east; justify-self: start; }
.seat-meta { color: #d3ddcd; font-size: .82rem; }
.table-core { position: relative; grid-area: core; display: grid; justify-items: center; align-content: center; min-width: 0; text-align: center; overflow-wrap: anywhere; }
.table-caption, .table-trick-title { color: #f1deab; font-size: .9rem; }
.table-caption { margin-top: 7px; }
.table-trick-title { font-weight: 700; }
.table-decision-label { margin-top: 5px; color: var(--gold-bright); font-size: .82rem; font-weight: 700; }
.table.table-decided { border-color: var(--gold-bright); }
.table-bid {
  position: relative; width: fit-content; max-width: 100%; margin: 7px auto 5px; padding: 4px 7px;
  border-radius: 7px; background: var(--gold-bright); color: var(--ink); font-size: .87rem; line-height: 1.35;
}
.table-bid.pass { background: #dce7d6; color: #17392c; }
.table-bid::before {
  position: absolute; top: -3px; left: calc(50% - 4px); width: 8px; height: 8px;
  background: inherit; transform: rotate(45deg); content: "";
}
.table-bid strong, .table-bid small { position: relative; display: block; }
.table-bid small { font-size: .75rem; overflow-wrap: anywhere; }
.deputy-call {
  position: relative; display: grid; justify-items: center; gap: 3px; min-width: 0; max-width: 100%;
  padding: 7px 12px; border-radius: 9px; background: #f4e5be; color: var(--ink);
  box-shadow: 0 4px 13px #10241777; line-height: 1.3;
}
.deputy-call::before {
  position: absolute; width: 12px; height: 12px; content: ""; background: inherit; transform: rotate(45deg);
}
.deputy-call.north::before { top: -5px; left: calc(50% - 6px); }
.deputy-call.south::before { bottom: -5px; left: calc(50% - 6px); }
.deputy-call.west::before { left: -5px; top: calc(50% - 6px); }
.deputy-call.east::before { right: -5px; top: calc(50% - 6px); }
.deputy-call > * { position: relative; }
.deputy-call span { font-size: .78rem; }
.deputy-call .card-img { width: min(100%, 49px); box-shadow: 0 1px 3px #46341659; }
.table:not(.preparation) .deputy-call { margin-top: 5px; padding: 4px; font-size: .83rem; }
.table:not(.preparation) .deputy-call .card-img { width: min(100%, 32px); }
.deal-stack {
  position: absolute; z-index: 4; width: clamp(30px, 7vw, 46px); aspect-ratio: 5 / 7;
  border-radius: 5%; background: url("/static/card-back.png") center / cover;
  box-shadow: 2px 2px 0 #e0d1a7, 4px 4px 0 #285d49, 5px 6px 0 #d1be90, 7px 10px 10px #11261d9c;
  pointer-events: none;
}
.table-card { position: relative; width: var(--played-card-width); justify-self: center; }
.table-card.north { grid-area: north-card; }
.table-card.west { grid-area: west-card; }
.table-card.east { grid-area: east-card; }
.table-card.south { grid-area: south-card; }
.table-card figcaption { position: absolute; inset: auto 0 0; padding: 1px 2px; background: #16372e; color: #f6e8c4; font-size: .72rem; text-align: center; line-height: 1.3; }
.card-img { width: 100%; aspect-ratio: 5 / 7; display: block; object-fit: fill; border-radius: 5%; user-select: none; }
.winner-card img { outline: 2px solid var(--gold-bright); outline-offset: 1px; }
.play-controls { padding: 16px; min-width: 0; }
.turn-message { margin-bottom: 9px; }
.turn-message p { margin-top: 4px; }
.turn-buttons:empty { display: none; }
.trick-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0 12px; }
.trick-controls .turn-message { min-width: 0; margin-bottom: 0; }
.trick-controls .turn-message h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trick-controls .turn-buttons .button { white-space: nowrap; }
.trick-controls .hand { grid-column: 1 / -1; }
.deputy-controls { display: grid; gap: 8px; }
.hand { display: flex; gap: 5px; min-width: 0; padding: 8px 3px; margin-top: 10px; flex-wrap: wrap; }
.hand-card, .hand .card-button { width: min(calc((100% - 60px) / 13), 65px); min-width: 40px; }
.card-button { padding: 0; border: 0; border-radius: 6%; background: transparent; display: block; }
.card-button:hover:not(:disabled), .card-button.chosen { outline: 2px solid var(--gold-bright); outline-offset: 2px; transform: translateY(-3px); }
.card-button:disabled { filter: brightness(.55); }
.card-button:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 3px; }
.hand :is(.hand-card, .card-button) { position: relative; }
.hand-role-mark {
  position: absolute; inset: auto auto 2px 50%; transform: translateX(-50%);
  padding: 1px 3px; border: 1px solid #8ec1d5; border-radius: 4px;
  background: #193a4d; color: #ecf9ff; font-size: clamp(.59rem, 1.35vw, .76rem);
  font-weight: 750; line-height: 1.05; white-space: nowrap; pointer-events: none;
}
.hand .card-button:disabled { filter: none; }
.hand .card-button:disabled .card-img { filter: brightness(.55); }
.exchange-row { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.exchange-row .card-button { width: 57px; margin-top: 4px; }
.exchange-buttons { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sidebar-section { padding: 14px 16px; min-width: 0; }
.sidebar-section h2 { margin-bottom: 8px; }
.game-facts { display: grid; gap: 7px; }
.game-facts > div { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 8px; font-size: .9rem; }
.game-facts dt { color: var(--muted); }
.game-facts dd { margin: 0; text-align: right; color: var(--gold-bright); overflow-wrap: anywhere; }
.fact-bidder { display: block; color: var(--muted); font-size: .82rem; }
.capture-row { border-top: 1px solid #3f5547; margin-top: 7px; padding-top: 7px; }
.capture-row summary { cursor: pointer; font-size: .88rem; overflow-wrap: anywhere; }
.capture-row summary strong { float: right; color: var(--gold-bright); }
.capture-row p, .small-cards { margin-top: 7px; }
.small-cards { display: flex; flex-wrap: wrap; gap: 4px; }
.small-cards img { width: 33px; }
.vote-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; border-top: 1px solid #5c5948; margin-top: 9px; padding-top: 9px; font-size: .86rem; }
.vote-row small { display: block; color: var(--gold); }
.vote-row button { flex: 0 0 auto; }
.totals { list-style: none; padding: 0; margin: 0; }
.totals li { display: flex; align-items: baseline; justify-content: space-between; gap: 7px; font-size: .89rem; padding: 4px 0; }
.totals li span { min-width: 0; overflow-wrap: anywhere; }
.totals li strong { color: var(--gold-bright); white-space: nowrap; }
.result-panel p { margin-top: 8px; }
.result-buried, .result-buried dd { display: flex; align-items: center; gap: 9px; }
.result-buried { margin: 9px 0 0; }
.result-buried dd { margin: 0; font-weight: 700; }
.result-buried .card-img { width: 32px; }
.decision-panel { padding: 15px 20px; border-color: #ab8d50; background: #293627; }
.decision-panel h2 { color: var(--gold-bright); }
.decision-panel p { margin-top: 5px; }
@media (prefers-reduced-motion: no-preference) {
  .decision-panel { animation: decision-enter .28s ease-out both; }
}
@keyframes decision-enter {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}
.score-overflow { overflow-x: auto; }
.scores { border-collapse: collapse; width: 100%; margin-top: 13px; text-align: left; font-size: .9rem; }
.scores th, .scores td { padding: 7px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.scores thead { color: var(--muted); }
.scores tbody strong { color: var(--gold-bright); }
.result-actions { margin-top: 15px; }

dialog { width: min(540px, calc(100% - 24px)); max-height: 90dvh; padding: 0; border: 1px solid #667b6b; border-radius: var(--radius); background: var(--panel); color: var(--text); box-shadow: 0 24px 70px #040a07bf; }
dialog.wide { width: min(880px, calc(100% - 24px)); }
dialog::backdrop { background: #070d0ac2; }
.modal-top { position: sticky; top: 0; z-index: 1; padding: 14px 17px; display: flex; justify-content: space-between; align-items: center; gap: 12px; background: #1d3026; border-bottom: 1px solid var(--line); }
#modal-content { padding: 17px; }
#modal-content p + p { margin-top: 6px; }
.help { display: grid; gap: 16px; }
.help-intro { padding: 12px; background: #20342a; border: 1px solid var(--line); border-radius: 8px; }
.help section { display: grid; gap: 8px; min-width: 0; }
.help section + section { padding-top: 14px; border-top: 1px solid var(--line); }
.help h3 { color: var(--gold-bright); font-size: 1.05rem; }
.help :is(ul, ol) { margin: 0; padding-inline-start: 1.35em; }
.help li + li { margin-top: 5px; }
.help details { padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; }
.help summary { cursor: pointer; font-weight: 650; }
.help details[open] summary, .help details p { margin-bottom: 6px; }
.help-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: .9rem; }
.help-table caption { margin-bottom: 3px; text-align: left; font-weight: 650; }
.help-table :is(th, td) { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.help-table thead { background: #20342a; }
#identity { display: flex; gap: 8px; margin-top: 15px; }
.account-logout { margin-top: 15px; }
.notice { position: fixed; bottom: 16px; right: 16px; z-index: 5; max-width: min(430px, calc(100vw - 32px)); color: #fff2cb; background: #322d20; border: 1px solid #a48755; border-radius: 10px; padding: 12px 17px; box-shadow: 0 10px 24px #030703a9; }
.modal-notice { margin: 12px 17px 0; padding: 8px 12px; background: #322d20; color: #fff2cb; border: 1px solid #a48755; border-radius: 7px; }
.history-list, .deputy-groups { display: grid; gap: 13px; }
.history-item { border: 1px solid var(--line); border-radius: 9px; padding: 12px; }
.history-item p { margin-top: 7px; overflow-wrap: anywhere; }
.history-game { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.public-call { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.public-call img { width: 32px; }
.public-tricks { display: grid; gap: 10px; }
.public-trick { border: 1px solid var(--line); border-radius: 9px; padding: 11px; }
.public-plays { list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin: 9px 0 0; padding: 0; }
.public-play { display: grid; grid-template-columns: 33px minmax(0, 1fr); gap: 7px; align-items: center; padding: 7px; background: #20342a; border-radius: 7px; }
.public-play .muted { font-size: .82rem; overflow-wrap: anywhere; }
.public-card-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin-bottom: 6px; }
.public-card-summary strong { color: var(--gold-bright); }
.public-card-grid { width: 100%; table-layout: fixed; border-spacing: clamp(2px, .65vw, 6px); }
.public-card-grid th, .public-card-grid td { padding: 0; }
.public-card-grid thead { color: var(--muted); font-size: clamp(.66rem, 1.35vw, .88rem); }
.public-card-grid tbody th { color: var(--muted); font-size: clamp(.9rem, 2.2vw, 1.25rem); }
.public-card-suit { width: clamp(12px, 3.5vw, 27px); }
.public-card-grid .unplayed-card .card-img { filter: grayscale(1) brightness(.55); }
.major-cards summary { cursor: pointer; font-size: 1.13rem; font-weight: 700; }
.major-cards .public-card-grid { margin-top: 8px; border-spacing: 3px; }
.major-cards .public-card-suit { width: 18px; }
.major-cards .public-card-grid tbody th { font-size: 1rem; }
.picker-cards { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.picker-cards .card-button { width: 42px; }
.replay-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.replay-toolbar select { width: auto; }
.replay-toolbar input { flex: 1 1 130px; min-width: 0; }
.replay-event { background: #24392d; border: 1px solid #496653; padding: 10px; border-radius: 7px; margin: 12px 0; overflow-wrap: anywhere; }
.replay-board {
  --replay-card-width: clamp(37px, 12vw, 54px);
  display: grid; grid-template-columns: max-content max-content minmax(0, 1fr);
  align-items: center; gap: 10px clamp(12px, 3vw, 28px); margin: 12px 0;
}
.replay-trick {
  display: grid; grid-template-columns: repeat(3, var(--replay-card-width));
  grid-template-areas: "west north east" "west south east";
  align-items: center; gap: 4px clamp(6px, 1.8vw, 15px); padding: 8px clamp(8px, 2vw, 18px);
  background: #194b36; border: 1px solid #7e744a; border-radius: 18px;
}
.replay-spot.north { grid-area: north; }
.replay-spot.west { grid-area: west; }
.replay-spot.east { grid-area: east; }
.replay-spot.south { grid-area: south; }
.replay-spot figcaption { margin-top: 2px; font-size: .75rem; text-align: center; line-height: 1.3; }
.replay-empty-card { aspect-ratio: 5 / 7; border: 1px dashed #a4bcab; border-radius: 5%; background: #132e25; }
.replay-kitty { display: grid; justify-items: center; gap: 3px; border-inline-start: 1px solid var(--line); padding-inline-start: clamp(10px, 2vw, 20px); }
.replay-kitty .card-img { width: var(--replay-card-width); }
.replay-board .game-facts { justify-self: end; min-width: min(100%, 160px); }
.replay-hands { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.replay-hands section { padding: 10px; min-width: 0; border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; }
.game-info { display: grid; gap: 12px; }

@media (max-width: 980px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) minmax(215px, 255px); gap: 13px; }
  .table { padding: 16px; }
}

@media (max-width: 760px) {
  .entrance { grid-template-columns: minmax(0, 1fr); gap: 24px; padding: 4px 0 20px; }
  .intro { text-align: center; }
  .card-spread { margin: 0 auto 21px; max-width: 340px; }
  .intro h1 { font-size: clamp(3rem, 11vw, 5rem); }
  .intro p { margin-top: 12px; }
  .lobby-layout, .game-layout { grid-template-columns: minmax(0, 1fr); }
  .table-sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .waiting-seats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 800px) {
  html:has(.topbar.has-game-tools) { scroll-padding-top: 100px; }
  .topbar.has-game-tools .topbar-inner { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 7px; padding-block: 6px; }
  .game-tools { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .public-plays { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .replay-board { grid-template-columns: max-content minmax(0, 1fr); }
  .replay-kitty { justify-self: start; }
  .replay-board .game-facts { grid-column: 1 / -1; justify-self: stretch; }
}

@media (max-width: 460px) {
  .wrap { padding-top: 23px; }
  .topbar-inner { padding: 8px 12px; min-height: 57px; gap: 6px; }
  .wordmark { font-size: .83rem; letter-spacing: .1em; gap: 5px; }
  .wordmark span { height: 24px; width: 24px; }
  nav { gap: 3px; }
  nav .compact { padding: 6px 5px; font-size: .78rem; }
  .game-tools { gap: 4px; }
  .game-tools .compact { padding-inline: 6px; font-size: .78rem; }
  .room-row { gap: 6px; grid-template-columns: minmax(0, 1fr) auto; }
  .room-row .chip { grid-row: 2; justify-self: start; }
  .room-row .button { grid-column: 2; grid-row: 1 / span 2; }
  .table { --played-card-width: 43px; gap: 6px 4px; padding: 13px 11px; }
  .table.preparation { min-height: 290px; }
  .table-seat { padding: 5px 3px; font-size: .83rem; }
  .seat-meta { font-size: .72rem; }
  .table-sidebar, .replay-hands { grid-template-columns: minmax(0, 1fr); }
  .play-controls { padding: 12px; }
  .hand-card, .hand .card-button { min-width: 36px; }
}

@media (max-width: 760px) and (orientation: portrait),
       (max-width: 1050px) and (max-height: 540px) and (orientation: landscape) {
  body {
    --phone-left: max(10px, env(safe-area-inset-left, 0px));
    --phone-right: max(10px, env(safe-area-inset-right, 0px));
    --phone-bottom: max(8px, env(safe-area-inset-bottom, 0px));
    min-width: 0;
    -webkit-text-size-adjust: 100%;
  }
  .topbar { padding-top: env(safe-area-inset-top, 0px); }
  .topbar-inner, .wrap { padding-inline: var(--phone-left) var(--phone-right); }
  .wrap { padding-top: 14px; padding-bottom: max(18px, var(--phone-bottom)); }
  .topbar-inner { min-height: 50px; gap: 6px; }
  .page-heading { margin-bottom: 14px; }
  .page-heading h1 { font-size: clamp(1.55rem, 6vw, 2.25rem); }
  .page-heading p { margin-top: 4px; }
  .button { touch-action: manipulation; }
  .compact { min-height: 40px; padding-block: 5px; }
  input:not([type="range"]), select { font-size: 1rem; min-height: 44px; }
  .lobby-rooms, .create-room, .waiting-panel, .result-panel, .login-panel { padding: 12px; }
  .lobby-layout, .game-layout { gap: 10px; }
  .lobby-shortcuts { display: flex; justify-content: flex-start; margin-bottom: 10px; }
  .lobby-rooms, .create-room { scroll-margin-top: 12px; }
  .room-row { gap: 6px; }
  .waiting-seats { gap: 7px; margin: 12px 0; }
  .waiting-seat { min-width: 0; min-height: 0; padding: 8px; gap: 4px; }
  .waiting-seat .button { margin-top: 3px; padding-inline: 7px; }
  .waiting-controls { gap: 8px; padding-top: 12px; }
  .entrance { gap: 14px; padding: 0; min-height: 0; }
  .intro h1 { font-size: clamp(2.15rem, 9vw, 3.5rem); }
  .intro p { margin-top: 7px; font-size: .9rem; }
  .card-spread { min-width: 0; height: clamp(86px, 23vw, 145px); margin-bottom: 12px; }
  .hero-card { width: clamp(63px, 17vw, 106px); }
  .login-panel h2 { margin-bottom: 10px; }

  dialog, dialog.wide {
    width: calc(100% - var(--phone-left) - var(--phone-right));
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top, 0px)) - var(--phone-bottom));
    inset-inline: var(--phone-left) var(--phone-right);
  }
  dialog { max-width: 540px; }
  dialog.wide { max-width: 880px; }
  .modal-top, #modal-content { padding: 8px 10px; }
  .modal-top h2 { overflow-wrap: anywhere; }
  .modal-top .button { flex-shrink: 0; }
  .replay-toolbar { gap: 5px; }
  .replay-toolbar input { min-height: 27px; }
  .history-game > div { min-width: 0; }
  .game-info .table-sidebar { gap: 7px; }

  .wrap:has(.result-game-layout) > .room-heading { align-items: center; gap: 6px; margin-bottom: 9px; }
  .wrap:has(.result-game-layout) > .room-heading h1 { font-size: 1rem; }
  .wrap:has(.result-game-layout) > .room-heading p { margin-top: 2px; font-size: .78rem; }
  .wrap:has(.result-game-layout) > .room-heading [data-ui="history"],
  .result-game-layout > .table-sidebar, .result-game-layout .table.preparation,
  .result-panel :is(.desktop-result, .score-overflow) { display: none; }
  .result-game-layout { grid-template-columns: minmax(0, 1fr); }
  .result-game-layout .game-main { gap: 10px; }
  .result-heading { display: grid; gap: 3px; }
  .result-heading h2 { color: var(--muted); font-size: .88rem; }
  .result-outcome { display: grid; gap: 2px; }
  .result-outcome strong { color: var(--gold-bright); font-size: clamp(1.45rem, 6vw, 2rem); line-height: 1.25; }
  .result-outcome span { color: var(--muted); font-size: .85rem; }
  .result-game-summary {
    display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 8px;
    margin-top: 9px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #1e3127;
  }
  .result-game-summary dt { color: var(--muted); font-size: .74rem; }
  .result-game-summary dd { margin: 2px 0 0; overflow-wrap: anywhere; font-size: .95rem; font-weight: 700; }
  .result-game-summary dd span { display: inline-block; }
  .result-panel .result-reason { font-size: .8rem; line-height: 1.45; }
  .result-panel .result-actions { margin: 10px 0; gap: 6px; }
  .result-actions .button { flex: 1 1 0; min-height: 44px; padding-inline: 6px; font-size: .88rem; }
  .result-score-list { display: grid; gap: 6px; list-style: none; margin: 0; padding: 0; }
  .result-score-card { min-width: 0; padding: 8px 9px; border: 1px solid #455e50; border-radius: 9px; background: #1d3026; }
  .result-score-card.self { border-color: #a58b52; background: #2a3427; }
  .result-player { display: flex; align-items: flex-start; justify-content: space-between; gap: 7px; }
  .result-player h3 { font-size: 1rem; line-height: 1.25; overflow-wrap: anywhere; }
  .result-player-meta { margin-top: 2px; color: var(--muted); font-size: .74rem; }
  .result-place {
    flex-shrink: 0; padding: 2px 6px; border: 1px solid #687864; border-radius: 6px;
    color: var(--gold-bright); font-size: .88rem; font-weight: 750; white-space: nowrap;
  }
  .result-score-values {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px;
    margin-top: 5px; padding-top: 4px; border-top: 1px solid #4a5e50;
  }
  .result-score-values dt { color: var(--muted); font-size: .73rem; }
  .result-score-values dd { margin: 0; font-size: 1.05rem; font-weight: 750; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
  .result-score-values dd span { margin-inline-start: 2px; color: var(--muted); font-size: .72rem; font-weight: 500; }

  body:has(.live-game-layout) {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
  }
  body:has(.live-game-layout) .topbar { position: relative; }
  body:has(:is(.live-game-layout, .result-game-layout)) .topbar.has-game-tools .topbar-inner { display: block; min-height: 0; padding-block: 3px; }
  body:has(:is(.live-game-layout, .result-game-layout)) :is(.wordmark, #account-nav, .desktop-tool-label) { display: none; }
  body:has(:is(.live-game-layout, .result-game-layout)) .game-tools { display: flex; flex-wrap: nowrap; justify-content: flex-start; gap: 4px; }
  body:has(:is(.live-game-layout, .result-game-layout)) .game-tools .mobile-only { display: inline; }
  body:has(:is(.live-game-layout, .result-game-layout)) .game-tools .button { padding-inline: 7px; white-space: nowrap; font-size: .78rem; }
  .table-contract { gap: 3px; padding: 3px 4px; border-radius: 5px; font-size: .85rem; }
  .wrap:has(.live-game-layout) { width: 100%; min-height: 0; overflow: auto; padding-top: 5px; padding-bottom: var(--phone-bottom); }
  .wrap:has(.live-game-layout) > .room-heading, .live-game-layout > .table-sidebar { display: none; }
  .live-game-layout { height: 100%; grid-template: minmax(0, 1fr) / minmax(0, 1fr); align-items: stretch; }
  .live-game-layout .game-main {
    grid-template-rows: minmax(151px, 1fr) auto;
    min-height: 0;
    gap: 5px;
  }
  .live-game-layout .table {
    --played-card-width: clamp(27px, min(10vw, 13dvh), 56px);
    grid-template-rows: auto minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1fr) auto;
    min-height: 0;
    gap: 3px;
    padding: 7px;
    border-radius: clamp(18px, 6vw, 42px);
    box-shadow: inset 0 0 0 3px #172b20, inset 0 0 0 4px #7e744a;
  }
  .live-game-layout .table.preparation { grid-template-rows: auto minmax(0, 1fr) auto; }
  .live-game-layout .table-seat {
    width: 100%; min-width: 0; max-width: 136px; padding: 3px 2px; line-height: 1.2; font-size: .75rem;
  }
  .live-game-layout .table-seat :is(.seat-index, strong) {
    display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  }
  .live-game-layout .table-seat .seat-index, .live-game-layout .seat-meta { font-size: .64rem; }
  .live-game-layout .seat-meta { display: flex; flex-wrap: wrap; justify-content: center; column-gap: 4px; }
  .live-game-layout .seat-meta > span { white-space: nowrap; }
  .live-game-layout .seat-separator { display: none; }
  .live-game-layout .table-bid { margin: 3px auto 0; padding: 2px 3px; font-size: .68rem; }
  .live-game-layout .table-bid strong { white-space: normal; }
  .live-game-layout .table-bid small { font-size: .58rem; }
  .live-game-layout .table-bid::before { width: 5px; height: 5px; top: -2px; left: calc(50% - 2px); }
  .live-game-layout .table-card {
    width: auto; height: 100%; max-height: var(--played-card-height); max-width: var(--played-card-width); aspect-ratio: 5 / 7;
  }
  .live-game-layout .table-card .card-img { height: 100%; }
  .live-game-layout .table-card figcaption { padding: 1px; font-size: .56rem; }
  .live-game-layout :is(.table-caption, .table-trick-title, .table-decision-label) { font-size: .74rem; }
  .live-game-layout .table-caption { margin-top: 3px; line-height: 1.2; }
  .live-game-layout .table .deputy-call {
    width: max-content;
    grid-template: "image label" auto "image name" auto / 22px minmax(0, 1fr);
    align-items: center; gap: 0 3px; padding: 3px 4px; font-size: .69rem; line-height: 1.15;
  }
  .live-game-layout .deputy-call span { grid-area: label; font-size: .58rem; }
  .live-game-layout .deputy-call strong { grid-area: name; }
  .live-game-layout .table .deputy-call .card-img { grid-area: image; width: 22px; }
  .live-game-layout .deputy-call::before { width: 7px; height: 7px; }

  .live-game-layout .play-controls {
    display: grid; grid-template-columns: minmax(0, 1fr); align-content: safe end; gap: 4px; padding: 5px 6px;
  }
  .live-game-layout[data-phase="trick"] .play-controls { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .live-game-layout .turn-buttons[data-waiting-for-turn] { display: none; }
  .live-game-layout .trick-controls .desktop-play-label { display: none; }
  .live-game-layout .trick-controls .turn-buttons .mobile-only { display: inline; }
  .live-game-layout .turn-message { min-width: 0; margin-bottom: 0; }
  .live-game-layout .turn-message h2 { font-size: .92rem; line-height: 1.25; overflow-wrap: anywhere; }
  .live-game-layout .trick-controls .turn-message h2 { overflow: visible; white-space: normal; }
  .live-game-layout .turn-message p { font-size: .7rem; line-height: 1.25; margin: 2px 0; }
  .live-game-layout .turn-buttons .button { min-height: 42px; padding: 3px 6px; font-size: .77rem; line-height: 1.2; }
  .live-game-layout .trick-controls .turn-buttons .button { white-space: normal; }
  .live-game-layout .hand {
    grid-column: 1 / -1; justify-content: center; gap: 4px; margin: 0; padding: 4px 0 2px;
  }
  .live-game-layout :is(.hand-card, .hand .card-button) {
    width: min(calc((100% - 24px) / 7), 55px); min-width: 0; touch-action: manipulation;
  }
  .live-game-layout .bid-form { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 3px; }
  .live-game-layout .bid-field { display: flex; align-items: center; gap: 3px; min-width: 0; }
  .live-game-layout .bid-field label { flex: none; font-size: .68rem; }
  .live-game-layout .bid-field select {
    width: 100%; min-height: 40px; padding: 4px 17px 4px 4px; background-position: right 8px center, right 3px center;
  }
  .live-game-layout .bid-actions { display: flex; flex-wrap: wrap; grid-column: 1 / -1; gap: 4px; }
  .live-game-layout .bid-actions .button { flex: 1 0 auto; }
  .live-game-layout .deputy-controls { gap: 3px; }
  .live-game-layout .deputy-controls .actions { gap: 3px; }
  .live-game-layout .deputy-controls .actions:first-child .button { flex: 1 0 auto; min-height: 34px; }
  .live-game-layout .deputy-controls .actions:last-child { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-game-layout .exchange-row { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 6px; }
  .live-game-layout .exchange-row .muted { font-size: .7rem; }
  .live-game-layout .exchange-row .card-button { width: 31px; min-height: 0; margin-top: 1px; padding: 0; }
  .live-game-layout .exchange-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
  .live-game-layout .decision-panel { padding: 7px 9px; }
  .live-game-layout .decision-panel h2 { font-size: .9rem; }
  .live-game-layout .decision-panel p { font-size: .77rem; }
}

@media (max-width: 1050px) and (max-height: 540px) and (orientation: landscape) {
  .wrap:has(.result-game-layout) { padding-top: 7px; }
  .wrap:has(.result-game-layout) > .room-heading > div:first-child {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px;
  }
  .result-panel {
    display: grid;
    grid-template: "heading scores" auto "actions scores" auto "summary scores" auto "reason scores" auto ". scores" 1fr
      / minmax(0, 2fr) minmax(0, 3fr);
    gap: 3px 12px;
    align-items: start;
  }
  .result-heading { grid-area: heading; }
  .result-outcome strong { font-size: clamp(1.35rem, 4.2vw, 1.65rem); }
  .result-game-summary { grid-area: summary; margin-top: 4px; }
  .result-panel .result-reason { grid-area: reason; margin-top: 4px; }
  .result-panel .result-actions { grid-area: actions; margin: 5px 0 0; }
  .result-score-list { grid-area: scores; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-score-card { padding: 5px 6px; }
  .result-player h3 { font-size: .88rem; }
  .live-game-layout .game-main {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    grid-template-rows: minmax(167px, 1fr);
  }
  .live-game-layout .table { --played-card-width: clamp(27px, 11.5dvh, 48px); }
  .live-game-layout .decision-panel { align-self: center; }
  .entrance { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }
  .card-spread { height: min(125px, 31dvh); }
  .hero-card { width: clamp(55px, 24dvh, 90px); }
  .lobby-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .waiting-seats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 660px) and (max-height: 540px) and (orientation: landscape) {
  .live-game-layout .game-main { grid-template-columns: minmax(0, 1.07fr) minmax(0, 1fr); }
  .live-game-layout .deputy-controls .full-deputy-label { display: none; }
  .live-game-layout .deputy-controls .short-deputy-label { display: inline; }
  .live-game-layout .deputy-controls .actions:first-child .button { padding-inline: 4px; }
}

@media (max-width: 520px) {
  .waiting-controls > .primary { width: 100%; }
  .replay-toolbar label[for="replay-position"] + input { flex-basis: 60%; }
}
