:root {
  --bg-dark: #081c15;
  --felt-green: #0f382c;
  --felt-border: #1b4332;
  --gold-accent: #ffd166;
  --gold-glow: rgba(255, 209, 102, 0.4);
  --ruby-red: #d90429;
  --card-bg: #f8f9fa;
  --text-light: #f1faee;
  --text-muted: #acccba;
  --panel-bg: rgba(15, 30, 24, 0.92);
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-deep: 0 16px 32px rgba(0, 0, 0, 0.5);
  --transition-fast: 0.18s cubic-bezier(0.22, 1, 0.36, 1);
  --transition-smooth: 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Tajawal', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-light);
  direction: rtl;
}

/* App Container */
.game-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: -webkit-fill-available;
  position: relative;
  background: radial-gradient(circle at center, #1b4d3e 0%, #081c15 100%);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Top Navigation Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(8, 28, 21, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 10;
  height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--gold-accent);
}

.app-icon {
  font-size: 1.4rem;
}

/* Score Pill Button Header */
.score-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 209, 102, 0.3);
  padding: 4px 14px;
  border-radius: 30px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.score-pill:active {
  transform: scale(0.96);
}

.score-team {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

.score-team .label {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.score-team .val {
  font-weight: 800;
  font-size: 1.1rem;
}

.score-team.us .val {
  color: #52b788;
}

.score-team.them .val {
  color: #ff4d6d;
}

.score-divider {
  color: rgba(255, 255, 255, 0.3);
  font-weight: 700;
}

.target-badge {
  background: var(--gold-accent);
  color: #000;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 10px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-light);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.18);
  transform: scale(0.95);
}

/* Contract Info Banner */
.contract-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.85rem;
}

.contract-chip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.contract-type {
  font-weight: 700;
  color: var(--gold-accent);
}

.contract-buyer {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.round-trick-counter {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Table Area */
.table-area {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 12px;
  overflow: hidden;
}

.table-felt {
  position: relative;
  width: 100%;
  max-width: 680px;
  height: 100%;
  max-height: 520px;
  background: radial-gradient(ellipse at center, #1a4d3e 0%, #0e3025 80%, #092019 100%);
  border-radius: 40px;
  border: 12px solid #2d1810;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8), 0 20px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.table-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.05;
  background-image: radial-gradient(var(--gold-accent) 1px, transparent 0);
  background-size: 24px 24px;
  pointer-events: none;
  border-radius: 28px;
}

.table-center-logo {
  position: absolute;
  opacity: 0.15;
  pointer-events: none;
  text-align: center;
}

.table-center-logo .logo-text {
  font-size: 3.5rem;
  font-weight: 900;
  letter-spacing: 4px;
  color: var(--gold-accent);
}

/* Player Seats */
.player-seat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 5;
  transition: transform 0.3s ease;
}

.seat-north { top: 12px; }
.seat-east  { right: 12px; }
.seat-west  { left: 12px; }
.seat-south { bottom: 12px; }

.avatar-ring {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #183a2e;
  border: 2px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.player-seat.active-turn .avatar-ring {
  border-color: var(--gold-accent);
  box-shadow: 0 0 16px var(--gold-accent);
  animation: pulseTurn 1.2s infinite alternate;
}

@keyframes pulseTurn {
  from { transform: scale(1); box-shadow: 0 0 10px var(--gold-accent); }
  to { transform: scale(1.08); box-shadow: 0 0 22px var(--gold-accent); }
}

.dealer-chip {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--ruby-red);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #fff;
  opacity: 0;
  transform: scale(0);
  transition: var(--transition-fast);
}

.dealer-chip.visible {
  opacity: 1;
  transform: scale(1);
}

.player-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.player-name {
  font-size: 0.8rem;
  font-weight: 700;
}

.player-status {
  font-size: 0.7rem;
  color: var(--gold-accent);
  min-height: 14px;
}

.hand-card-count {
  font-size: 0.7rem;
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 8px;
  border-radius: 10px;
  color: var(--text-muted);
}

/* Center Trick Cards Zone */
.trick-zone {
  position: absolute;
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.played-slot {
  position: absolute;
  width: 64px;
  height: 90px;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.slot-north { top: 0; }
.slot-east  { right: 10px; }
.slot-south { bottom: 0; }
.slot-west  { left: 10px; }

/* Turn Card & Center Deck */
.deck-center {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 6;
}

.turn-card-wrapper {
  position: relative;
  width: 70px;
  height: 100px;
  perspective: 1000px;
}

.bid-message-bubble {
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--gold-accent);
  color: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  animation: fadeIn 0.3s ease;
}

/* Cards Visual Design */
.card {
  width: 68px;
  height: 98px;
  background-color: var(--card-bg);
  border-radius: 8px;
  border: 1px solid #dcdcdc;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 5px;
  font-weight: 800;
  position: relative;
  user-select: none;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.2, 1, 0.3, 1), box-shadow 0.2s ease;
  backface-visibility: hidden;
}

.card.red {
  color: var(--ruby-red);
}

.card.black {
  color: #111;
}

.card-top {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1;
}

.card-value {
  font-size: 1.1rem;
}

.card-suit-sm {
  font-size: 0.9rem;
}

.card-center-suit {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  opacity: 0.9;
}

.card-bottom {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
  transform: rotate(180deg);
}

/* Card Back Design */
.card-back {
  background: linear-gradient(135deg, #1d3557 0%, #457b9d 100%);
  border: 2px solid #fff;
}

.card-back::before {
  content: "🃏";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  opacity: 0.7;
}

/* Player Hand Container */
.player-hand-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 8px 12px 14px;
  z-index: 8;
}

.player-hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 110px;
  max-width: 500px;
  width: 100%;
  position: relative;
}

.player-hand .card {
  margin-left: -22px;
  transform-origin: bottom center;
}

.player-hand .card:first-child {
  margin-left: 0;
}

.player-hand .card:hover, .player-hand .card.selected {
  transform: translateY(-20px) scale(1.08) !important;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5), 0 0 12px var(--gold-accent);
  z-index: 20;
}

.player-hand .card.disabled {
  opacity: 0.4;
  filter: grayscale(0.8);
  cursor: not-allowed;
}

/* Floating Bidding Panel */
.bidding-panel, .double-panel {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid rgba(255, 209, 102, 0.4);
  backdrop-filter: blur(16px);
  padding: 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-deep);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 90%;
  max-width: 440px;
  animation: slideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.bidding-header {
  font-weight: 800;
  color: var(--gold-accent);
  font-size: 1rem;
}

.bidding-actions, .double-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

.bid-btn {
  flex: 1;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-light);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.bid-btn:active {
  transform: scale(0.95);
}

.bid-btn.pass-btn { background: rgba(108, 117, 125, 0.3); }
.bid-btn.hokm-btn { background: rgba(217, 4, 41, 0.4); border-color: #d90429; }
.bid-btn.sun-btn { background: rgba(255, 209, 102, 0.3); border-color: var(--gold-accent); color: var(--gold-accent); }
.bid-btn.ashkal-btn { background: rgba(72, 149, 239, 0.3); border-color: #4895ef; }
.bid-btn.double-btn { background: linear-gradient(135deg, #e63946, #d90429); color: #fff; }

.suit-selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 8px;
}

.suit-selector-title {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.suit-buttons {
  display: flex;
  gap: 8px;
  width: 100%;
}

.suit-btn {
  flex: 1;
  padding: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Toast Projects Announcer */
.projects-toast {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: linear-gradient(135deg, rgba(20, 50, 40, 0.95), rgba(10, 30, 20, 0.95));
  border: 2px solid var(--gold-accent);
  padding: 12px 24px;
  border-radius: 30px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  z-index: 20;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.projects-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-title {
  font-weight: 800;
  color: var(--gold-accent);
  font-size: 0.95rem;
}

.toast-content {
  font-size: 0.85rem;
  margin-top: 2px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.25s ease;
}

.modal-card {
  background: #0f281e;
  border: 1px solid rgba(255, 209, 102, 0.3);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-deep);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h3 {
  font-size: 1.1rem;
  color: var(--gold-accent);
}

.close-modal-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.6;
}

/* Nashra Table */
.nashra-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
}

.nashra-table th, .nashra-table td {
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.nashra-table th {
  color: var(--gold-accent);
  font-weight: 700;
}

.total-row {
  font-weight: 900;
  font-size: 1.05rem;
  background: rgba(255, 209, 102, 0.1);
}

.nashra-target-hint {
  text-align: center;
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Victory Game Over Card */
.victory-card {
  text-align: center;
  padding: 30px 20px;
  align-items: center;
}

.game-over-icon {
  font-size: 4rem;
  margin-bottom: 10px;
}

.final-score-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 20px 0;
  background: rgba(0, 0, 0, 0.3);
  padding: 16px;
  border-radius: var(--radius-md);
  width: 100%;
}

.final-team {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.final-team strong {
  font-size: 1.8rem;
}

.final-team.us strong { color: #52b788; }
.final-team.them strong { color: #ff4d6d; }

.primary-btn {
  background: linear-gradient(135deg, var(--gold-accent), #e0a96d);
  color: #000;
  border: none;
  padding: 12px 32px;
  border-radius: 30px;
  font-family: inherit;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(255, 209, 102, 0.4);
  transition: var(--transition-fast);
}

.primary-btn:active {
  transform: scale(0.96);
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Mobile responsive adjustments */
@media (max-width: 480px) {
  .top-bar { padding: 6px 10px; }
  .brand .app-title { font-size: 0.95rem; }
  .score-pill { padding: 2px 10px; }
  .table-felt { border-width: 8px; border-radius: 28px; }
  .player-hand .card { margin-left: -28px; }
  .card { width: 60px; height: 86px; }
  .card-value { font-size: 1rem; }
  .card-center-suit { font-size: 1.5rem; }
  .bid-btn { padding: 10px 4px; font-size: 0.85rem; }
}