:root {
  --bg: #faf6ef;
  --ink: #211d19;
  --muted: #7a7264;
  --accent: #c1272d;
  --accent-dark: #9c1f24;
  --card-border: #e3dcd0;
  --panel: #ffffff;
  --good: #1f7a5c;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--accent); font-weight: 600; }

#app { max-width: 560px; margin: 0 auto; padding: 0 14px 28px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 2px 10px;
}
.logo { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.12em; }
.logo-suit { color: var(--accent); margin-left: 2px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.whoami { font-weight: 700; }
.icon-btn { font-size: 1.15rem; background: none; border: none; cursor: pointer; padding: 6px; }
.text-btn { background: none; border: none; color: var(--ink); font-size: 0.95rem; cursor: pointer; padding: 6px 4px; }
.text-btn.danger { color: var(--accent); }

.banner {
  background: #fff3cd; border: 1px solid #e6cf8a; color: #6b5710;
  padding: 10px 12px; border-radius: var(--radius); margin-bottom: 12px; font-size: 0.9rem;
}

.card-panel {
  background: var(--panel); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card-panel h2 { margin: 0 0 10px; font-size: 1.15rem; }
.card-panel h3 { margin: 16px 0 8px; font-size: 1rem; }
.card-panel h3:first-child { margin-top: 0; }

label { display: block; margin-bottom: 10px; font-size: 0.9rem; color: var(--muted); }
input {
  width: 100%; padding: 12px; margin-top: 4px; font-size: 1rem;
  border: 1px solid var(--card-border); border-radius: 10px; background: #fff; color: var(--ink);
}
.code-input { flex: 1; text-transform: uppercase; letter-spacing: 0.1em; }

.btn {
  appearance: none; border: 1px solid var(--card-border); background: #fff; color: var(--ink);
  padding: 12px 18px; border-radius: 999px; font-size: 1rem; font-weight: 700; cursor: pointer;
  min-height: 48px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
.btn.big { width: 100%; padding: 14px 18px; }
.btn.small { padding: 8px 14px; min-height: 40px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ready-on { background: var(--good); border-color: var(--good); color: #fff; }
.btn-row { display: flex; gap: 10px; align-items: stretch; margin: 8px 0; }
.btn-row .btn { flex: 1; }
.btn-col { display: flex; flex-direction: column; gap: 10px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tab {
  border: 1px solid var(--card-border); background: #fff; color: var(--ink);
  padding: 8px 12px; border-radius: 999px; font-size: 0.88rem; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

table.lb { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.lb th, table.lb td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--card-border); }
table.lb th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
table.lb td.num, table.lb th.num { text-align: right; }
table.lb tr.me td { font-weight: 800; }
.lb-empty { color: var(--muted); padding: 8px 0; }

.rules-text p { margin: 8px 0; line-height: 1.45; }
summary { cursor: pointer; font-size: 1.05rem; }

.room-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.room-code { font-size: 0.95rem; }
.room-code strong { letter-spacing: 0.12em; }

.waiting-player {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--card-border);
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none;
}
.badge {
  margin-left: auto; padding: 5px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 700;
  background: #f0e9dc; color: var(--muted);
}
.badge.ready { background: var(--good); color: #fff; }
.badge.empty { background: #fff; border: 1px dashed var(--card-border); }

.hukam-banner {
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px; text-align: center;
}
.hukam-banner .h-title { font-size: 1.25rem; font-weight: 800; letter-spacing: 0.04em; }
.hukam-banner .h-sub { font-size: 0.92rem; opacity: 0.92; margin-top: 2px; }
.hukam-banner.check { background: var(--ink); }

.opponents { display: flex; gap: 10px; justify-content: center; margin-bottom: 8px; }
.opp {
  flex: 1; max-width: 240px; background: var(--panel); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 10px; text-align: center; position: relative;
}
.opp.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(193, 39, 45, 0.25); }
.opp .avatar { margin: 0 auto 4px; }
.opp-name { font-weight: 800; }
.opp-count { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-weight: 700; margin-top: 4px; }
.mini-back {
  width: 16px; height: 23px; border-radius: 3px; display: inline-block;
  background: repeating-linear-gradient(45deg, var(--accent), var(--accent) 3px, #a51f25 3px, #a51f25 6px);
  border: 1px solid #fff; box-shadow: 0 0 0 1px var(--card-border);
}
.place-badge {
  position: absolute; top: 8px; right: 8px; background: var(--ink); color: #fff;
  border-radius: 999px; padding: 3px 9px; font-size: 0.75rem; font-weight: 800;
}

.table-area {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  background: #f3ecdd; border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 16px 10px 12px; margin-bottom: 10px;
}
.table-side { width: 84px; text-align: center; }
.table-center { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pile-slot { min-height: 104px; display: flex; align-items: center; justify-content: center; }
.pile-label { font-size: 0.8rem; color: var(--muted); font-weight: 700; margin-top: 4px; }
.chip {
  background: #fff; border: 1px solid var(--card-border); border-radius: 999px;
  padding: 6px 14px; font-weight: 800; font-size: 0.92rem;
}
.chip .red { color: var(--accent); }
.chip.stack { background: var(--accent); color: #fff; border-color: var(--accent); font-size: 1.05rem; animation: pulse 0.9s infinite alternate; }
.chip.subtle { font-weight: 600; color: var(--muted); font-size: 0.82rem; }
.chip.turn { font-size: 0.85rem; text-align: center; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.07); } }

.toast {
  background: var(--ink); color: #fff; border-radius: 10px; padding: 9px 12px;
  text-align: center; font-weight: 700; margin-bottom: 10px; font-size: 0.95rem;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 6px; min-height: 48px; }
.actions .btn { flex: 0 1 auto; }
.actions .hint { width: 100%; text-align: center; color: var(--muted); font-size: 0.9rem; font-weight: 600; }

.hand {
  display: flex; justify-content: center; align-items: flex-end;
  padding: 18px 4px 6px; min-height: 128px; overflow-x: auto;
}
.my-name { text-align: center; font-weight: 800; margin-top: 2px; }

/* Playing cards */
.card {
  width: 64px; height: 92px; background: #fff; border: 1px solid var(--card-border);
  border-radius: 9px; position: relative; flex: none; user-select: none;
  box-shadow: 0 1px 3px rgba(33, 29, 25, 0.12);
}
.card.red { color: var(--accent); }
.card.black { color: var(--ink); }
.card .corner { position: absolute; font-weight: 800; font-size: 0.82rem; line-height: 1.05; text-align: center; }
.card .corner.tl { top: 4px; left: 5px; }
.card .corner.br { bottom: 4px; right: 5px; transform: rotate(180deg); }
.card .pip {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.9rem; font-weight: 800;
}
.card.face .pip { font-size: 1.6rem; }
.card.back {
  background: repeating-linear-gradient(45deg, var(--accent), var(--accent) 5px, #a51f25 5px, #a51f25 10px);
  border-color: #fff; box-shadow: 0 0 0 1px var(--card-border), 0 1px 3px rgba(33,29,25,0.15);
}
.card.big { width: 74px; height: 106px; }
.card.big .pip { font-size: 2.3rem; }
.card.big .corner { font-size: 0.95rem; }
.hand .card { margin-left: -22px; cursor: pointer; transition: transform 0.12s ease; }
.hand .card:first-child { margin-left: 0; }
.hand .card.playable { transform: translateY(-12px); box-shadow: 0 0 0 2px var(--accent), 0 4px 8px rgba(33,29,25,0.18); }
.hand .card.pickable { transform: translateY(-12px); box-shadow: 0 0 0 2px var(--good), 0 4px 8px rgba(33,29,25,0.18); }
.hand .card.dim { opacity: 0.55; }
.card.flip-in { animation: flipIn 0.45s ease; }
@keyframes flipIn { from { transform: rotateY(90deg); } to { transform: rotateY(0); } }
.pile-stack { position: relative; }
.pile-stack .card { position: absolute; }
.pile-stack .card:nth-child(1) { transform: rotate(-6deg) translate(-3px, 2px); }
.pile-stack .card:nth-child(2) { transform: rotate(4deg) translate(3px, -1px); }
.pile-stack .card:nth-child(3) { position: relative; }

.results-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--card-border);
  font-size: 1.02rem;
}
.results-row .place { font-weight: 800; width: 64px; }
.results-row .pts { margin-left: auto; font-weight: 800; color: var(--accent); }

/* Overlays & animation */
.overlay {
  position: fixed; inset: 0; background: rgba(33, 29, 25, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px;
}
.overlay-card {
  background: #fff; border-radius: var(--radius); padding: 20px; width: 100%; max-width: 400px; text-align: center;
}
.overlay-card h3 { margin: 0 0 14px; }
.suit-row { display: flex; gap: 8px; margin: 12px 0; }
.suit-btn {
  flex: 1; font-size: 1.9rem; padding: 12px 0 8px; border: 1px solid var(--card-border);
  border-radius: 12px; background: #fff; cursor: pointer; color: var(--ink);
}
.suit-btn span { display: block; font-size: 0.75rem; font-weight: 700; }
.suit-btn.red { color: var(--accent); }

.anim-layer {
  position: fixed; inset: 0; background: rgba(250, 246, 239, 0.96); z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.anim-deck { position: relative; width: 74px; height: 106px; }
.anim-deck .card { position: absolute; inset: 0; }
.anim-deck.shuffling .card:nth-child(1) { animation: shuf1 0.28s infinite alternate; }
.anim-deck.shuffling .card:nth-child(2) { animation: shuf2 0.32s infinite alternate; }
.anim-deck.shuffling .card:nth-child(3) { animation: shuf3 0.24s infinite alternate; }
@keyframes shuf1 { from { transform: translate(-7px, 0) rotate(-5deg); } to { transform: translate(7px, -3px) rotate(4deg); } }
@keyframes shuf2 { from { transform: translate(6px, 2px) rotate(5deg); } to { transform: translate(-6px, -2px) rotate(-4deg); } }
@keyframes shuf3 { from { transform: translate(0, 3px) rotate(0); } to { transform: translate(0, -4px) rotate(2deg); } }
.anim-text { font-size: 1.15rem; font-weight: 800; }
.fly-card { position: fixed; z-index: 35; pointer-events: none; transition: transform 0.16s ease, opacity 0.16s ease; }

.foul-banner {
  position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%) rotate(-4deg);
  background: var(--accent); color: #fff; font-size: 2rem; font-weight: 900; letter-spacing: 0.06em;
  padding: 14px 30px; border-radius: 14px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  text-align: center;
}
.foul-banner .foul-sub { font-size: 1rem; font-weight: 700; display: block; margin-top: 2px; }

@media (min-width: 480px) {
  .card { width: 72px; height: 104px; }
  .hand .card { margin-left: -20px; }
}
