:root {
  --bg: #030914;
  --line: rgba(255, 255, 255, 0.05);
  --text: #ffffff;
  --muted: rgba(233, 238, 245, 0.6);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --r: 24px;
  
  --accent: #00e5ff; /* Cyan */
  --gold: #e5c276;
  
  --good: #34d399; /* Green finish */
  --bad: #fb7185; /* Red warning */

  /* Purple for Under/Nazool */
  --purple: #a855f7;
  --purpleBg: rgba(168, 85, 247, 0.15);
  --purpleLine: rgba(168, 85, 247, 0.5);

  /* WhatsApp Green */
  --wa: #25D366;
  --waBg: rgba(37, 211, 102, 0.15);
  --waLine: rgba(37, 211, 102, 0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0; 
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Kufi Arabic", "Noto Sans Arabic", sans-serif;
  background-color: var(--bg);
  background-image: 
    radial-gradient(circle at 50% -10%, rgba(0, 229, 255, 0.12) 0%, transparent 60%),
    radial-gradient(circle at 0% 100%, rgba(229, 194, 118, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 100% 50%, rgba(0, 229, 255, 0.06) 0%, transparent 50%);
  background-attachment: fixed;
  overflow-x: hidden;
}

.dust {
  position: fixed; inset: 0; pointer-events: none; opacity: 0.25;
  background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><filter id="noiseFilter"><feTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noiseFilter)"/></svg>');
  mix-blend-mode: overlay;
  z-index: 0;
}

.wrap {
  position: relative;
  z-index: 10;
  max-width: 980px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(90px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 6px 0 24px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 52px; height: 52px; border-radius: 12px; overflow: hidden;
  background: transparent;
  border: none;
  box-shadow: none;
}
.logo img { 
  width: 100%; height: 100%; object-fit: contain; display: block; 
  filter: drop-shadow(0 4px 10px rgba(0, 229, 255, 0.4));
}
.title-ar {
  margin: 0; font-size: 20px; font-weight: 900; color: var(--cyan);
  text-shadow: 0 0 20px rgba(0, 229, 255, 0.3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
small { display: block; color: var(--muted); font-weight: 700; margin-top: 2px; font-size: 13px; text-shadow: none; }

.actions { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.btn {
  appearance: none; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #fff; padding: 10px 14px; border-radius: 14px; font-weight: 800; font-size: 14px;
  cursor: pointer; transition: all 0.2s; touch-action: manipulation;
  min-height: 44px; -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.15); }

/* Accent / Good / Bad Buttons */
.btn-accent {
  border-color: rgba(87, 212, 255, 0.5); 
  background: linear-gradient(135deg, rgba(87, 212, 255, 0.2), rgba(0, 229, 255, 0.05));
  box-shadow: 0 5px 15px rgba(0, 229, 255, 0.15);
}
.btn-danger {
  border-color: rgba(251, 113, 133, 0.5); 
  background: linear-gradient(135deg, rgba(251, 113, 133, 0.2), rgba(251, 113, 133, 0.05));
  box-shadow: 0 5px 15px rgba(251, 113, 133, 0.15);
  color: #fff;
}
.btn-success-flash {
  border-color: rgba(52, 211, 153, 0.7) !important;
  background: rgba(52, 211, 153, 0.18) !important;
}

/* WhatsApp Button */
.btn-wa {
  border-color: var(--waLine);
  background: var(--waBg);
  color: #fff;
}

/* Large Round Buttons */
.btn-lg { padding: 14px 16px; border-radius: 16px; font-size: 15px; }
.actionRow { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 16px; }
.actionRow .btn { flex: 1; max-width: 340px; }

/* Main Cards */
.card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  margin-bottom: 24px;
}
.hd {
  padding: 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(0, 0, 0, 0.3); flex-wrap: wrap;
}
.hd strong { font-size: 16px; font-weight: 900; }
.bd { padding: 16px; }
.muted { color: var(--muted); font-size: 13px; font-weight: 700; }
.hr { height: 1px; background: var(--line); margin: 16px 0; }

.grid { display: grid; gap: 16px; }
@media (min-width: 860px) { .grid { grid-template-columns: 1fr 1fr; align-items: start; } }

/* Inputs and Selects */
.input, select {
  width: 100%; border: 1px solid rgba(87, 212, 255, 0.2);
  background: rgba(0, 0, 0, 0.5); color: #fff; border-radius: 14px;
  padding: 12px 16px; outline: none; font-weight: 800; font-size: 16px;
  transition: all 0.2s;
}
.input:focus, select:focus {
  border-color: rgba(87, 212, 255, 0.6);
  box-shadow: 0 0 10px rgba(87, 212, 255, 0.15);
}

/* Custom Select Dropdown UI */
select {
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" xmlns="http://www.w3.org/2000/svg"><path d="M6 9l6 6 6-6"/></svg>');
  background-repeat: no-repeat;
  background-position: left 12px center;
  background-size: 16px;
  padding-left: 36px; /* give room for the chevron on the left in RTL */
  cursor: pointer;
}

label { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 8px; font-weight: 900; }

/* Round Tabs */
.roundTabs { display: flex; gap: 8px; overflow: auto; padding-bottom: 6px; scrollbar-width: none; }
.roundTabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; padding: 10px 14px; border-radius: 14px; border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02); color: var(--muted); font-weight: 900;
  cursor: pointer; user-select: none; min-height: 44px; -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}
.tab.active {
  color: #fff; border-bottom: 2px solid var(--accent); background: rgba(87, 212, 255, 0.1);
  text-shadow: 0 0 10px rgba(87, 212, 255, 0.4);
}
.tab.locked { opacity: 0.3; cursor: not-allowed; }

/* Player Grid Tiles */
.playersGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 560px) { .playersGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.pTile {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 18px; padding: 16px 12px; text-align: center;
  font-weight: 900; font-size: 15px; user-select: none; cursor: pointer; min-height: 56px;
  -webkit-tap-highlight-color: transparent; transition: all 0.2s;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.pTile:active { transform: scale(0.96); }
.pTile small { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); font-weight: 800; }

/* Semantic Tile States */
.pTile.hand { border-color: rgba(87, 212, 255, 0.5); background: rgba(87, 212, 255, 0.15); box-shadow: 0 0 15px rgba(87, 212, 255, 0.15); }
.pTile.finish { border-color: rgba(52, 211, 153, 0.5); background: rgba(52, 211, 153, 0.15); box-shadow: 0 0 15px rgba(52, 211, 153, 0.1); }
.pTile.drop { border-color: var(--purpleLine); background: var(--purpleBg); box-shadow: 0 0 15px rgba(168, 85, 247, 0.15); }
.pTile.victim { border-color: rgba(251, 113, 133, 0.5); background: rgba(251, 113, 133, 0.15); box-shadow: 0 0 15px rgba(251, 113, 133, 0.15); }

/* Bottom Sheet */
.sheetBack { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(8px); display: none; z-index: 100; }
.sheet { position: fixed; left: 0; right: 0; bottom: -520px; z-index: 101; transition: bottom 0.3s cubic-bezier(0.1, 0.7, 0.1, 1); padding: 0; }
.sheet.show { bottom: 0; }
.sheetBack.show { display: block; }
.sheetCard {
  max-width: 980px; margin: 0 auto;
  border-top: 1px solid rgba(255,255,255,0.1); border-left: 1px solid rgba(255,255,255,0.05); border-right: 1px solid rgba(255,255,255,0.05);
  border-radius: 28px 28px 0 0;
  background: rgba(10, 15, 25, 0.85);
  backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheetHd { padding: 18px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheetHd strong { font-size: 18px; font-weight: 900; }
.sheetBd { padding: 24px; }
.sheetActions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media(min-width:560px) { .sheetActions { grid-template-columns: repeat(3, 1fr); } }

/* Action Chips */
.chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 16px; padding: 14px; text-align: center;
  font-weight: 900; font-size: 14px; cursor: pointer; min-height: 48px;
  -webkit-tap-highlight-color: transparent; user-select: none; transition: all 0.2s;
}
.chip:active { transform: scale(0.96); }
.chip:hover { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.15); }
.chip.warn { border-color: rgba(251, 113, 133, 0.4); background: rgba(251, 113, 133, 0.1); color: #fb7185; }
.chip.good { border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.1); color: #34d399; }
.chip.active {
  border-color: rgba(87, 212, 255, 0.7);
  background: rgba(87, 212, 255, 0.2);
  color: #fff;
  box-shadow: 0 0 15px rgba(87, 212, 255, 0.2);
}

.lockBanner {
  display: none; margin-top: 16px; padding: 14px; border-radius: 16px;
  border: 1px solid rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.15);
  font-weight: 900; text-align: center; font-size: 14px;
}
.lockBanner.show { display: block; }

/* Score Table */
.table { width: 100%; border-collapse: separate; border-spacing: 0; border: 1px solid var(--line); border-radius: 16px; background: rgba(0, 0, 0, 0.2); overflow: hidden; }
.table th, .table td { padding: 14px 12px; border-bottom: 1px solid var(--line); font-size: 14px; text-align: right; white-space: nowrap; font-weight: 800; }
.table th { color: var(--muted); font-size: 13px; background: rgba(0, 0, 0, 0.4); position: sticky; top: 0; z-index: 1; }
.table tr:nth-child(even) td { background: rgba(255, 255, 255, 0.015); }
.table tr:last-child td { border-bottom: 0; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--bad); font-weight: 900; }
.neg { color: var(--good); font-weight: 900; }

/* Purple Nazool Dot */
.purpleDot {
  display: inline-block;
  width: 10px; height: 10px; border-radius: 999px;
  background: var(--purple);
  margin-left: 8px; vertical-align: middle;
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.6);
}

.mini { font-size: 13px; color: var(--muted); line-height: 1.6; }

/* A separate hold target in the score table keeps round-entry controls intact. */
.hand-score-name{display:inline-flex;align-items:center;gap:8px}
.hand-score-gap{display:inline-grid;place-items:center;width:28px;height:28px;min-height:28px;padding:0;border:0;background:transparent;color:var(--accent,#dcc48f);font:600 11px/1 Arial,sans-serif;touch-action:pan-y;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;cursor:help;flex-shrink:0}
.hand-score-gap::before{content:'';position:absolute;width:15px;height:15px;border:1px solid currentColor;border-radius:50%;opacity:.65;pointer-events:none}
.hand-score-gap:hover{color:var(--text)}
.hand-score-gap:focus-visible{outline:1px solid var(--accent,#dcc48f);outline-offset:1px;border-radius:50%}
.hand-score-gap-popup{position:fixed;z-index:1200;width:max-content;max-width:min(250px,calc(100vw - 24px));padding:12px 16px;background:#19352e;border:1px solid #dcc48f55;border-radius:12px;box-shadow:0 10px 28px #0005;direction:rtl;pointer-events:none;font:400 13px/1.8 'IBM Plex Sans Arabic',Tahoma,sans-serif;color:#f3f0e5}
.hand-score-gap-popup strong{display:block;font-size:11px;font-weight:500;color:#dcc48f;margin-bottom:2px}
