:root {
  --bg: #0c1a0c;
  --bg-card: #152615;
  --bg-hover: #1e331e;
  --text: #f2f7f2;
  --text-muted: #9aaf9a;
  --primary: #1a4a28;
  --primary-light: #2a6b3a;
  --gold: #d4af37;
  --gold-dark: #b8941f;
  --gold-soft: rgba(212, 175, 55, 0.15);
  --accent: #3a8a4a;
  --danger: #c0392b;
  --success: #27ae60;
  --border: #2a452a;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, 'Noto Sans Arabic', Tahoma, Arial, sans-serif;
}

[data-theme="light"] {
  --bg: #f0f5f0;
  --bg-card: #ffffff;
  --bg-hover: #e4ede4;
  --text: #1a2a1a;
  --text-muted: #5a6e5a;
  --primary: #1a4a28;
  --primary-light: #2a6b3a;
  --gold: #b8941f;
  --gold-dark: #8a6f15;
  --gold-soft: rgba(184, 148, 31, 0.12);
  --accent: #2e7a3e;
  --danger: #c0392b;
  --success: #27ae60;
  --border: #c5d5c5;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  transition: background 0.3s, color 0.3s;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  padding: 1.1rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand img {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.brand-text h1 {
  font-size: 1.45rem;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-text p {
  font-size: 0.9rem;
  color: var(--gold);
  margin-top: 0.1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

/* Language Switcher */
.lang-switcher {
  display: flex;
  gap: 0.3rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 24px;
  padding: 0.25rem;
}

.lang-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1.35rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  opacity: 0.55;
}

.lang-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}

.lang-btn.active {
  opacity: 1;
  background: var(--gold);
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.45);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-card);
  color: var(--text);
  line-height: 1.3;
}

.btn:hover {
  background: var(--bg-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--gold);
  color: #1a1a1a;
  border: none;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--gold-dark);
  color: #1a1a1a;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
}

.btn-danger:hover {
  background: #a93226;
}

.btn-success {
  background: var(--success);
  color: #fff;
  border: none;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.2rem;
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Layout */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
}

/* Tabs */
.nav-tabs {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  background: var(--bg-card);
  padding: 0.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: var(--header-h, 72px);
  z-index: 90;
}

.nav-tab {
  flex: 1;
  min-width: 110px;
  padding: 0.8rem 1rem;
  text-align: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 550;
  font-size: 0.98rem;
  transition: all 0.2s;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
}

.nav-tab:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(26, 74, 40, 0.4);
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.15rem;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 1.2rem;
  font-weight: 650;
  margin-bottom: 1.1rem;
  color: var(--gold);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Grid */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.15rem;
}

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

/* Forms */
.form-group {
  margin-bottom: 1.15rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.45rem;
  font-weight: 550;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1.02rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

select.form-control {
  cursor: pointer;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}

th, td {
  padding: 0.9rem 1rem;
  text-align: start;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--bg-hover);
}

/* Score buttons */
.score-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.1rem 0;
}

.score-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 92px;
  height: 92px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 2rem;
  font-family: inherit;
  color: var(--text);
}

.score-btn:hover {
  border-color: var(--gold);
  background: var(--gold-soft);
  transform: scale(1.06);
  box-shadow: var(--shadow-sm);
}

.score-btn:active {
  transform: scale(0.98);
}

.score-btn span {
  font-size: 0.78rem;
  margin-top: 0.3rem;
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}

/* Leaderboard */
.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.leaderboard-item.rank-1 {
  border-color: var(--gold);
  background: linear-gradient(90deg, var(--gold-soft), transparent);
}

.rank {
  font-size: 1.5rem;
  font-weight: 700;
  width: 40px;
  text-align: center;
  color: var(--gold);
}

.player-name {
  flex: 1;
  font-weight: 600;
  font-size: 1.08rem;
}

.player-score {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

/* Stats */
.stat-box {
  text-align: center;
  padding: 1.4rem 1rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.stat-value {
  font-size: 2.2rem;
  font-weight: 750;
  color: var(--gold);
  line-height: 1.15;
}

.stat-label {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  font-weight: 500;
}

/* History */
.history-item {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.85rem 0.4rem;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item .emoji {
  font-size: 1.55rem;
  flex-shrink: 0;
}

.history-time {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-inline-start: auto;
  white-space: nowrap;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s;
  padding: 1rem;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: scale(0.92);
  transition: transform 0.25s;
}

.modal-overlay.show .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.35rem;
}

.modal-header h2 {
  font-size: 1.3rem;
  color: var(--gold);
  font-weight: 650;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.7rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.2rem;
}

.modal-close:hover {
  color: var(--text);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.75rem;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: var(--primary);
  color: #fff;
  padding: 0.95rem 1.6rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 300;
  transition: transform 0.3s ease;
  font-weight: 550;
  font-size: 1.02rem;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 2.75rem 1.25rem;
  color: var(--text-muted);
}

.empty-state .emoji {
  font-size: 3.2rem;
  margin-bottom: 0.85rem;
}

.empty-state p {
  font-size: 1.05rem;
}

/* Responsive */
@media (max-width: 640px) {
  html {
    font-size: 16px;
  }

  .header {
    flex-direction: column;
    gap: 0.85rem;
    text-align: center;
    padding: 1rem 1.15rem;
  }

  .brand {
    flex-direction: column;
    gap: 0.5rem;
  }

  .header-actions {
    justify-content: center;
  }

  .score-btn {
    width: 80px;
    height: 80px;
    font-size: 1.7rem;
  }

  .nav-tab {
    min-width: 90px;
    font-size: 0.9rem;
    padding: 0.7rem 0.6rem;
  }

  .stat-value {
    font-size: 1.9rem;
  }

  .container {
    padding: 1rem 0.85rem 2rem;
  }
}

/* Print */
@media print {
  .header,
  .nav-tabs,
  .btn,
  .header-actions,
  .no-print,
  .lang-switcher {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}

/* Utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.mt-1 { margin-top: 0.6rem; }
.mb-1 { margin-bottom: 0.6rem; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.fw-bold { font-weight: 700; }

/* LTR support */
[dir="ltr"] th,
[dir="ltr"] td {
  text-align: left;
}

[dir="ltr"] .history-time {
  margin-inline-start: auto;
}

/* View-only banner */
.status-banner {
  background: var(--bg-card);
  color: var(--text-muted);
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.status-banner.admin-active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* Flag score buttons slightly different */
.score-btn-flag {
  border-color: #5a3a3a;
}

.score-btn-flag:hover {
  border-color: var(--danger);
  background: rgba(192, 57, 43, 0.12);
}

/* Worst rank highlight */
.rank-worst {
  border-color: var(--danger) !important;
  background: linear-gradient(90deg, rgba(192, 57, 43, 0.12), transparent) !important;
}

/* Better touch targets on mobile */
@media (max-width: 640px) {
  .btn-icon {
    width: 46px;
    height: 46px;
  }
  .lang-btn {
    width: 42px;
    height: 42px;
  }
  .nav-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .nav-tab {
    flex: 0 0 auto;
    min-width: 100px;
  }
}

/* Leaderboard breakdown emojis */
.lb-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.lb-breakdown {
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  line-height: 1.3;
  word-break: break-all;
}

/* Legend / Symbols Guide */
.legend-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.legend-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.legend-heading {
  font-size: 1.08rem;
  color: var(--gold);
  margin-bottom: 0.85rem;
  font-weight: 650;
}

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

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.legend-emoji {
  font-size: 1.7rem;
  flex-shrink: 0;
}

.legend-list {
  padding-inline-start: 1.4rem;
  line-height: 1.7;
  color: var(--text-muted);
}

.legend-list li {
  margin-bottom: 0.4rem;
}


/* Scroll to top button */
.scroll-top-btn {
  position: fixed;
  bottom: 1.5rem;
  inset-inline-end: 1.25rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--gold);
  color: #1a1a1a;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, opacity 0.2s;
  opacity: 0.92;
}

.scroll-top-btn:hover {
  transform: scale(1.08);
  opacity: 1;
}

.scroll-top-btn.show {
  display: flex;
}

@media (max-width: 640px) {
  .scroll-top-btn {
    bottom: 1.25rem;
    inset-inline-end: 1rem;
    width: 46px;
    height: 46px;
  }
}

/* Facebook header button */
.fb-btn {
  background: #1877f2 !important;
  color: #fff !important;
  font-weight: 800;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1.25rem !important;
  text-decoration: none !important;
  border: none !important;
}
.fb-btn:hover {
  filter: brightness(1.08);
  color: #fff !important;
}

/* Community card in Legend */
.fb-community-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-top: 1.25rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  text-decoration: none !important;
  color: inherit !important;
  background: linear-gradient(135deg, rgba(24, 119, 242, 0.14), rgba(24, 119, 242, 0.04));
  border: 1px solid rgba(24, 119, 242, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.fb-community-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(24, 119, 242, 0.18);
}
.fb-community-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #1877f2;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.4rem;
  font-family: Helvetica, Arial, sans-serif;
  flex-shrink: 0;
}
.fb-community-card strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 0.15rem;
}
.fb-community-card span {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.fb-arrow {
  margin-inline-start: auto;
  font-size: 1.2rem;
  color: #1877f2;
  font-weight: 700;
}
