:root {
  --bg: #0b1220;
  --bg2: #111a2e;
  --panel: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.1);
  --text: #e8eef8;
  --muted: #8a9ab8;
  --ice: #2f8fe8;
  --rose: #e5484d;
  --mint: #16a37a;
  --gold: #f0a91a;
  --accent: #7cc4ff;
  --card-w: 64px;
  --card-h: 96px;
  --radius: 12px;
  font-family: 'Segoe UI', Tahoma, 'Noto Sans Arabic', system-ui, sans-serif;
}
@media (min-width: 720px) {
  :root {
    --card-w: 78px;
    --card-h: 117px;
  }
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 700px at 50% 35%, #16264a 0%, var(--bg) 60%) fixed;
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#app {
  height: 100%;
}
button {
  font: inherit;
  color: inherit;
}
.muted {
  color: var(--muted);
}
.err {
  color: #ff8a8a;
  max-width: 420px;
  text-align: center;
}

/* ---------- logo / screens */
.logo {
  font-weight: 800;
  font-size: 44px;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #bfe3ff, #7cc4ff 45%, #e8f4ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(124, 196, 255, 0.25);
  direction: ltr;
}
.logo.sm {
  font-size: 22px;
}
.center-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
}
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.name-form {
  display: flex;
  gap: 8px;
}
.name-form input {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
}

/* ---------- buttons */
.btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s;
}
.btn:hover:not([disabled]) {
  background: rgba(255, 255, 255, 0.1);
}
.btn:active:not([disabled]) {
  transform: scale(0.96);
}
.btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn.primary {
  background: linear-gradient(135deg, #2f8fe8, #5b6cff);
  border-color: transparent;
  color: #fff;
}
.btn.big {
  padding: 13px 22px;
  font-size: 17px;
}
.btn.warn {
  background: linear-gradient(135deg, #e5484d, #b3261e);
  border-color: transparent;
}
.btn.ghost {
  background: transparent;
}
.btn.sorn {
  background: linear-gradient(135deg, #7cc4ff, #e8f4ff);
  color: #0b1220;
  border: none;
  font-size: 18px;
  animation: pulse 1s ease-in-out infinite;
}
.btn.catch {
  background: #e5484d;
  border: none;
  color: #fff;
  padding: 4px 10px;
  font-size: 13px;
  animation: pulse 0.7s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    transform: scale(1.07);
    box-shadow: 0 0 22px rgba(124, 196, 255, 0.55);
  }
}

/* ---------- avatars */
.avwrap {
  position: relative;
  display: inline-flex;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  flex: none;
  background: #22345c;
}
.avwrap.lg {
  width: 58px;
  height: 58px;
}
.avwrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.av-fallback {
  margin: auto;
  font-weight: 800;
  color: #cfe3ff;
}

/* ---------- lobby */
.lobby {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 24px 14px 40px;
}
.lobby-head {
  text-align: center;
}
.lobby-head p {
  margin: 4px 0 0;
}
.seats {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 130px));
  gap: 12px;
}
.seat {
  position: relative;
  aspect-ratio: 1;
  border-radius: 18px;
  border: 1px dashed var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
}
.seat.filled {
  border-style: solid;
  background: var(--panel);
  animation: popIn 0.25s ease-out;
}
.seat.away {
  opacity: 0.45;
}
.seat-name {
  font-size: 13px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.seat .plus {
  font-size: 28px;
  color: var(--muted);
}
.crown {
  position: absolute;
  top: 4px;
  left: 6px;
}
.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.watchers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
  max-width: 460px;
}
.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
}
.rules {
  max-width: 480px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.8;
}
.rules summary {
  cursor: pointer;
  font-weight: 700;
}
.rules ul {
  padding-inline-start: 18px;
  margin: 8px 0 0;
}

/* ---------- cards */
.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  flex: none;
  color: #fff;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  direction: ltr;
  transition: transform 0.15s ease, opacity 0.2s, box-shadow 0.2s;
}
.card.c-ice {
  background: linear-gradient(160deg, #4aa6f5, var(--ice) 55%, #1d6fc0);
}
.card.c-rose {
  background: linear-gradient(160deg, #f26b70, var(--rose) 55%, #b8323a);
}
.card.c-mint {
  background: linear-gradient(160deg, #2cc596, var(--mint) 55%, #0d7d5d);
}
.card.c-gold {
  background: linear-gradient(160deg, #ffc44d, var(--gold) 55%, #c5830c);
}
.card.wild {
  background: #141b2d;
}
.card .face {
  position: relative;
  z-index: 1;
  font-weight: 900;
  font-size: calc(var(--card-w) * 0.5);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}
.card .wheel {
  position: absolute;
  width: calc(var(--card-w) * 0.78);
  height: calc(var(--card-w) * 0.78);
  border-radius: 50%;
  background: conic-gradient(var(--ice) 0 25%, var(--rose) 0 50%, var(--mint) 0 75%, var(--gold) 0);
  opacity: 0.95;
}
.card.wild .face b {
  position: relative;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
.card .corner {
  position: absolute;
  font-size: calc(var(--card-w) * 0.2);
  font-weight: 800;
  z-index: 1;
}
.card .corner.tl {
  top: 4px;
  left: 6px;
}
.card .corner.br {
  bottom: 4px;
  right: 6px;
  transform: rotate(180deg);
}
.card .flake {
  position: absolute;
  font-size: calc(var(--card-w) * 1.1);
  opacity: 0.08;
  pointer-events: none;
}
.card.back {
  background: repeating-linear-gradient(45deg, #13203d 0 8px, #172850 8px 16px);
  border-color: #9cc8ff;
}
.back-logo {
  font-weight: 900;
  color: #bfe3ff;
  font-size: calc(var(--card-w) * 0.26);
  transform: rotate(-18deg);
  letter-spacing: 1px;
}
.card.pop {
  animation: popIn 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes popIn {
  from {
    transform: scale(0.6) rotate(-8deg);
    opacity: 0;
  }
}

/* ---------- table */
.table {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.dir {
  font-size: 22px;
  color: var(--accent);
}
.opponents {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 10px 8px 4px;
}
.opp {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 78px;
  padding: 8px 6px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  transition: transform 0.2s, border-color 0.2s;
}
.opp.turn {
  border-color: var(--accent);
  transform: translateY(2px);
  box-shadow: 0 0 18px rgba(124, 196, 255, 0.3);
}
.opp.away {
  opacity: 0.45;
}
.opp-av {
  position: relative;
}
.opp-av .ring {
  position: absolute;
  inset: -6px;
  width: calc(100% + 12px);
  height: calc(100% + 12px);
  transform: rotate(-90deg);
}
.opp-av .ring circle {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-dasharray: 113;
  animation: ring 30s linear forwards;
}
@keyframes ring {
  to {
    stroke-dashoffset: 113;
  }
}
.opp-name {
  font-size: 12px;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opp-cards {
  display: flex;
  align-items: center;
  height: 16px;
  direction: ltr;
}
.opp-cards i {
  width: 9px;
  height: 14px;
  border-radius: 2px;
  background: #2a4f8f;
  border: 1px solid #9cc8ff;
  margin-left: -4px;
}
.opp-cards b {
  margin-left: 6px;
  font-size: 13px;
}
.badge.call {
  position: absolute;
  top: -8px;
  right: -6px;
  background: #e8f4ff;
  color: #0b1220;
  font-size: 11px;
  font-weight: 800;
  border-radius: 999px;
  padding: 2px 7px;
}
.table-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
}
.pile-wrap {
  display: flex;
  gap: 26px;
  align-items: center;
}
.deck {
  position: relative;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.deck:not([disabled]) .card {
  box-shadow: 0 0 0 3px rgba(124, 196, 255, 0.55), 4px 4px 0 #0e1a33, 8px 8px 0 #0a1428;
  animation: nudge 1.4s ease-in-out infinite;
}
.deck[disabled] {
  cursor: default;
}
.card.stack {
  box-shadow: 4px 4px 0 #0e1a33, 8px 8px 0 #0a1428;
}
@keyframes nudge {
  50% {
    transform: translateY(-4px);
  }
}
.deck-count {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: #0b1220;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
}
.discard {
  position: relative;
  border-radius: calc(var(--radius) + 6px);
  padding: 6px;
  transition: box-shadow 0.3s;
}
.discard .card {
  transform: scale(1.15);
}
.glow-ice {
  box-shadow: 0 0 34px rgba(47, 143, 232, 0.65);
}
.glow-rose {
  box-shadow: 0 0 34px rgba(229, 72, 77, 0.65);
}
.glow-mint {
  box-shadow: 0 0 34px rgba(22, 163, 122, 0.65);
}
.glow-gold {
  box-shadow: 0 0 34px rgba(240, 169, 26, 0.65);
}
.pending {
  position: absolute;
  top: -12px;
  left: -14px;
  background: #e5484d;
  color: #fff;
  font-weight: 900;
  border-radius: 999px;
  padding: 3px 10px;
  z-index: 3;
}
.pending.mine {
  animation: pulse 0.8s infinite;
}
.color-now {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}
.dot.c-ice {
  background: var(--ice);
}
.dot.c-rose {
  background: var(--rose);
}
.dot.c-mint {
  background: var(--mint);
}
.dot.c-gold {
  background: var(--gold);
}
.turn-line {
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  padding: 0 10px;
}
.turn-line.mine {
  color: var(--accent);
}
.hint {
  font-weight: 400;
  color: var(--text);
}
.timer {
  width: min(320px, 70vw);
  height: 5px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  margin-inline-start: auto;
}
.timer-fill.low {
  background: #e5484d;
}

/* ---------- my hand */
.me-area {
  border-top: 1px solid var(--line);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.35), transparent);
  padding: 6px 0 max(10px, env(safe-area-inset-bottom));
}
.me-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 42px;
  padding: 0 10px;
}
.reacts {
  display: flex;
  gap: 2px;
  margin-inline-start: auto;
}
.react {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0.75;
}
.react:active {
  transform: scale(1.3);
}
.hand {
  display: flex;
  gap: 0;
  overflow-x: auto;
  padding: 18px 16px 8px;
  scrollbar-width: none;
  direction: ltr;
  justify-content: safe center;
}
.hand::-webkit-scrollbar {
  display: none;
}
.hand .card {
  margin-left: calc(var(--card-w) * -0.28);
}
.hand .card:first-child {
  margin-left: 0;
}
.hand .card.playable {
  transform: translateY(-12px);
  cursor: pointer;
  box-shadow: 0 0 0 3px #e8f4ff, 0 10px 18px rgba(0, 0, 0, 0.4);
}
.hand .card.playable:hover {
  transform: translateY(-20px);
  z-index: 2;
}
.hand .card.dim {
  opacity: 0.45;
}
.hand .card.drawn {
  outline: 3px dashed #e8f4ff;
  outline-offset: 2px;
}
.my-turn .me-area {
  box-shadow: inset 0 3px 0 var(--accent);
}
.spectate {
  text-align: center;
  padding: 18px;
  border-top: 1px solid var(--line);
}

/* ---------- modals */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 18, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  width: min(380px, 100%);
  text-align: center;
  animation: popIn 0.22s ease-out;
}
.modal h3,
.modal h2 {
  margin: 0 0 14px;
}
.color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.color-btn {
  height: 64px;
  border-radius: 14px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  font-weight: 800;
  font-size: 17px;
  cursor: pointer;
  color: #fff;
}
.color-btn.c-ice {
  background: var(--ice);
}
.color-btn.c-rose {
  background: var(--rose);
}
.color-btn.c-mint {
  background: var(--mint);
}
.color-btn.c-gold {
  background: var(--gold);
}
.results .trophy {
  font-size: 54px;
  animation: popIn 0.4s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.ranking {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ranking li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-radius: 12px;
  padding: 6px 10px;
}
.rank {
  width: 20px;
  font-weight: 800;
  color: var(--accent);
}
.rname {
  flex: 1;
  text-align: start;
}
.row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- toasts / misc */
#toasts {
  position: fixed;
  bottom: calc(var(--card-h) + 92px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  z-index: 30;
  pointer-events: none;
  width: min(92vw, 420px);
}
.toast {
  background: rgba(17, 26, 46, 0.95);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  text-align: center;
  font-size: 14px;
  animation: popIn 0.2s ease-out;
  transition: opacity 0.4s, transform 0.4s;
}
.toast.good {
  border-color: rgba(124, 196, 255, 0.6);
}
.toast.bad {
  border-color: rgba(229, 72, 77, 0.7);
}
.toast.out {
  opacity: 0;
  transform: translateY(-8px);
}
.offline {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #b3261e;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 40;
}
.float-emoji {
  position: fixed;
  font-size: 34px;
  pointer-events: none;
  z-index: 50;
  transform: translate(-50%, -50%);
  animation: floatUp 1.6s ease-out forwards;
}
@keyframes floatUp {
  to {
    transform: translate(-50%, -140%) scale(1.4);
    opacity: 0;
  }
}

/* short landscape phones */
@media (max-height: 480px) {
  :root {
    --card-w: 52px;
    --card-h: 78px;
  }
  .opponents {
    padding-top: 4px;
  }
  .opp {
    min-width: 64px;
    padding: 4px;
  }
  .topbar {
    padding: 4px 12px;
  }
  .hand {
    padding-top: 14px;
  }
}
