:root {
  --bg: #17151f;
  --bg-soft: #242232;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.14);
  --text: #fbfaf8;
  --muted: #c9c5d6;
  --line: rgba(255, 255, 255, 0.16);
  --gold: #f6c65b;
  --gold-dark: #a96c1f;
  --green: #5ce1a5;
  --red: #ff6b7a;
  --black-card: #20202a;
  --white-card: #fff8ec;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 8%, rgba(246, 198, 91, 0.18), transparent 30rem),
    radial-gradient(circle at 82% 18%, rgba(92, 225, 165, 0.14), transparent 26rem),
    linear-gradient(145deg, #17151f 0%, #201a25 48%, #121720 100%);
  overflow-x: hidden;
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 46px;
  padding: 0.8rem 1rem;
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, opacity 160ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
}

button:focus-visible,
.card:focus-visible {
  outline: 3px solid rgba(246, 198, 91, 0.8);
  outline-offset: 3px;
}

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

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: clamp(1rem, 3vw, 2rem);
}

.topbar {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin: 0 auto 1rem;
  max-width: 1180px;
  width: 100%;
}

.topbar h1,
.screen h2,
.section-title h3,
.opponent h3 {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(2.1rem, 5vw, 4.6rem);
  line-height: 0.9;
}

.topbar-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.eyebrow {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  margin: 0 0 0.4rem;
  text-transform: uppercase;
}

.status-pill {
  background: rgba(92, 225, 165, 0.16);
  border: 1px solid rgba(92, 225, 165, 0.32);
  border-radius: 999px;
  color: #baffdc;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 0.55rem 0.85rem;
  white-space: nowrap;
}

.sound-toggle {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 0.85rem;
  min-height: auto;
  padding: 0.55rem 0.85rem;
  white-space: nowrap;
}

.sound-toggle[aria-pressed="false"] {
  color: var(--muted);
  opacity: 0.78;
}

main {
  display: grid;
  flex: 1;
  margin: 0 auto;
  max-width: 1180px;
  width: 100%;
}

.screen {
  display: none;
  min-height: calc(100vh - 8rem);
}

.screen.is-active {
  display: block;
}

.start-screen {
  align-items: center;
  gap: clamp(1.5rem, 5vw, 4rem);
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
}

.start-screen.is-active {
  display: grid;
}

.start-copy h2,
.result-screen h2 {
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 0.95;
  margin-bottom: 1rem;
  max-width: 760px;
}

.start-copy p {
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  line-height: 1.6;
  max-width: 680px;
}

.rule-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(3, 1fr);
  margin: 1.5rem 0;
}

.rule-grid div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

.rule-grid strong {
  color: var(--gold);
  display: block;
  font-size: 1.5rem;
}

.rule-grid span {
  color: var(--muted);
  display: block;
  font-size: 0.92rem;
  margin-top: 0.25rem;
}

.player-select {
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: inline-flex;
  font-weight: 800;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
}

.player-select select {
  appearance: none;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-weight: 900;
  padding: 0.55rem 2rem 0.55rem 0.75rem;
}

.online-panel {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 1rem;
  padding: 1rem;
}

.online-panel h3 {
  margin: 0 0 0.8rem;
}

.online-intro {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  margin: -0.25rem 0 0.85rem;
}

.online-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.online-grid label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  font-weight: 800;
  gap: 0.35rem;
}

.online-grid input {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  min-height: 44px;
  padding: 0.65rem 0.75rem;
  text-transform: none;
}

.online-grid #roomCodeInput {
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.online-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.online-status {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
  margin: 0.75rem 0 0;
}

.online-lobby {
  color: var(--muted);
  display: grid;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.online-rooms {
  color: var(--muted);
  display: grid;
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.online-room-card {
  align-items: center;
  background: rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  display: grid;
  gap: 0.65rem;
  grid-template-columns: 1fr auto;
  padding: 0.7rem;
}

.online-room-card div {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.online-room-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-room-card button {
  min-height: 38px;
  padding: 0.5rem 0.75rem;
}

.online-lobby strong,
.online-rooms strong,
.online-room-card b {
  color: var(--gold);
}

.hero-table {
  align-items: center;
  aspect-ratio: 1;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.02)),
    radial-gradient(circle at center, rgba(92, 225, 165, 0.16), transparent 62%);
  border: 1px solid var(--line);
  border-radius: 50%;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: center;
  min-width: 260px;
  position: relative;
}

.hero-table::before {
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  content: "";
  inset: 10%;
  position: absolute;
}

.mini-card {
  align-items: center;
  background: var(--white-card);
  border-radius: 8px;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.3);
  color: var(--black-card);
  display: flex;
  flex-direction: column;
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 950;
  height: clamp(130px, 22vw, 190px);
  justify-content: center;
  line-height: 1;
  margin: -1.5rem;
  transform: rotate(var(--tilt));
  width: clamp(88px, 15vw, 130px);
  z-index: 1;
}

.mini-card:nth-child(1) {
  --tilt: -16deg;
}

.mini-card:nth-child(2) {
  --tilt: 3deg;
  transform: translateY(-1rem) rotate(var(--tilt));
}

.mini-card:nth-child(3) {
  --tilt: 15deg;
}

.mini-card span {
  font-size: 0.9em;
}

.heart,
.diamond,
.card.red {
  color: #c72238;
}

.spade,
.club,
.card.black {
  color: #20202a;
}

.start-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.start-note {
  color: var(--muted);
  flex-basis: 100%;
  font-size: 0.92rem;
  line-height: 1.45;
  margin: 0;
}

.primary-button {
  background: linear-gradient(180deg, #ffd978, var(--gold));
  box-shadow: 0 12px 24px rgba(246, 198, 91, 0.22);
  color: #251600;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
  color: var(--text);
}

.ghost-button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--muted);
}

.game-screen {
  gap: 1rem;
}

.game-screen.is-active {
  display: grid;
  grid-template-rows: auto auto auto minmax(180px, 1fr) auto auto;
}

.game-head {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.game-head h2 {
  font-size: clamp(1.6rem, 4vw, 3rem);
}

.game-head-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-end;
}

.game-head-actions button {
  font-size: 0.85rem;
  min-height: 38px;
  padding: 0.55rem 0.75rem;
}

.message {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #f4f1ff;
  padding: 0.85rem 1rem;
}

.opponents {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.opponent {
  align-items: center;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.7rem;
  grid-template-columns: 1fr auto;
  min-width: 0;
  padding: 0.75rem;
  position: relative;
}

.opponent.current {
  border-color: rgba(246, 198, 91, 0.72);
  box-shadow: 0 0 0 2px rgba(246, 198, 91, 0.12), 0 12px 28px rgba(246, 198, 91, 0.08);
}

.opponent.is-you {
  border-color: rgba(92, 225, 165, 0.9);
  box-shadow: 0 0 0 2px rgba(92, 225, 165, 0.22), 0 12px 28px rgba(92, 225, 165, 0.08);
}

.opponent.is-you h3 {
  color: #5ce1a5;
}

.opponent.current::before {
  background: var(--gold);
  border-radius: 999px;
  box-shadow: 0 0 14px rgba(246, 198, 91, 0.85);
  content: "";
  height: 9px;
  position: absolute;
  right: 0.65rem;
  top: 0.65rem;
  width: 9px;
}

.opponent.current h3 {
  color: var(--gold);
}

.opponent.eliminated {
  opacity: 0.48;
}

.opponent h3 {
  font-size: 1rem;
}

.opponent span {
  color: var(--muted);
  font-size: 0.78rem;
}

.opponent > strong {
  color: var(--gold);
  font-size: 1.25rem;
  min-width: 2.4rem;
  text-align: right;
}

.opponent-meta {
  grid-column: 1 / -1;
}

.life-row {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.35rem;
}

.life {
  background: rgba(246, 198, 91, 0.3);
  border: 1px solid rgba(246, 198, 91, 0.55);
  border-radius: 999px;
  height: 12px;
  width: 12px;
}

.life.empty {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
}

.back-mini {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.24), transparent 28%),
    linear-gradient(145deg, #4f2b7c, #252044);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 5px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.24);
  height: 42px;
  margin-left: -10px;
  width: 30px;
}

.back-mini:first-child {
  margin-left: 0;
}

.table-area {
  align-items: stretch;
  background:
    linear-gradient(145deg, rgba(23, 88, 65, 0.45), rgba(21, 61, 65, 0.22)),
    rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(92, 225, 165, 0.18);
  border-radius: 8px;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.2);
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(150px, 0.72fr) minmax(280px, 1.4fr) minmax(150px, 0.72fr);
  padding: clamp(1rem, 3vw, 1.5rem);
}

.pile,
.draw-zone,
.table-score {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  justify-content: center;
  min-width: 0;
  text-align: center;
}

.dealer-panel strong {
  color: var(--gold);
  font-size: clamp(1.5rem, 4vw, 2.6rem);
  line-height: 1;
}

.pile > span,
.draw-zone > span,
.table-score > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pile small,
.table-score small {
  color: var(--muted);
}

.table-score strong {
  color: #5ce1a5;
  font-size: clamp(2.8rem, 7vw, 5rem);
  line-height: 0.95;
}

.draw-card-slot {
  align-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 148px;
  min-width: 104px;
  padding: 0.5rem;
}

.table-cards {
  display: grid;
  gap: clamp(0.5rem, 2vw, 0.75rem);
  grid-template-columns: repeat(3, clamp(104px, 9vw, 136px));
  justify-content: center;
  min-width: 0;
  width: 100%;
}

.table-cards .card {
  min-height: 0;
  width: 100%;
}

.player-area {
  align-self: end;
}

.section-title {
  align-items: end;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-title span {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.hand {
  display: grid;
  gap: clamp(0.6rem, 2vw, 1rem);
  grid-template-columns: repeat(3, minmax(82px, 150px));
  justify-content: center;
}

.card {
  aspect-ratio: 0.71;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.94), rgba(255, 248, 236, 0.96));
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.28);
  color: var(--black-card);
  min-height: 124px;
  min-width: 0;
  overflow: hidden;
  padding: 0.65rem;
  position: relative;
  text-align: left;
  transform-origin: 50% 100%;
  user-select: none;
}

.card.card-swap-source {
  opacity: 0;
}

.flying-card {
  box-shadow: 0 26px 46px rgba(0, 0, 0, 0.38), 0 0 22px rgba(246, 198, 91, 0.22);
  margin: 0;
  pointer-events: none;
  position: fixed;
  transform-origin: center;
  will-change: transform, opacity;
  z-index: 30;
}

.card.selectable {
  cursor: pointer;
}

.card.selected {
  border-color: rgba(246, 198, 91, 0.95);
  box-shadow: inset 0 0 0 3px rgba(246, 198, 91, 0.9), 0 18px 34px rgba(0, 0, 0, 0.32);
  transform: none;
}

.card-corner {
  display: grid;
  font-size: clamp(1rem, 3vw, 1.35rem);
  font-weight: 950;
  line-height: 0.95;
  position: absolute;
  left: 0.7rem;
  top: 0.7rem;
  z-index: 1;
}

.card-center {
  display: grid;
  font-size: clamp(2.5rem, 5vw, 4.35rem);
  font-weight: 900;
  inset: 0;
  place-items: center;
  position: absolute;
  line-height: 1;
}

.card-bottom {
  bottom: 0.7rem;
  left: auto;
  right: 0.7rem;
  top: auto;
  transform: rotate(180deg);
}

.deck-card {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.18) 0 8px, transparent 8px 16px),
    linear-gradient(145deg, #4f2b7c, #252044);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff8ec;
  font-size: 1.4rem;
  justify-content: center;
  letter-spacing: 0.08em;
  max-height: 148px;
  min-height: 148px;
  width: 104px;
}

.deck-card span {
  align-self: center;
  justify-self: center;
}

.controls {
  background: rgba(16, 15, 24, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 0.75rem;
  position: sticky;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 4;
}

.result-screen {
  align-content: center;
  justify-items: center;
  text-align: center;
}

.result-screen.is-active {
  display: grid;
}

.winner-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 0.5rem 0 1rem;
  max-width: 560px;
  padding: 1.25rem;
  width: 100%;
}

.winner-card.game-winner {
  border-color: rgba(246, 198, 91, 0.75);
  box-shadow: 0 0 0 2px rgba(246, 198, 91, 0.16), 0 24px 60px rgba(246, 198, 91, 0.12);
}

.winner-card strong {
  color: var(--gold);
  display: block;
  font-size: clamp(2rem, 7vw, 4rem);
  line-height: 1;
}

.victory-trophy {
  filter: drop-shadow(0 12px 22px rgba(246, 198, 91, 0.35));
  font-size: clamp(4rem, 14vw, 7rem);
  line-height: 1;
  margin-bottom: 0.45rem;
}

.winner-summary-label {
  color: var(--gold);
  display: block;
  font-size: 0.82rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.confetti-layer {
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  position: fixed;
  z-index: 60;
}

.confetti-piece {
  animation-name: confettiFall;
  animation-timing-function: cubic-bezier(0.12, 0.68, 0.28, 1);
  animation-fill-mode: forwards;
  background: var(--confetti-color);
  height: 14px;
  left: var(--start-x);
  opacity: 0;
  position: absolute;
  top: -24px;
  transform: translate3d(0, 0, 0) rotate(0deg);
  width: 8px;
}

.results-list {
  display: grid;
  gap: 0.7rem;
  margin-bottom: 1rem;
  max-width: 700px;
  width: 100%;
}

.result-row {
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr auto;
  padding: 0.85rem 1rem;
  text-align: left;
}

.result-row.is-you {
  border-color: rgba(92, 225, 165, 0.95);
  box-shadow: 0 0 0 2px rgba(92, 225, 165, 0.2), 0 12px 28px rgba(92, 225, 165, 0.08);
}

.result-row.is-you b {
  color: #5ce1a5;
}

.result-row strong {
  color: var(--gold);
  font-size: 1.25rem;
}

.result-name-line {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.life-loss-badge {
  background: rgba(255, 83, 103, 0.16);
  border: 1px solid rgba(255, 83, 103, 0.48);
  border-radius: 999px;
  color: #ff6b7d;
  font-size: 0.78rem;
  font-weight: 950;
  line-height: 1;
  padding: 0.35rem 0.55rem;
}

.result-hand {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

@keyframes confettiFall {
  0% {
    opacity: 0;
    transform: translate3d(0, -8vh, 0) rotate(0deg);
  }

  12% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--drift-x), 112vh, 0) rotate(var(--spin));
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 0.9rem;
  }

  .topbar {
    align-items: center;
  }

  .topbar-actions {
    max-width: none;
  }

  .start-screen.is-active {
    align-content: start;
    display: grid;
    gap: 1.25rem;
    grid-template-columns: 1fr;
  }

  .hero-table {
    justify-self: center;
    max-width: 420px;
    width: 86vw;
  }

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

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

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

  .table-area {
    grid-template-columns: 1fr 1fr;
  }

  .draw-zone {
    grid-column: 1 / -1;
  }

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

@media (max-width: 680px) {
  .app-shell {
    padding: 0.75rem;
  }

  body[data-screen="game"] .app-shell {
    padding: 0.35rem;
  }

  body[data-screen="game"] .topbar {
    display: none;
  }

  .topbar {
    gap: 0.65rem;
    margin-bottom: 0.75rem;
  }

  .topbar h1 {
    font-size: 2.45rem;
  }

  .topbar-actions {
    gap: 0.45rem;
  }

  .sound-toggle,
  .status-pill {
    font-size: 0.72rem;
    min-height: 38px;
    padding: 0.45rem 0.65rem;
  }

  .screen {
    min-height: calc(100vh - 5.2rem);
  }

  .game-screen {
    gap: 0.32rem;
  }

  .game-screen.is-active {
    grid-template-rows: auto auto auto auto auto auto;
  }

  .game-head {
    align-items: center;
    display: grid;
    gap: 0.24rem;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .game-head h2 {
    font-size: clamp(1.22rem, 6.4vw, 1.65rem);
    line-height: 0.98;
  }

  .game-head .eyebrow {
    font-size: 0.6rem;
    margin-bottom: 0.14rem;
  }

  .game-head-actions {
    align-items: stretch;
    flex-direction: column;
    gap: 0.25rem;
  }

  .game-head-actions button {
    font-size: 0.62rem;
    min-height: 25px;
    padding: 0.24rem 0.4rem;
  }

  .message {
    font-size: 0.68rem;
    line-height: 1.2;
    overflow: hidden;
    padding: 0.32rem 0.44rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .opponents {
    display: flex;
    gap: 0.4rem;
    margin-inline: -0.45rem;
    overflow-x: auto;
    padding: 0 0.45rem 0.15rem;
    scroll-padding-inline: 0.45rem;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }

  .opponent {
    flex: 0 0 min(54vw, 11.2rem);
    gap: 0.28rem;
    grid-template-columns: 1fr auto;
    min-height: 46px;
    padding: 0.36rem;
    scroll-snap-align: start;
  }

  .opponent h3 {
    font-size: 0.84rem;
  }

  .opponent span {
    font-size: 0.68rem;
  }

  .opponent > strong {
    font-size: 0.88rem;
    max-width: 5.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .opponent-meta {
    margin-top: -0.15rem;
  }

  .life-row {
    gap: 0.22rem;
    margin-top: 0.18rem;
  }

  .life {
    height: 8px;
    width: 8px;
  }

  .table-area {
    gap: 0.28rem;
    grid-template-columns: 1fr 1fr;
    padding: 0.34rem;
  }

  .draw-zone {
    grid-column: 1 / -1;
    order: 1;
  }

  .table-score {
    order: 2;
  }

  .pile {
    order: 3;
  }

  .pile,
  .table-score {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    gap: 0.1rem;
    min-height: 44px;
    padding: 0.26rem 0.3rem;
  }

  .draw-zone {
    gap: 0.28rem;
  }

  .table-cards {
    gap: 0.26rem;
    grid-template-columns: repeat(3, minmax(0, 74px));
  }

  .table-score strong {
    font-size: clamp(1.65rem, 9.8vw, 2.2rem);
  }

  .dealer-panel strong {
    font-size: clamp(0.92rem, 4.8vw, 1.18rem);
  }

  .pile > span,
  .draw-zone > span,
  .table-score > span {
    font-size: 0.58rem;
    letter-spacing: 0.06em;
  }

  .pile small,
  .table-score small {
    font-size: 0.56rem;
  }

  .player-area {
    align-self: auto;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.12rem;
    margin-bottom: 0.16rem;
  }

  .section-title h3 {
    font-size: 0.92rem;
  }

  .section-title span {
    display: none;
  }

  .hand {
    gap: 0.26rem;
    grid-template-columns: repeat(3, minmax(0, 78px));
  }

  .card {
    border-radius: 7px;
    min-height: 0;
    padding: 0.3rem;
  }

  .card-corner {
    font-size: 0.78rem;
    left: 0.34rem;
    top: 0.34rem;
  }

  .card-center {
    font-size: 1.7rem;
  }

  .card-bottom {
    bottom: 0.34rem;
    right: 0.34rem;
  }

  .controls {
    backdrop-filter: blur(14px);
    border-radius: 8px;
    gap: 0.22rem;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin-inline: -0.2rem;
    padding: 0.26rem;
    position: static;
  }

  .controls button {
    font-size: 0.58rem;
    line-height: 1.05;
    min-height: 31px;
    padding: 0.28rem 0.12rem;
  }

}

@media (max-width: 520px) {
  .topbar {
    flex-wrap: wrap;
  }

  .topbar > div:first-child {
    min-width: 0;
  }

  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .start-screen.is-active {
    gap: 1rem;
  }

  .start-copy h2,
  .result-screen h2 {
    font-size: clamp(2rem, 10vw, 2.45rem);
    margin-bottom: 0.75rem;
  }

  .start-copy p {
    font-size: 0.98rem;
    line-height: 1.45;
  }

  .rule-grid {
    gap: 0.55rem;
    margin: 1rem 0;
  }

  .rule-grid div,
  .online-panel {
    padding: 0.75rem;
  }

  .online-actions,
  .start-actions,
  .result-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .online-actions button,
  .start-actions button,
  .result-actions button {
    width: 100%;
  }

  .online-room-card {
    grid-template-columns: 1fr;
  }

  .online-room-card button {
    width: 100%;
  }

  .hero-table {
    display: none;
  }

  .table-area {
    gap: 0.75rem;
    padding: 0.75rem;
  }

  body[data-screen="game"] .table-area {
    gap: 0.24rem;
    padding: 0.28rem;
  }

  .draw-card-slot,
  .deck-card {
    min-height: 128px;
    width: 90px;
  }

  body[data-screen="game"] .draw-card-slot,
  body[data-screen="game"] .deck-card {
    min-height: 86px;
    width: 62px;
  }

  .table-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body[data-screen="game"] .table-cards {
    grid-template-columns: repeat(3, minmax(0, 70px));
  }

  .card {
    min-height: 120px;
    padding: 0.5rem;
  }

  body[data-screen="game"] .card {
    min-height: 0;
    padding: 0.28rem;
  }

  .card-corner {
    left: 0.55rem;
    top: 0.55rem;
  }

  body[data-screen="game"] .card-corner {
    font-size: 0.74rem;
    left: 0.32rem;
    top: 0.32rem;
  }

  body[data-screen="game"] .card-center {
    font-size: 1.58rem;
  }

  .card-bottom {
    bottom: 0.55rem;
    right: 0.55rem;
  }

  body[data-screen="game"] .card-bottom {
    bottom: 0.32rem;
    right: 0.32rem;
  }

  button {
    min-height: 44px;
    padding: 0.7rem 0.75rem;
  }

  body[data-screen="game"] button {
    min-height: 30px;
    padding: 0.28rem 0.2rem;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding: 0.6rem;
  }

  .topbar h1 {
    font-size: 2.2rem;
  }

  .opponents {
    margin-inline: -0.6rem;
    padding-inline: 0.6rem;
  }

  .opponent {
    flex-basis: 84vw;
  }

  .table-area {
    gap: 0.55rem;
    padding: 0.6rem;
  }

  body[data-screen="game"] .table-area {
    gap: 0.22rem;
    padding: 0.24rem;
  }

  .draw-card-slot,
  .deck-card {
    min-height: 118px;
    width: 84px;
  }

  body[data-screen="game"] .draw-card-slot,
  body[data-screen="game"] .deck-card {
    min-height: 78px;
    width: 56px;
  }

  body[data-screen="game"] .table-cards {
    grid-template-columns: repeat(3, minmax(0, 64px));
  }

  .card {
    min-height: 110px;
    padding: 0.45rem;
  }

  body[data-screen="game"] .card {
    min-height: 0;
    padding: 0.24rem;
  }

  .card-center {
    font-size: 2.25rem;
  }

  body[data-screen="game"] .card-center {
    font-size: 1.42rem;
  }

  .card-corner {
    font-size: 0.95rem;
    left: 0.45rem;
    top: 0.45rem;
  }

  body[data-screen="game"] .card-corner {
    font-size: 0.68rem;
    left: 0.28rem;
    top: 0.28rem;
  }

  .card-bottom {
    bottom: 0.45rem;
    right: 0.45rem;
  }

  body[data-screen="game"] .card-bottom {
    bottom: 0.28rem;
    right: 0.28rem;
  }

  .controls button {
    font-size: 0.82rem;
    padding-inline: 0.4rem;
  }

  body[data-screen="game"] .controls button {
    font-size: 0.52rem;
    min-height: 28px;
    padding: 0.22rem 0.08rem;
  }
}

@media (max-width: 680px) and (max-height: 760px) {
  body[data-screen="game"] .message {
    display: none;
  }

  body[data-screen="game"] .opponent {
    min-height: 42px;
  }

  body[data-screen="game"] .pile,
  body[data-screen="game"] .table-score {
    min-height: 40px;
  }

  body[data-screen="game"] .hand,
  body[data-screen="game"] .table-cards {
    gap: 0.2rem;
  }
}

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