:root {
  color-scheme: dark;
  font-family: "Tajawal", "Cairo", system-ui, -apple-system, Segoe UI, Arial, sans-serif;
  color: #ffffff;
  background: #05070a;
  --panel: rgba(8, 12, 16, 0.62);
  --panel-strong: rgba(7, 12, 14, 0.82);
  --line: rgba(255, 255, 255, 0.15);
  --muted: rgba(255, 255, 255, 0.72);
  --gold: #f4d27a;
  --green: #3fd08f;
  --ruby: #ff5f8f;
  --ink: #11151c;
  --card: #fff7e9;
  --felt: #0c4b39;
  --felt-deep: #061f1a;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(3, 5, 8, 0.18), rgba(3, 5, 8, 0.76)),
    linear-gradient(90deg, rgba(4, 33, 29, 0.82), rgba(42, 7, 20, 0.58)),
    url("/assets/salfa-desktop.png") center bottom / cover fixed,
    #05070a;
}

button,
a {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  color: inherit;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  margin-inline: auto;
  padding: clamp(10px, 1.5vw, 18px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: clamp(10px, 1.4vw, 16px);
}

.topbar,
.table-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.topbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 18px;
}

.brand,
.top-actions,
.top-actions a {
  display: inline-flex;
  align-items: center;
}

.brand {
  gap: 10px;
  font-weight: 950;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.24), transparent 45%),
    linear-gradient(135deg, #f4d27a, #df5b7d 52%, #39d1a0);
  color: #11151c;
  font-size: 1.45rem;
  font-weight: 950;
}

.top-actions {
  gap: 8px;
}

.top-actions a,
.action-bar button,
.mode,
.room-card button,
.deck-stack,
.discard-stack {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.10);
  cursor: pointer;
  font-weight: 900;
}

.top-actions a {
  justify-content: center;
  padding-inline: 14px;
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 12px;
}

.side-panel {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(160px, 0.32fr) minmax(220px, 0.45fr) minmax(260px, 0.55fr) minmax(300px, 0.8fr);
  align-items: stretch;
  gap: 10px;
  padding: clamp(10px, 1.4vw, 16px);
  border-radius: 22px;
}

.kicker,
.subtitle {
  margin: 0;
  color: var(--muted);
  font-weight: 850;
}

.kicker {
  color: var(--gold);
}

h1 {
  margin: 0;
  font-size: clamp(3.2rem, 5vw, 5.8rem);
  line-height: 0.88;
  letter-spacing: 0;
}

.subtitle {
  max-width: 25rem;
  font-size: 1.06rem;
  line-height: 1.65;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.24);
}

.mode.is-active {
  border-color: rgba(244, 210, 122, 0.56);
  background: linear-gradient(135deg, rgba(244, 210, 122, 0.22), rgba(63, 208, 143, 0.14));
}

.score-grid div,
.rules-card,
.dealer-strip,
.zone-title,
.action-bar button {
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.08);
}

.score-grid div {
  min-height: 70px;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 10px 8px;
  border-radius: 16px;
}

.score-grid span,
.label,
.mini-label {
  color: var(--muted);
  font-weight: 850;
}

.score-grid strong {
  font-size: 1.8rem;
}

.rules-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 16px;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.45;
}

.room-card {
  display: none;
  gap: 8px;
  align-content: start;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
}

.room-card.is-visible {
  display: grid;
}

.room-mode .side-panel {
  max-height: 300px;
  align-items: start;
  overflow-y: auto;
  scrollbar-width: thin;
}

.room-mode .room-card {
  order: -3;
}

.room-mode .mode-switch {
  order: -2;
}

.room-mode .play-table {
  min-height: calc(100svh - 390px);
}

.room-card label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 850;
}

.room-card input {
  min-height: 38px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 0 10px;
  background: rgba(0, 0, 0, 0.24);
  color: #ffffff;
  font: inherit;
  font-weight: 850;
}

.room-actions,
.join-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.room-card button {
  min-height: 38px;
  color: #ffffff;
}

.open-rooms,
.room-players {
  display: grid;
  gap: 6px;
}

.open-room,
.room-player {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.18);
  color: rgba(255, 255, 255, 0.82);
  font-weight: 850;
}

.open-room {
  cursor: pointer;
}

.invite-box {
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid rgba(244, 210, 122, 0.22);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
}

.qr-box {
  width: 136px;
  height: 136px;
  display: grid;
  place-items: center;
  justify-self: center;
  padding: 8px;
  border-radius: 14px;
  background: #ffffff;
}

.room-mode .qr-box {
  width: 104px;
  height: 104px;
}

.qr-box svg {
  width: 100%;
  height: 100%;
}

.rules-card strong {
  color: #ffffff;
}

.play-table {
  min-height: calc(100svh - 250px);
  width: 100%;
  display: grid;
  grid-template-columns: minmax(260px, 0.52fr) minmax(420px, 1fr);
  grid-template-areas:
    "dealer dealer"
    "opponent opponent"
    "center melds"
    "player player"
    "actions actions";
  grid-template-rows: auto auto minmax(126px, auto) auto auto;
  gap: 10px;
  padding: clamp(10px, 1.4vw, 16px);
  border-radius: 26px;
  background:
    linear-gradient(135deg, rgba(244, 210, 122, 0.08), transparent 28%),
    radial-gradient(circle at 50% 44%, rgba(63, 208, 143, 0.22), transparent 46%),
    linear-gradient(135deg, rgba(7, 45, 35, 0.92), rgba(8, 14, 20, 0.78) 58%, rgba(58, 9, 26, 0.74)),
    var(--panel-strong);
  overflow: hidden;
}

.dealer-strip {
  grid-area: dealer;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 18px;
}

.dealer-strip div {
  display: grid;
  gap: 2px;
}

.dealer-strip strong {
  font-size: 1.2rem;
}

.dealer-strip p {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  font-weight: 850;
  text-align: left;
}

.opponent-zone,
.player-zone,
.meld-column {
  min-width: 0;
}

.opponent-zone {
  grid-area: opponent;
}

.player-zone {
  grid-area: player;
}

.zone-title {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  font-weight: 900;
}

.zone-title strong {
  color: var(--gold);
}

.card-backs,
.hand,
.meld-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-backs {
  min-height: 68px;
  justify-content: center;
  padding: 10px 4px 0;
}

.opponent-row {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.16);
}

.mini-backs {
  min-height: 44px;
  justify-content: start;
  padding: 0;
  overflow: hidden;
}

.mini-backs .card-back {
  width: 30px;
  height: 42px;
  border-radius: 8px;
}

.card-back {
  width: 48px;
  height: 68px;
  border: 1px solid rgba(244, 210, 122, 0.30);
  border-radius: 11px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 46%),
    repeating-linear-gradient(45deg, rgba(244, 210, 122, 0.18) 0 5px, transparent 5px 10px),
    linear-gradient(145deg, #111827, #540f2b);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.30);
  transform: rotate(var(--tilt));
}

.center-table {
  grid-area: center;
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 220px));
  justify-content: center;
  align-items: center;
  gap: clamp(14px, 3vw, 34px);
  padding: 4px;
}

.deck-stack,
.discard-stack {
  min-height: 126px;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04)),
    rgba(4, 10, 12, 0.62);
}

.deck-stack strong {
  width: 76px;
  height: 98px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.20), transparent 44%),
    repeating-linear-gradient(135deg, rgba(244, 210, 122, 0.20) 0 7px, transparent 7px 14px),
    linear-gradient(145deg, #123d36, #7f1f45);
  color: #ffffff;
  font-size: 1.55rem;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08), 0 16px 26px rgba(0, 0, 0, 0.34);
}

.discard-stack .compact-card {
  pointer-events: none;
}

.meld-zone {
  grid-area: melds;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.meld-list {
  min-height: 76px;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-top: 8px;
}

.meld-row {
  min-height: 68px;
  padding: 8px;
  border: 1px solid rgba(244, 210, 122, 0.16);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.18);
  overflow-x: auto;
}

.meld-type {
  min-width: max-content;
  color: var(--gold);
  font-size: 0.9rem;
  font-weight: 950;
}

.hand {
  min-height: 132px;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  padding: 14px 0 4px;
}

.card {
  width: clamp(64px, 6.5vw, 92px);
  height: calc(clamp(64px, 6.5vw, 92px) * 1.42);
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  place-items: center;
  border: 1px solid rgba(17, 21, 28, 0.18);
  border-radius: 13px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.84), rgba(255, 247, 233, 0.96)),
    var(--card);
  color: var(--ink);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.62),
    0 13px 24px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.card.compact-card {
  width: 76px;
  height: 102px;
}

.meld-row .card {
  width: 42px;
  height: 60px;
  border-radius: 9px;
  cursor: default;
}

.card:disabled {
  cursor: default;
}

.card:hover:not(:disabled) {
  transform: translateY(-5px);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.76),
    0 18px 30px rgba(0, 0, 0, 0.34);
}

.card.is-selected {
  transform: translateY(-16px);
  border-color: rgba(244, 210, 122, 0.82);
  box-shadow:
    0 0 0 3px rgba(244, 210, 122, 0.24),
    0 20px 34px rgba(0, 0, 0, 0.40);
}

.rank {
  width: 100%;
  padding: 7px 8px 0;
  text-align: start;
  font-size: 1.04rem;
  font-weight: 950;
}

.suit {
  font-size: clamp(1.8rem, 3.5vw, 3.1rem);
  line-height: 1;
}

.card.compact-card .suit {
  font-size: 2.2rem;
}

.meld-row .suit {
  font-size: 1.3rem;
}

.corner {
  width: 100%;
  padding: 0 8px 7px;
  text-align: end;
  font-size: 0.92rem;
  font-weight: 950;
}

.face-card.red {
  color: #b7144d;
}

.face-card.black {
  color: #11151c;
}

.placeholder {
  min-height: 58px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.62);
  font-weight: 850;
}

.action-bar {
  grid-area: actions;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.action-bar button {
  padding-inline: 12px;
  color: #ffffff;
}

.top-actions a:hover,
.action-bar button:hover:not(:disabled),
.deck-stack:hover:not(:disabled),
.discard-stack:hover:not(:disabled) {
  border-color: rgba(244, 210, 122, 0.52);
  background: rgba(255, 255, 255, 0.15);
}

.action-bar button:disabled,
.deck-stack:disabled,
.discard-stack:disabled {
  opacity: 0.48;
  cursor: default;
}

.is-winner {
  color: var(--green);
}

.is-warning {
  color: var(--gold);
}

@media (max-width: 1080px) {
  body {
    background-attachment: scroll;
  }

  .side-panel {
    grid-template-columns: 1fr;
    align-content: start;
  }

  h1 {
    font-size: clamp(3.6rem, 16vw, 6rem);
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions a {
    flex: 1;
  }

  .play-table {
    min-height: auto;
    grid-template-columns: 1fr;
    grid-template-areas:
      "dealer"
      "opponent"
      "center"
      "player"
      "actions"
      "melds";
    grid-template-rows: auto auto auto auto auto auto;
    border-radius: 22px;
  }

  .dealer-strip {
    align-items: start;
    flex-direction: column;
  }

  .dealer-strip p {
    text-align: right;
  }

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

  .deck-stack,
  .discard-stack {
    min-height: 126px;
  }

  .meld-zone,
  .action-bar,
  .score-grid {
    grid-template-columns: 1fr;
  }

  .card {
    width: clamp(58px, 18vw, 76px);
  }

  .hand {
    min-height: 132px;
    gap: 7px;
  }
}
