/* «لا تطيّح السالفة» — stacking game overlay. All selectors are prefixed with .ag- */
.ag-root {
  --ag-blue: #1d63d8;
  --ag-deep: #0b3a9a;
  --ag-navy: #0a3066;
  --ag-cyan: #12c0e0;
  --ag-green: #2bd16f;
  --ag-white: #ffffff;
  --ag-head: "Noto Kufi Arabic", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --ag-body: "IBM Plex Sans Arabic", "Noto Kufi Arabic", system-ui, sans-serif;
  position: fixed;
  inset: 0;
  z-index: 9000;
  overflow: hidden;
  direction: rtl;
  background: linear-gradient(180deg, var(--ag-blue), var(--ag-deep));
  color: var(--ag-white);
  font-family: var(--ag-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: contain;
  opacity: 0;
  transition: opacity .28s ease;
}
.ag-root.ag-in { opacity: 1; }
.ag-root *, .ag-root *::before, .ag-root *::after { box-sizing: border-box; }
.ag-root img { max-width: 100%; display: block; -webkit-user-drag: none; }
.ag-root :where(button) {
  font: inherit;
  color: inherit;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.ag-root button:focus-visible { outline: 3px solid var(--ag-cyan); outline-offset: 3px; }
.ag-root :where(h2, h3, p, ol, ul, li) { margin: 0; padding: 0; }
.ag-root :where(ol, ul) { list-style: none; }

.ag-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------------------------------------------------------------- HUD */
.ag-hud {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  pointer-events: none;
  transition: opacity .3s ease;
}
.ag-hud.ag-dim .ag-hud-mid { opacity: 0; }
.ag-hud-brand { justify-self: start; padding-top: 6px; }
.ag-hud-brand img { width: auto; height: 26px; filter: drop-shadow(0 2px 6px rgba(4, 20, 60, .35)); }
.ag-hud-btns { justify-self: end; display: flex; gap: 8px; pointer-events: auto; }
.ag-icon {
  width: 42px;
  flex: none;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(10, 48, 102, .42);
  border: 1px solid rgba(255, 255, 255, .22);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 16px rgba(4, 20, 60, .25);
  transition: transform .15s ease, background .15s ease;
}
.ag-icon svg { width: 20px; height: 20px; }
.ag-icon:hover { background: rgba(10, 48, 102, .62); }
.ag-icon:active { transform: scale(.92); }
.ag-mute[aria-pressed="true"] { color: var(--ag-cyan); }

.ag-hud-mid { text-align: center; transition: opacity .3s ease; min-width: 150px; }
.ag-counter {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  font-family: var(--ag-head);
  line-height: 1.1;
  text-shadow: 0 3px 14px rgba(4, 20, 60, .45);
}
.ag-count { font-size: 38px; font-weight: 900; font-variant-numeric: tabular-nums; }
.ag-unit { font-size: 17px; font-weight: 800; opacity: .92; }
.ag-meters {
  font-size: 13px;
  font-weight: 700;
  opacity: .85;
  margin-top: 1px;
  letter-spacing: .2px;
}
.ag-progress {
  width: 150px;
  height: 6px;
  margin: 7px auto 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, .2);
  overflow: hidden;
}
.ag-progress-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(270deg, var(--ag-green), var(--ag-cyan));
  transform-origin: right center;
  transform: scaleX(0);
  transition: transform .45s cubic-bezier(.2, .9, .3, 1.2);
}
.ag-progress.ag-pulse { animation: ag-pulse .7s ease; }
@keyframes ag-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(43, 209, 111, 0); } 40% { box-shadow: 0 0 0 6px rgba(43, 209, 111, .35); } }
.ag-progress-label { font-size: 12px; font-weight: 500; opacity: .85; margin-top: 4px; white-space: nowrap; }

.ag-hint {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 4.5vh);
  transform: translate(-50%, 10px);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 99px;
  background: rgba(10, 48, 102, .62);
  border: 1px solid rgba(255, 255, 255, .2);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease, transform .3s ease;
}
.ag-hint.ag-show { opacity: 1; transform: translate(-50%, 0); }
.ag-hint-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ag-cyan);
  box-shadow: 0 0 0 0 rgba(18, 192, 224, .7);
  animation: ag-ping 1.4s ease-out infinite;
}
@keyframes ag-ping { 0% { box-shadow: 0 0 0 0 rgba(18, 192, 224, .7); } 100% { box-shadow: 0 0 0 12px rgba(18, 192, 224, 0); } }

/* ---------------------------------------------------------------- screens */
.ag-screen {
  position: absolute;
  inset: 0;
  display: flex;
  padding: calc(env(safe-area-inset-top, 0px) + 66px) 16px calc(env(safe-area-inset-bottom, 0px) + 18px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: radial-gradient(120% 80% at 50% 30%, rgba(6, 28, 80, .25), rgba(5, 22, 64, .7));
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease, visibility 0s linear .3s;
}
.ag-screen.ag-show { opacity: 1; visibility: visible; transition: opacity .3s ease; }
.ag-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 22px 20px 20px;
  border-radius: 28px;
  text-align: center;
  background: linear-gradient(180deg, rgba(20, 74, 168, .97), rgba(9, 38, 98, .985));
  border: 1px solid rgba(255, 255, 255, .16);
  box-shadow: 0 30px 80px rgba(3, 16, 48, .55), inset 0 1px 0 rgba(255, 255, 255, .2);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  transform: translateY(14px) scale(.98);
  transition: transform .4s cubic-bezier(.2, .9, .3, 1.15);
}
.ag-screen.ag-show .ag-card { transform: none; }

/* start */
.ag-card--start { padding-top: 18px; }
.ag-title-img {
  width: min(46vw, 170px);
  height: auto;
  margin: -4px auto 4px;
  filter: drop-shadow(0 10px 18px rgba(4, 20, 60, .45));
  animation: ag-float 4s ease-in-out infinite;
}
@keyframes ag-float { 0%, 100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(-5px) rotate(1deg); } }
.ag-name {
  font-family: var(--ag-head);
  font-weight: 900;
  font-size: clamp(26px, 7.4vw, 32px);
  line-height: 1.3;
  letter-spacing: -.2px;
}
.ag-tag {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 14px 5px;
  border-radius: 99px;
  background: var(--ag-green);
  color: #06341b;
  font-family: var(--ag-head);
  font-weight: 800;
  font-size: 14px;
  transform: rotate(-1.5deg);
  box-shadow: 0 4px 0 rgba(6, 52, 27, .35);
}
.ag-how {
  margin: 18px 0 18px;
  display: grid;
  gap: 8px;
  text-align: right;
}
.ag-how li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .1);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
}
.ag-how i {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-style: normal;
  font-family: var(--ag-head);
  font-weight: 800;
  font-size: 13px;
  background: var(--ag-cyan);
  color: var(--ag-navy);
}

/* buttons */
.ag-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border-radius: 999px;
  font-family: var(--ag-head);
  font-weight: 800;
  font-size: 16px;
  line-height: 1.3;
  text-align: center;
  transition: transform .12s ease, box-shadow .12s ease, filter .15s ease;
}
.ag-btn:hover { filter: brightness(1.04); }
.ag-btn--primary {
  background: var(--ag-white);
  color: var(--ag-navy);
  box-shadow: 0 6px 0 #082652, 0 16px 30px rgba(3, 16, 48, .45);
}
.ag-btn--primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #082652, 0 8px 16px rgba(3, 16, 48, .4); }
.ag-btn--xl { min-height: 62px; font-size: 24px; font-weight: 900; }
.ag-btn--cyan {
  background: var(--ag-cyan);
  color: var(--ag-navy);
  box-shadow: 0 5px 0 #0a7d93, 0 12px 24px rgba(3, 16, 48, .35);
}
.ag-btn--green {
  background: var(--ag-green);
  color: #06341b;
  box-shadow: 0 5px 0 #168a45, 0 12px 24px rgba(3, 16, 48, .35);
}
.ag-btn--cyan:active, .ag-btn--green:active { transform: translateY(3px); }

/* reward ladder */
.ag-ladder {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  margin-top: 22px;
}
.ag-ladder li {
  padding: 9px 4px 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .07);
  border: 1px dashed rgba(255, 255, 255, .28);
  display: grid;
  gap: 1px;
}
.ag-ladder b { font-family: var(--ag-head); font-weight: 800; font-size: 14px; }
.ag-ladder span { font-size: 12px; opacity: .85; line-height: 1.35; }
.ag-ladder .ag-ladder-top { border-color: var(--ag-green); background: rgba(43, 209, 111, .14); }
.ag-ladder--mini { margin-top: 10px; }

/* game over */
.ag-card--over { padding-top: 20px; }
.ag-kicker {
  display: inline-block;
  padding: 4px 22px 7px;
  border-radius: 99px;
  background: var(--ag-white);
  color: var(--ag-navy);
  font-family: var(--ag-head);
  font-weight: 900;
  font-size: 17px;
  transform: rotate(-2deg);
  box-shadow: 0 5px 0 rgba(8, 38, 82, .7);
}
.ag-kicker--best { background: var(--ag-green); color: #06341b; box-shadow: 0 5px 0 #168a45; }
.ag-final {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  font-family: var(--ag-head);
  line-height: 1.1;
}
.ag-final-n { font-size: 64px; font-weight: 900; text-shadow: 0 6px 20px rgba(4, 20, 60, .45); }
.ag-final-u { font-size: 22px; font-weight: 800; opacity: .9; }
.ag-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 12px;
}
.ag-stats div {
  padding: 7px 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .08);
  display: grid;
}
.ag-stats span { font-size: 11.5px; opacity: .78; }
.ag-stats b { font-family: var(--ag-head); font-size: 16px; font-weight: 800; }

.ag-reward {
  margin-top: 12px;
  padding: 14px 14px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, .96);
  color: var(--ag-navy);
  box-shadow: 0 10px 26px rgba(3, 16, 48, .3);
}
.ag-reward-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  font-family: var(--ag-head);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.4;
}
.ag-badge {
  padding: 1px 10px 3px;
  border-radius: 99px;
  background: var(--ag-green);
  color: #06341b;
  font-size: 12px;
  font-weight: 800;
}
.ag-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 6px 6px 6px;
  padding-inline-start: 16px;
  border-radius: 14px;
  border: 2px dashed var(--ag-cyan);
  background: #eefbff;
}
.ag-code code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--ag-navy);
  -webkit-user-select: all;
  user-select: all;
}
.ag-copy {
  flex: none;
  padding: 7px 14px;
  border-radius: 10px;
  background: var(--ag-navy);
  color: #fff;
  font-family: var(--ag-head);
  font-size: 13px;
  font-weight: 800;
}
.ag-copy.ag-copied { background: var(--ag-green); color: #06341b; }
.ag-note { margin-top: 8px; font-size: 11.5px; line-height: 1.5; color: #45608f; }
.ag-reward .ag-ladder li { background: #f1f6ff; border-color: #b9cdf0; color: var(--ag-navy); }
.ag-reward .ag-ladder .ag-ladder-top { background: #e6faef; border-color: var(--ag-green); }

.ag-rank { margin-top: 14px; text-align: center; font-family: var(--ag-head); font-weight: 800; font-size: 16px; line-height: 1.6; color: #fff; }
.ag-actions { display: grid; gap: 14px; margin-top: 18px; }
.ag-actions-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.ag-actions-row .ag-share { padding: 8px 20px; white-space: nowrap; }
.ag-branch { min-height: 50px; }

@media (max-width: 359px) {
  .ag-actions-row .ag-btn { font-size: 14px; padding: 8px 12px; }
  .ag-hud-brand img { height: 20px; }
}
/* Short phones: keep the result card on one screen so the replay and branch buttons stay in view. */
@media (max-height: 900px) {
  .ag-actions { gap: 10px; margin-top: 12px; }
  .ag-card--over { padding-top: 14px; }
  .ag-actions-row .ag-btn { white-space: nowrap; font-size: 15px; padding-inline: 12px; }
}
@media (max-height: 700px) {
  .ag-reward .ag-ladder { display: none; } /* the ladder is on the start screen; keep the result card to one screen */
  .ag-stats { margin-top: 8px; }
}
@media (max-height: 700px) {
  .ag-title-img { width: min(34vw, 120px); }
  .ag-how { margin: 12px 0 14px; }
  .ag-how li { padding: 7px 10px; font-size: 14px; }
  .ag-ladder { margin-top: 14px; }
  .ag-final-n { font-size: 52px; }
}
@media (min-width: 900px) {
  .ag-hud-brand img { height: 30px; }
}
@media (prefers-reduced-motion: reduce) {
  .ag-root, .ag-root * { animation: none !important; transition-duration: .01ms !important; }
}

/* daily tries */
.ag-tries { margin: 12px 0 0; font-size: 14px; font-weight: 700; color: rgba(255, 255, 255, .85); }
.ag-tries--over { margin-top: 10px; text-align: center; }
.ag-tries b { color: var(--ag-green); }
.ag-tries--out { color: #ffd23f; }
.ag-btn--off { opacity: .55; }
.ag-tries.ag-pulse { animation: ag-tries-pulse .6s ease; }
@keyframes ag-tries-pulse { 30% { transform: scale(1.08); } }

/* sign-up before the first game */
.ag-hello { margin: -4px 0 12px; font-size: 15px; font-weight: 700; }
.ag-notme { margin-inline-start: 6px; font: inherit; font-size: 13px; font-weight: 600; color: var(--ag-cyan); text-decoration: underline; text-underline-offset: 3px; background: none; border: 0; padding: 4px 2px; cursor: pointer; }
.ag-card--reg { text-align: right; }
.ag-reg-img { display: block; width: min(30vw, 104px); height: auto; margin: -2px auto 2px; filter: drop-shadow(0 8px 14px rgba(4, 20, 60, .45)); }
.ag-reg-h { font-family: var(--ag-head); font-weight: 900; font-size: clamp(24px, 6.6vw, 28px); line-height: 1.3; text-align: center; }
.ag-reg-p { margin: 6px 0 16px; font-size: 14.5px; line-height: 1.7; color: rgba(255, 255, 255, .86); text-align: center; }
.ag-field { display: block; margin-bottom: 12px; }
.ag-field span { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 700; }
.ag-field input {
  display: block; width: 100%; height: 54px; padding: 0 16px;
  border-radius: 16px; border: 1.5px solid rgba(255, 255, 255, .22);
  background: rgba(255, 255, 255, .1); color: #fff;
  font: inherit; font-size: 17px; font-weight: 600; /* 16px+ keeps iOS from zooming in */
  transition: border-color .15s ease, background .15s ease;
}
.ag-field .ag-phone { display: flex; gap: 8px; margin: 0; }
.ag-phone b { flex: none; display: grid; place-items: center; height: 54px; padding: 0 14px; border-radius: 16px; border: 1.5px solid rgba(255, 255, 255, .22); background: rgba(255, 255, 255, .16); font-size: 17px; font-weight: 700; letter-spacing: .5px; }
.ag-phone input { flex: 1; min-width: 0; }
.ag-field input[dir="ltr"] { text-align: left; letter-spacing: .5px; }
.ag-field input::placeholder { color: rgba(255, 255, 255, .42); font-weight: 500; }
.ag-field input:focus { outline: none; border-color: var(--ag-cyan); background: rgba(255, 255, 255, .16); }
.ag-check { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; padding: 4px 0; font-size: 13.5px; line-height: 1.6; color: rgba(255, 255, 255, .9); cursor: pointer; }
.ag-check input { flex: none; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--ag-green); cursor: pointer; }
.ag-check a { color: #fff; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.ag-reg-err { min-height: 20px; margin: 0 0 8px; font-size: 13.5px; font-weight: 700; color: #ffd23f; text-align: center; }
.ag-reg-err:empty { min-height: 0; margin: 0; }
.ag-reg-go:disabled { opacity: .7; }
.ag-reg-fine { margin-top: 12px; font-size: 12px; line-height: 1.6; color: rgba(255, 255, 255, .62); text-align: center; }
@media (max-height: 700px) {
  .ag-reg-img { display: none; }
  .ag-reg-p { margin-bottom: 10px; }
}

/* close button on every popup card */
.ag-card-x {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .22);
  color: #fff;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.ag-card-x svg { width: 18px; height: 18px; }
.ag-card-x:hover { background: rgba(255, 255, 255, .24); }
.ag-card-x:active { transform: scale(.9); }
/* the corner button now does this job while a popup is up */
.ag-hud.ag-popup .ag-close { visibility: hidden; }
