:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  --felt: #174b39;
  --felt-dark: #0d2f25;
  --gold: #f3c969;
  --cream: #fff9e9;
  --ink: #202019;
  --muted: #a9c4b8;
  --danger: #d95050;
  --panel: rgba(7, 29, 23, 0.84);
}

* { box-sizing: border-box; }
html, body { min-width: 0; min-height: 100%; margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% 15%, rgba(57, 133, 98, .5), transparent 38%),
    linear-gradient(145deg, var(--felt), var(--felt-dark));
  color: white;
  overflow-x: hidden;
  overscroll-behavior-y: auto;
}
#app { width: 100%; min-width: 0; }
button, input { font: inherit; }
button { touch-action: manipulation; }

.shell { width: min(100%, 560px); max-width: 100%; min-height: 100dvh; margin: auto; padding: max(18px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)); }
.home { display: grid; place-content: center; gap: 18px; }
.logo { margin: 0; text-align: center; font-size: clamp(64px, 20vw, 104px); line-height: .85; color: var(--gold); text-shadow: 0 5px 0 #75551e, 0 14px 30px #061c15; }
.tagline { margin: 0; text-align: center; color: var(--muted); }
.panel { min-width: 0; max-width: 100%; padding: 18px; border: 1px solid rgba(255,255,255,.13); border-radius: 22px; overflow-wrap: anywhere; background: var(--panel); box-shadow: 0 18px 55px rgba(0,0,0,.25); backdrop-filter: blur(14px); }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 14px; }
input { width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid rgba(255,255,255,.17); border-radius: 13px; outline: none; color: white; background: rgba(255,255,255,.08); text-transform: none; }
input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(243,201,105,.14); }
.button { max-width: 100%; min-height: 48px; padding: 10px 16px; border: 0; border-radius: 13px; color: #173025; font-weight: 800; white-space: normal; background: var(--gold); box-shadow: 0 5px 0 #99742a; cursor: pointer; }
.button:active { transform: translateY(3px); box-shadow: 0 2px 0 #99742a; }
.button.secondary { color: white; background: rgba(255,255,255,.13); box-shadow: none; border: 1px solid rgba(255,255,255,.15); }
.button.danger { color: white; background: var(--danger); box-shadow: 0 5px 0 #8e2828; }
.button:disabled { opacity: .48; cursor: default; transform: none; box-shadow: none; }
.divider { display: flex; align-items: center; gap: 10px; color: #7fa696; font-size: 12px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: rgba(255,255,255,.12); }
.seat-picker { min-width: 0; margin: 0; padding: 0; border: 0; }
.seat-picker legend { margin-bottom: 8px; color: var(--muted); font-size: 14px; }
.seat-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.seat-option { display: block; cursor: pointer; }
.seat-option input { position: absolute; width: 1px; height: 1px; min-height: 0; margin: 0; opacity: 0; pointer-events: none; }
.seat-option span { min-height: 62px; display: grid; place-items: center; align-content: center; gap: 2px; border: 1px solid rgba(255,255,255,.14); border-radius: 12px; background: rgba(255,255,255,.07); }
.seat-option b { color: var(--gold); font-size: 22px; }
.seat-option small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 10px; white-space: nowrap; }
.seat-option input:checked + span { border-color: var(--gold); background: rgba(243,201,105,.15); box-shadow: 0 0 0 2px rgba(243,201,105,.12); }
.seat-option.occupied { cursor: not-allowed; }
.seat-option.occupied span { opacity: .42; }

.room-head { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.room-head h1 { min-width: 0; margin: 0; overflow-wrap: anywhere; font-size: 24px; color: var(--gold); }
.room-tools { display: flex; align-items: center; gap: 10px; }
.connection { width: 10px; height: 10px; border-radius: 50%; background: #59dc92; box-shadow: 0 0 10px #59dc92; }
.connection.offline { background: #d95d5d; box-shadow: none; }
.room-code { letter-spacing: .16em; }
.seat-list { min-width: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.seat { min-width: 0; min-height: 78px; padding: 12px; border-radius: 15px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); }
.seat.mine { border-color: var(--gold); }
.seat .number { color: var(--gold); font-size: 12px; text-transform: uppercase; }
.seat strong { display: block; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat small { color: var(--muted); }
.offline-text { color: #ed9c9c !important; }
.teams-note { color: var(--muted); overflow-wrap: anywhere; text-align: center; font-size: 13px; }

.game-shell { display: grid; grid-template-rows: auto auto auto minmax(300px, 1fr) auto; gap: 8px; height: auto; min-height: 100dvh; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.game-shell > * { min-width: 0; }
.scorebar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; padding: 8px 10px; border-radius: 14px; background: rgba(0,0,0,.22); }
.team-score { font-size: 13px; color: var(--muted); }
.team-score.right { text-align: right; }
.team-score .team-name { display: block; overflow: hidden; text-overflow: ellipsis; color: var(--muted); white-space: nowrap; }
.team-score strong { display: block; color: white; font-size: 22px; }
.trump { display: grid; justify-items: center; gap: 2px; text-align: center; font-weight: 900; }
.trump-label { color: var(--muted); font-size: 9px; line-height: 1; letter-spacing: .11em; text-transform: uppercase; }
.trump-value { position: relative; display: grid; width: 38px; height: 34px; place-items: center; border: 1px solid rgba(243,201,105,.62); border-radius: 10px; color: var(--ink); background: linear-gradient(145deg, #fffefa, #f5f2e9); box-shadow: 0 4px 12px rgba(0,0,0,.24), inset 0 1px 0 #fff; }
.trump-symbol { font-size: 26px; line-height: 1; }
.trump-symbol.red { color: #bd2929; }
.trump-symbol.empty { color: #77766f; }
.trump-contract { position: absolute; top: -6px; right: -7px; display: grid; width: 18px; height: 18px; place-items: center; border: 2px solid #123b2c; border-radius: 50%; color: #31260f; background: var(--gold); font-size: 10px; line-height: 1; }
.score-tools { display: grid; justify-items: center; gap: 3px; }
.game-controls { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.icon-button { width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 1px solid rgba(255,255,255,.13); border-radius: 9px; color: white; background: rgba(255,255,255,.08); cursor: pointer; }
.icon-button:active { transform: scale(.94); }
.status { min-height: 42px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 12px; text-align: center; color: var(--cream); font-size: 14px; }
.open-tricks { display: grid; grid-template-columns: repeat(2, minmax(88px, 138px)); justify-content: space-between; gap: 8px; }
.trump-reveal { display: inline-flex; align-items: center; gap: 7px; padding: 4px 8px; border: 1px solid var(--gold); border-radius: 10px; color: var(--gold); background: rgba(0,0,0,.2); font-size: 11px; font-weight: 800; }
.trump-reveal .card { pointer-events: none; }

.table { position: relative; min-height: 300px; border: 1px solid rgba(255,255,255,.13); border-radius: 38% / 18%; background: radial-gradient(circle, rgba(40,116,83,.92), rgba(10,57,42,.82)); box-shadow: inset 0 0 40px rgba(0,0,0,.3), 0 12px 35px rgba(0,0,0,.2); }
.player-chip { position: absolute; max-width: 34%; padding: 5px 9px; border-radius: 999px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; background: rgba(4,25,19,.7); border: 1px solid transparent; }
.player-chip.active { color: white; border-color: var(--gold); box-shadow: 0 0 14px rgba(243,201,105,.22); animation: active-player 1.7s ease-in-out infinite; }
.player-chip.dealing { color: white; border-color: var(--gold); box-shadow: 0 0 22px rgba(243,201,105,.55); }
.player-chip.partner::after { content: " · пара"; color: var(--gold); }
.pos-top { top: 7px; left: 50%; transform: translateX(-50%); }
.pos-left { left: 5px; top: 50%; transform: translateY(-50%); }
.pos-right { right: 5px; top: 50%; transform: translateY(-50%); }
.pos-bottom { bottom: 7px; left: 50%; transform: translateX(-50%); }
.trick-card { position: absolute; z-index: calc(1 + var(--play-order)); }
.trick-card.awaiting-drop { visibility: hidden; }
.trick-card.pos-top { top: calc(50% - 22px); bottom: auto; left: 50%; right: auto; transform: translate(-50%, -50%) rotate(-3deg); }
.trick-card.pos-left { top: 50%; bottom: auto; left: calc(50% - 24px); right: auto; transform: translate(-50%, -50%) rotate(-7deg); }
.trick-card.pos-right { top: 50%; bottom: auto; left: calc(50% + 24px); right: auto; transform: translate(-50%, -50%) rotate(7deg); }
.trick-card.pos-bottom { top: calc(50% + 22px); bottom: auto; left: 50%; right: auto; transform: translate(-50%, -50%) rotate(3deg); }
.trick-card.played-in.from-top { animation: play-from-top .42s cubic-bezier(.2,.75,.25,1) both; }
.trick-card.played-in.from-left { animation: play-from-left .42s cubic-bezier(.2,.75,.25,1) both; }
.trick-card.played-in.from-right { animation: play-from-right .42s cubic-bezier(.2,.75,.25,1) both; }
.trick-card.played-in.from-bottom { animation: play-from-bottom .42s cubic-bezier(.2,.75,.25,1) both; }
.card { position: relative; width: 58px; aspect-ratio: 2.5 / 3.5; overflow: hidden; padding: 5px; border: 1px solid rgba(31,29,24,.08); border-radius: 10px; color: var(--ink); background: linear-gradient(145deg, #fffefa, #f5f2e9); box-shadow: 0 6px 14px rgba(0,0,0,.34), inset 0 1px 0 #fff; font-weight: 900; text-align: left; user-select: none; }
.card.red { color: #bd2929; }
.card .card-corner { position: absolute; top: 6px; left: 7px; display: grid; justify-items: center; font-weight: 900; line-height: .85; }
.card .card-corner.bottom { top: auto; right: 7px; bottom: 6px; left: auto; transform: rotate(180deg); }
.card .rank { display: inline-block; font-size: 17px; line-height: .85; }
.card .suit { display: block; margin-top: 3px; font-size: 14px; line-height: 1; }
.card .big-suit { position: absolute; inset: 0; display: grid; place-items: center; font-size: 29px; opacity: .94; }
.card[data-rank="10"] .rank { font-size: 14px; font-variant-numeric: tabular-nums; letter-spacing: .06em; line-height: .9; }
.card.back { background: repeating-linear-gradient(45deg, #25499c 0 6px, #e8ddbd 6px 8px); border: 4px solid var(--cream); }
.card.mini { width: 36px; border-radius: 5px; padding: 3px; }
.card.mini .card-corner { top: 3px; left: 4px; }
.card.mini .card-corner.bottom { top: auto; right: 4px; bottom: 3px; left: auto; }
.card.mini .rank { font-size: 10px; }
.card.mini[data-rank="10"] .rank { font-size: 8px; letter-spacing: .04em; }
.card.mini .suit { margin-top: 1px; font-size: 9px; }
.card.mini .big-suit { font-size: 18px; }

.open-trick { min-width: 0; min-height: 49px; padding: 5px 7px; border: 1px solid rgba(255,255,255,.1); border-radius: 11px; color: var(--muted); background: rgba(4,25,19,.34); font-size: 10px; pointer-events: none; }
.open-trick.team-1 { text-align: right; }
.open-trick-label { display: block; color: var(--muted); font-size: 8px; letter-spacing: .08em; text-transform: uppercase; }
.open-trick strong { display: block; overflow: hidden; margin: 1px 0 3px; color: var(--gold); text-overflow: ellipsis; white-space: nowrap; }
.open-trick-cards { min-height: 25px; display: flex; align-items: center; gap: 3px; }
.open-trick.team-1 .open-trick-cards { justify-content: flex-end; }
.open-trick-card { display: inline-flex; min-width: 25px; height: 25px; align-items: center; justify-content: center; gap: 1px; padding: 0 3px; border: 1px solid rgba(31,29,24,.08); border-radius: 6px; color: var(--ink); background: linear-gradient(145deg, #fffefa, #f5f2e9); box-shadow: 0 2px 5px rgba(0,0,0,.24); font-size: 10px; font-weight: 900; line-height: 1; white-space: nowrap; }
.open-trick-card.red { color: #bd2929; }
.open-trick-empty { opacity: .72; }

.deck-marker { position: absolute; z-index: 2; display: grid; justify-items: center; gap: 3px; color: var(--gold); font-size: 9px; pointer-events: none; }
.deck-marker .card { display: block; width: 40px; box-shadow: -2px 2px 0 #e8ddbd, -4px 4px 0 #25499c, 0 8px 16px rgba(0,0,0,.3); }
.deck-marker.deck-top { top: 40px; left: 50%; transform: translateX(-50%); }
.deck-marker.deck-bottom { bottom: 40px; left: 50%; transform: translateX(-50%); }
.deck-marker.deck-left { top: 50%; left: 42px; transform: translateY(-50%); }
.deck-marker.deck-right { top: 50%; right: 42px; transform: translateY(-50%); }
.deck-marker.shuffling .card { animation: shuffle-deck .36s ease-in-out 2; }

.hand-wrap { min-height: 116px; }
.hand-wrap.drag-active { position: relative; z-index: 12; }
.hand { display: flex; align-items: flex-end; justify-content: center; overflow-x: auto; padding: 9px 8px 12px; scrollbar-width: none; }
.hand.dragging-hand { overflow: visible; }
.hand::-webkit-scrollbar { display: none; }
.hand .card { flex: 0 0 66px; width: 66px; margin-left: -16px; transition: transform .12s, filter .12s; cursor: pointer; }
.hand .card:first-child { margin-left: 0; }
.hand .card.legal { outline: 3px solid var(--gold); transform: translateY(-7px); touch-action: none; }
.hand .card.dragging { z-index: 6; transform: translate3d(var(--drag-x, 0), calc(var(--drag-y, 0px) - 7px), 0) scale(1.055); filter: brightness(1.06); box-shadow: 0 16px 30px rgba(0,0,0,.52), 0 0 20px rgba(243,201,105,.42); transition: none; cursor: grabbing; }
.hand .card.dragging.drop-ready { outline-width: 4px; filter: brightness(1.12); box-shadow: 0 18px 34px rgba(0,0,0,.55), 0 0 28px rgba(243,201,105,.72); }
.hand .card.drag-hint { animation: drag-hint .42s ease; }
.hand .card:not(.legal) { cursor: default; }
.hand.awaiting-deal .card { opacity: 0; }
.hand .card.receiving { animation: receive-card .52s cubic-bezier(.18,.8,.25,1) var(--receive-delay, 0ms) both; }
.game-shell.animating-deal .actions, .game-shell.animating-deal .hand { pointer-events: none; }
.game-shell.animating-deal .actions { opacity: .62; }
.hand .card.invalid { animation: invalid-card .42s ease; }
@keyframes invalid-card {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-9px) rotate(-2deg); }
  60% { transform: translateX(8px) rotate(2deg); }
}
.hand .card.marriage::after { content: attr(data-marriage); position: absolute; top: -8px; right: -7px; padding: 3px 5px; border-radius: 8px; color: #3a2a09; background: var(--gold); font-size: 10px; }
.actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; min-height: 48px; }
.actions .button { min-height: 42px; }
.actions .marriage-action { color: #3a2a09; background: #ffe49a; box-shadow: 0 5px 0 #99742a; }
.suit-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }
.suit-button { min-height: 54px; border: 0; border-radius: 13px; color: #202019; background: var(--cream); font-size: 27px; cursor: pointer; }
.suit-button.red { color: #bd2929; }
.draw-options { display: flex; justify-content: center; gap: 12px; }
.draw-options .card { width: 68px; cursor: pointer; }
.result { position: absolute; inset: 50% auto auto 50%; width: min(88%, 340px); transform: translate(-50%, -50%); z-index: 3; text-align: center; }
.result h2 { color: var(--gold); margin-top: 0; }
.announcement { color: var(--gold); font-size: 12px; }
.inactive-note { margin: 20px auto; color: var(--muted); text-align: center; }
#toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 20; max-width: calc(100% - 32px); padding: 10px 14px; border-radius: 12px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; color: white; background: #9d3131; box-shadow: 0 8px 30px rgba(0,0,0,.35); transition: .2s; }
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.success { color: #173025; background: var(--gold); }

#fx-layer { position: fixed; inset: 0; z-index: 50; overflow: hidden; pointer-events: none; }
.fx-flying-card { position: fixed; z-index: 51; width: 38px; margin: 0; }
.fx-play-card { position: fixed; z-index: 53; margin: 0; transform-origin: top left; pointer-events: none; }
.fx-collect-card { position: fixed; z-index: 52; width: 58px; margin: 0; }
.fx-reveal { position: fixed; top: 50%; left: 50%; z-index: 54; display: grid; justify-items: center; gap: 10px; padding: 14px 18px; border: 1px solid var(--gold); border-radius: 18px; color: var(--gold); background: rgba(5,27,20,.9); box-shadow: 0 22px 70px rgba(0,0,0,.48); font-size: 13px; font-weight: 900; }
.fx-reveal .card { width: 104px; pointer-events: none; }
.fx-reveal .card .rank { font-size: 25px; }
.fx-reveal .card[data-rank="10"] .rank { font-size: 20px; }
.fx-reveal .card .suit { font-size: 21px; }
.fx-reveal .card .big-suit { font-size: 48px; }
.fx-announcement { position: fixed; top: 48%; left: 50%; z-index: 55; display: flex; align-items: center; gap: 12px; padding: 15px 22px; border: 2px solid var(--gold); border-radius: 18px; color: #3a2a09; background: #ffe49a; box-shadow: 0 18px 55px rgba(0,0,0,.4); }
.fx-announcement strong { font-size: 21px; }
.fx-announcement span { font-size: 32px; }
.trump.trump-set { animation: trump-set .8s ease-out; }
.table.card-drag-active { border-color: rgba(243,201,105,.38); transition: border-color .16s, box-shadow .16s; }
.table.card-drop-ready { border-color: var(--gold); box-shadow: inset 0 0 46px rgba(243,201,105,.12), 0 0 22px rgba(243,201,105,.2), 0 12px 35px rgba(0,0,0,.2); }

@keyframes active-player {
  0%, 100% { box-shadow: 0 0 10px rgba(243,201,105,.2); }
  50% { box-shadow: 0 0 22px rgba(243,201,105,.58); }
}
@keyframes shuffle-deck {
  0%, 100% { translate: 0 0; rotate: 0deg; }
  35% { translate: -7px -2px; rotate: -5deg; }
  70% { translate: 7px 1px; rotate: 5deg; }
}
@keyframes receive-card {
  from { translate: 0 -70px; rotate: -7deg; scale: .82; opacity: 0; }
  to { translate: 0 0; rotate: 0deg; scale: 1; opacity: 1; }
}
@keyframes drag-hint {
  0%, 100% { transform: translateY(-7px); }
  45% { transform: translateY(-22px); }
}
@keyframes play-from-top { from { translate: 0 -130px; opacity: .25; } to { translate: 0 0; opacity: 1; } }
@keyframes play-from-left { from { translate: -150px 0; opacity: .25; } to { translate: 0 0; opacity: 1; } }
@keyframes play-from-right { from { translate: 150px 0; opacity: .25; } to { translate: 0 0; opacity: 1; } }
@keyframes play-from-bottom { from { translate: 0 155px; opacity: .25; } to { translate: 0 0; opacity: 1; } }
@keyframes trump-set {
  0% { transform: scale(.6); filter: brightness(1); }
  45% { transform: scale(1.45); filter: brightness(1.7); }
  100% { transform: scale(1); filter: brightness(1); }
}

@media (min-width: 700px) {
  .game-shell { width: min(100%, 680px); }
  .table { min-height: 380px; }
  .card { width: 68px; }
  .hand .card { flex-basis: 78px; width: 78px; }
}

@media (max-width: 420px) {
  .shell { padding-right: 10px; padding-left: 10px; }
  .panel { padding: 14px; }
  .room-head { gap: 8px; }
  .room-head h1 { font-size: 22px; }
  .room-tools { gap: 6px; }
  .seat-list { gap: 8px; }
  .seat { min-height: 74px; padding: 10px; }
  .seat .number { font-size: 10px; }
  .seat strong { font-size: 15px; }
  .scorebar { gap: 4px; padding-right: 6px; padding-left: 6px; }
  .team-score { min-width: 0; font-size: 11px; }
  .team-score strong { font-size: 19px; }
  .status { font-size: 12px; }
  .open-tricks { grid-template-columns: repeat(2, minmax(84px, 116px)); gap: 4px; }
  .open-trick { padding-right: 5px; padding-left: 5px; }
  .open-trick-card { min-width: 23px; padding-right: 2px; padding-left: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
