html:has(.game-screen) { overflow: hidden; overscroll-behavior: none; }

.game-screen {
  --game-line: #30413e;
  --game-muted: var(--muted);
  --game-accent: var(--gold);
  height: 100svh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--felt-background);
}

.game-screen #app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  padding-top: env(safe-area-inset-top);
}

.game-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .65rem;
  min-width: 0;
  padding: .18rem clamp(.7rem, 2.8vw, 2.3rem);
  background: #101f22bf;
}

.game-back {
  justify-self: start;
  padding: .5rem .7rem;
  border: 1px solid var(--game-line);
  border-radius: .5rem;
  color: #d6e1da;
  font-size: .9rem;
  font-weight: 650;
}

.game-brand {
  display: flex;
  align-items: center;
  gap: .48rem;
  color: #f4ecdc;
  font: 1.24rem Georgia, serif;
  white-space: nowrap;
}

.game-brand span {
  display: grid;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  border: 1px solid #80643f;
  border-radius: .45rem;
  color: var(--game-accent);
  background: #302b20;
}

.game-tools { display: flex; justify-content: end; gap: .38rem; }
.game-tools button { color: var(--game-muted); font-size: .875rem; }
.game-tools [data-action="history"] { display: none; }

.game-content {
  width: min(100%, 106rem);
  min-height: 0;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(14rem, 22vw, 20rem);
  gap: clamp(.55rem, 1.6vw, 1.4rem);
  padding: .75rem clamp(.75rem, 2.3vw, 2rem) max(.7rem, env(safe-area-inset-bottom));
}

.table-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: .55rem;
}

.table-heading { display: flex; align-items: center; gap: .65rem; justify-content: space-between; min-width: 0; }
.table-heading > div { min-width: 0; }
.table-heading h1 { font-size: clamp(1.35rem, 3.1vw, 2.3rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table-heading p { margin-top: .21rem; color: var(--game-muted); font-size: .8rem; }
.table-heading-tools { display: flex; flex: none; align-items: center; gap: .35rem; }
.table-heading-tools .mobile-end { display: none; }
.table-status {
  flex: none;
  padding: .27rem .58rem;
  border: 1px solid var(--game-line);
  border-radius: 100px;
  color: #dce6de;
  font-size: .76rem;
  font-weight: 650;
}

.table-status.live { border-color: #496f5f; color: #bcdec9; background: #19362b; }
.table-status.live::before { content: '•'; margin-inline-end: .35rem; color: #94d8ae; }

.felt {
  position: relative;
  min-width: 0;
  min-height: 0;
  isolation: isolate;
  container-type: size;
}

.seats { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.seat {
  position: absolute;
  top: var(--seat-y);
  left: var(--seat-x);
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: .45rem;
  min-width: 0;
  min-height: 2.6rem;
  max-width: min(35%, 10rem);
  padding: .28rem .55rem .28rem .32rem;
  border: 1px solid #51645a;
  border-radius: .78rem;
  background: #142425;
  color: #f6efe1;
  box-shadow: 0 3px 11px #0310119c;
  pointer-events: auto;
}

.avatar {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 1.78rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(150deg, #385c55, #26423d);
  color: #dcf0db;
  font-family: Georgia, serif;
  font-weight: 700;
}

.seat-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; font-weight: 650; }
.seat-count { grid-column: 2; font-size: .73rem; line-height: 1; color: #b8d0c4; }
.seat-count::after { content: ' карт'; }
.seat.own { border-color: #669589; }
.seat.turn { border-color: var(--game-accent); box-shadow: 0 0 0 2px #edc88533, 0 4px 14px #090d0a; }
.seat.turn .avatar { background: #634829; color: #ffe4ab; }
.seat.receiving { border-color: #ffb87c; background: #3f3028; }
.seat-receipt {
  position: absolute;
  top: -.48rem;
  right: -.42rem;
  padding: .02rem .27rem;
  border-radius: .375rem;
  background: #efbb83;
  color: #372213;
  font-size: .76rem;
  font-weight: 800;
}

.felt-center {
  position: absolute;
  z-index: 1;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: clamp(.22rem, 1.8cqh, .65rem);
  width: min(64%, 29rem);
  text-align: center;
}

.turn-callout { display: flex; justify-content: center; align-items: center; min-width: 0; max-width: 100%; gap: .4rem; }
.turn-callout h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(1rem, 2.25vw, 1.58rem);
  color: #f8f3e7;
}
.turn-callout.my-turn h2 { color: #ffde9f; }
.claim {
  flex: none;
  display: grid;
  min-width: 1.7rem;
  min-height: 1.7rem;
  padding-inline: .22rem;
  place-items: center;
  border: 1px solid #bba06c;
  border-radius: .42rem;
  color: #ffe3ad;
  background: #2f392a;
  font: 650 .95rem system-ui, sans-serif;
}

.table-piles { display: flex; justify-content: center; gap: clamp(.8rem, 3vw, 2.15rem); }
.pile-zone { display: grid; justify-items: center; gap: .26rem; }
.stack-caption { font-size: .78rem; color: #c7dcd4; white-space: nowrap; }
.stack-caption strong { color: #fff2dd; font-variant-numeric: tabular-nums; }

.stack, .discard-slot {
  display: grid;
  place-items: center;
  width: clamp(1.5rem, 15cqh, 3.6rem);
  aspect-ratio: 500 / 726;
  border: 1px dashed #a4c3b47a;
  border-radius: .32rem;
  color: #9bbfb0;
  font-size: clamp(.95rem, 6cqh, 1.48rem);
}

.stack.has-cards, .flight-card {
  border: 2px solid #f0c581;
  background:
    repeating-conic-gradient(from 45deg, #fff8d229 0 25%, transparent 0 50%) 0 0 / .55rem .55rem,
    linear-gradient(140deg, #745139, #4b302b);
  color: #fff1d1;
  box-shadow: 2px 2px #5d422c, 4px 4px #c6a36d, 5px 5px 4px #182921;
}

.stack.has-cards span, .discard-slot.filled span {
  display: grid;
  place-items: center;
  width: 55%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #463429;
}

.discard-slot.filled { border-style: solid; color: #abd6c8; background: #244541; box-shadow: 2px 2px #789d89; }
.discard-slot.filled span { background: #1b3833; }
.table-detail, .reveal-summary p, .chest-results { font-size: .82rem; color: #e0ede1; max-width: 100%; }
.table-detail, .reveal-summary p, .chest-results {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.reveal-summary { display: grid; justify-items: center; gap: .25rem; }
.reveal-cards { display: flex; justify-content: center; gap: .25rem; }
.card { display: block; width: clamp(1.3rem, 9cqh, 2.4rem); aspect-ratio: 500 / 726; border-radius: .3rem; padding: 0; }
.card img { display: block; width: 100%; height: 100%; object-fit: contain; }
.reveal-summary .result.take { color: #ffdbaf; }
.chest-results { color: #bfe7ce; }

.game-dock { min-width: 0; }
.hand-heading {
  min-height: 1.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .55rem;
  padding-inline: .35rem;
}
.hand-heading h2 { font: 650 .86rem system-ui, sans-serif; color: #f4ecdc; white-space: nowrap; }
.hand-heading h2 span { margin-inline-start: .3rem; color: #b9c8c0; font-size: .76rem; }
.hand-selection { color: #f5dfbb; font-size: .8rem; font-weight: 650; white-space: nowrap; }

.fan {
  --rows: var(--wide-rows);
  --card-width: clamp(2.35rem, min(9dvh, 11vw), 5.75rem);
  --card-height: calc(var(--card-width) * 1.452);
  --layer-gap: clamp(1.72rem, 4.6dvh, 2.7rem);
  --preferred-step: calc(var(--card-width) * .66);
  position: relative;
  height: calc(.5rem + var(--card-height) + (var(--rows) - 1) * var(--layer-gap));
  width: min(calc(100% - 1rem), 52rem);
  margin-inline: auto;
  display: grid;
  place-items: center;
  isolation: isolate;
}

.fan.empty-hand { height: 2.6rem; }
.hand-region { position: relative; z-index: 2; }

.fan-card {
  --row: var(--wide-row);
  --column: var(--wide-column);
  --gaps: var(--wide-gaps);
  --curve: var(--wide-curve);
  --angle: var(--wide-angle);
  --edge: var(--wide-edge);
  --front: var(--wide-front);
  --step: min(var(--preferred-step), calc((100% - var(--card-width) - .5rem) / var(--gaps)));
  position: absolute;
  left: calc(50% - var(--card-width) / 2 + var(--column) * var(--step));
  top: calc(.15rem + var(--row) * var(--layer-gap));
  width: calc(var(--step) + (var(--card-width) - var(--step)) * var(--edge));
  height: calc(var(--layer-gap) + (var(--card-height) - var(--layer-gap)) * var(--front));
  aspect-ratio: auto;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: .3rem;
  background: transparent;
  touch-action: manipulation;
}

.fan-face {
  --selection-ring: transparent;
  position: absolute;
  inset: 0 auto auto 0;
  width: var(--card-width);
  height: var(--card-height);
  transform: translateY(calc(var(--curve) * 6px)) rotate(var(--angle));
  transform-origin: left top;
  border-radius: .32rem;
  box-shadow: 0 0 0 2px var(--selection-ring), 1px 3px 8px #0009;
  pointer-events: none;
  transition: transform .16s ease-out, box-shadow .16s ease-out;
}

.fan-card.picked .fan-face { --selection-ring: #ff414d; }
.fan-card:focus-visible, .fan-card.peek { z-index: 3; }
.fan-card:focus-visible .fan-face, .fan-card.peek .fan-face {
  transform: translateY(-20%) scale(1.22);
  box-shadow: 0 0 0 2px var(--selection-ring), 0 8px 22px #000d;
}

@media (hover: hover) and (pointer: fine) {
  .fan-card:hover { z-index: 3; }
  .fan-card:hover .fan-face {
    transform: translateY(-21%) scale(1.22);
    box-shadow: 0 0 0 2px var(--selection-ring), 0 8px 22px #000d;
  }
}

.game-controls {
  position: relative;
  z-index: 3;
  min-height: 3.2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: .45rem .7rem;
  padding-top: .3rem;
}
.response-controls, .play-controls { display: flex; align-items: end; gap: .45rem; }
.play-controls label { display: grid; gap: .15rem; color: #e4eee6; font-size: .72rem; }
.play-controls button { min-width: 9.8rem; }
.play-controls button:disabled {
  opacity: 1;
  border-color: #778c7e;
  background: #294743;
  color: #d4e4db;
}
.game-controls .primary { background: var(--game-accent); color: #272316; }
.game-controls .primary:hover:not(:disabled) { background: #ffdd9f; }
.game-controls .secondary { border-color: #6e9a8c; background: #203d37; }
.game-controls .secondary:hover { background: #2c4d43; }
.game-controls .challenge { border-color: #a57467; background: #422e2a; }
.game-controls .challenge:hover { background: #54352c; }
.play-controls select {
  min-height: 2.75rem;
  width: 8.45rem;
  background: #182827;
  border-color: #577168;
  padding: .4rem;
}
.play-controls select:disabled { opacity: .65; }
.game-controls .button { max-width: 100%; overflow-wrap: anywhere; }
.play-controls button { white-space: nowrap; }
.dock-management { display: none; }

.table-aside {
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: .9rem;
  padding: 1rem clamp(.75rem, 1.5vw, 1.2rem);
  border-left: 1px solid #8eac9e44;
  background: #101f2245;
}
.table-aside h2 { font-size: 1.47rem; }
.history-body { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.history { display: grid; gap: .55rem; list-style: none; padding: 0; margin: 0; }
.history li {
  padding: .5rem .6rem;
  border-left: 2px solid #5e7569;
  border-radius: 0 .32rem .32rem 0;
  background: #1c2c2c;
  color: #dae2dc;
  font-size: .83rem;
  overflow-wrap: anywhere;
}
.history li:last-child { border-color: #d8af72; background: #29362d; color: #fff1d9; }
.aside-management { border-top: 1px solid var(--game-line); padding-top: .3rem; }
#game-history { background: #172526; border-color: #49645d; max-height: 74dvh; overflow: auto; }
#game-history [data-history] { margin-top: .75rem; }
#rules { max-height: 82dvh; overflow: auto; }
.game-screen #notice { z-index: 10; bottom: max(1rem, env(safe-area-inset-bottom)); }

.flight-card {
  position: fixed;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 2.9rem;
  aspect-ratio: 500 / 726;
  border-radius: .35rem;
  pointer-events: none;
}
.flight-card.flight-face { border: 0; background: transparent; box-shadow: none; }
.flight-face img { width: 100%; height: 100%; object-fit: contain; }

@media (max-width: 850px) {
  .game-content { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .table-aside { display: none; }
  .game-tools [data-action="history"] { display: inline-flex; }
  .dock-management { display: block; }
  .table-heading-tools .mobile-end { display: inline-flex; font-size: .75rem; min-height: 2.35rem; padding: 0 .25rem; }
}

@media (max-width: 540px) {
  .game-bar { gap: .28rem; padding-inline: .45rem; }
  .game-back { padding-inline: .45rem; font-size: .83rem; }
  .game-brand { font-size: .94rem; gap: .26rem; }
  .game-brand span { width: 1.25rem; height: 1.25rem; border-radius: .3rem; }
  .game-tools { gap: .1rem; }
  .game-tools button { padding-inline: .24rem; font-size: .78rem; }
  .game-content { padding: .4rem .38rem max(.38rem, env(safe-area-inset-bottom)); }
  .table-main { gap: .35rem; }
  .table-heading { padding-inline: .22rem; }
  .table-heading p { font-size: .73rem; }
  .table-status { font-size: .69rem; }
  .felt-center { width: 57%; }
  .dense .felt-center { width: 54%; }
  .seat {
    top: var(--compact-y);
    left: var(--compact-x);
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    row-gap: .13rem;
    border-radius: .45rem;
    width: clamp(3.2rem, 15.6vw, 4.35rem);
    min-height: 0;
    padding: .18rem .24rem .23rem;
  }
  .avatar { grid-row: auto; width: 1.35rem; font-size: .73rem; }
  .seat-name { max-width: 100%; font-size: .68rem; }
  .seat-count { grid-column: 1; font-size: .62rem; }
  .seat-count::after { content: ''; }
  .dense .seat { min-width: 0; width: 2.8rem; }
  .dense .avatar { width: 1.1rem; }
  .dense .seat-name { font-size: .62rem; }
  .seat-receipt { font-size: .64rem; }
  .table-detail, .reveal-summary p, .chest-results { font-size: .73rem; }
  .stack-caption { font-size: .7rem; }
  .fan {
    --rows: var(--phone-rows);
    --card-width: clamp(2.05rem, min(13vw, 7.7dvh), 4.25rem);
    --layer-gap: clamp(1.45rem, 4.5dvh, 2.3rem);
    width: calc(100% - .75rem);
  }
  .fan-card {
    --row: var(--phone-row);
    --column: var(--phone-column);
    --gaps: var(--phone-gaps);
    --curve: var(--phone-curve);
    --angle: var(--phone-angle);
    --edge: var(--phone-edge);
    --front: var(--phone-front);
  }
  .game-controls { gap: .23rem .4rem; }
  .game-controls button, .game-controls .button { font-size: .84rem; padding-inline: .56rem; }
  .response-controls, .play-controls { gap: .26rem; }
  .play-dock .game-controls { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: stretch; padding-inline: .18rem; }
  .game-controls .response-controls { justify-content: center; }
  .game-controls .play-controls { display: grid; grid-template-columns: minmax(7rem, .46fr) minmax(0, 1fr); width: 100%; }
  .play-controls select { width: 100%; }
  .play-controls button { width: 100%; min-width: 0; }
  .play-controls label > span { white-space: nowrap; }
  .dock-management { flex-basis: 100%; text-align: center; }
  .game-controls:has(.response-controls) .dock-management { flex-basis: auto; }
}

@media (max-width: 375px) {
  .game-brand { font-size: .85rem; }
  .game-brand span { display: none; }
  .game-tools button { font-size: .73rem; }
  .table-heading-tools { gap: .2rem; }
  .table-heading-tools:has(.mobile-end) .table-status.live { display: none; }
}

@media (max-width: 540px) and (max-height: 650px) {
  .seat { row-gap: .08rem; line-height: 1.25; }
  .seat .avatar { width: 1.05rem; }
  .dense .seat { padding: .12rem .16rem; }
  .dense .avatar { width: .95rem; }
  .game-controls button, .play-controls select { min-height: 2.5rem; }
  .felt-center { gap: .2rem; }
  .stack, .discard-slot { width: clamp(1.5rem, 11cqh, 2.65rem); }
}

@media (max-height: 520px) {
  .game-content { padding-block: .27rem max(.22rem, env(safe-area-inset-bottom)); }
  .table-main { gap: .2rem; }
  .table-heading h1 { font-size: 1.2rem; }
  .table-heading p { margin-top: .1rem; font-size: .7rem; }
  .fan {
    --card-width: clamp(1.75rem, min(8.75dvh, 12vw), 3.05rem);
    --layer-gap: clamp(1.15rem, 4.8dvh, 1.65rem);
  }
  .game-controls { min-height: 2rem; padding-top: .12rem; }
  .game-controls button, .play-controls select { min-height: 2rem; padding-block: .15rem; }
  .dock-management { flex-basis: auto; }
  .felt-center { gap: .18rem; }
  .table-detail, .reveal-summary p, .chest-results { -webkit-line-clamp: 1; }
  .seat { min-height: 0; }
  .avatar { width: 1.35rem; }
}

@media (min-width: 541px) and (max-height: 520px) {
  .fan { --rows: var(--landscape-rows); width: min(calc(100% - 1rem), 48rem); }
  .fan-card {
    --row: var(--landscape-row);
    --column: var(--landscape-column);
    --gaps: var(--landscape-gaps);
    --curve: var(--landscape-curve);
    --angle: var(--landscape-angle);
    --edge: var(--landscape-edge);
    --front: var(--landscape-front);
  }
  .seat { top: var(--landscape-y); left: var(--landscape-x); }
  .seat-name { font-size: .73rem; }
  .seat-count::after { content: ''; }
}

@container (max-height: 240px) {
  .felt-center { top: 51%; gap: .16rem; }
  .table-detail, .reveal-summary p, .chest-results { font-size: .73rem; }
  .stack, .discard-slot { width: clamp(1.4rem, 10.8cqh, 2.55rem); }
  .felt:not(.dense) .seat {
    grid-template-columns: auto minmax(0, 1fr);
    justify-items: start;
    width: max-content;
    max-width: min(30%, 7.2rem);
    column-gap: .27rem;
    padding: .22rem .28rem;
  }
  .felt:not(.dense) .avatar { grid-row: 1 / span 2; width: 1.13rem; }
  .felt:not(.dense) .seat-count { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  .fan-face { transition: none; }
}
