:root {
  --ink: #141414;
  --ink-2: #1d1d1d;
  --steel: #2b2b2b;
  --steel-hi: #3a3a3a;
  --gold: #F5B200;
  --gold-hi: #FFD24D;
  --gold-lo: #B98500;
  --white: #FFFFFF;
  --mute: #9a9a95;
  --green: #1E9E5A;
  --cell: 44px;
  --gap: 6px;
  --sep: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(245, 178, 0, .14), transparent 60%),
    var(--ink);
  color: var(--white);
  font-family: "Tajawal", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 3px solid var(--gold-hi); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }
#flash { position: fixed; inset: 0; background: var(--gold-hi); opacity: 0; pointer-events: none; z-index: 29; }
#flash.on { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .35; } to { opacity: 0; } }

.screen {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}

/* ---------- Entry ---------- */
#entry { justify-content: center; align-items: center; text-align: center; gap: 10px; }
.entry-logo { width: min(56vw, 220px); height: auto; filter: drop-shadow(0 6px 24px rgba(245, 178, 0, .25)); margin-bottom: 8px; }
.entry-title { font-family: "Cairo", sans-serif; font-weight: 900; font-size: 34px; line-height: 1.1; }
.entry-title .big { display: block; font-size: 120px; line-height: .95; color: var(--gold); text-shadow: 0 6px 0 var(--gold-lo), 0 0 40px rgba(245, 178, 0, .35); }
.entry-sub { color: var(--mute); font-size: 18px; margin-bottom: 18px; }
.code-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.code-label { font-weight: 700; font-size: 15px; color: var(--mute); }
.code-input {
  width: 100%;
  font-family: "Cairo", sans-serif; font-weight: 900; font-size: 44px; letter-spacing: .25em; text-align: center;
  padding: 10px 0 10px .25em;
  background: var(--ink-2); color: var(--gold);
  border: 2px solid var(--steel-hi); border-radius: 16px;
  box-shadow: inset 0 4px 0 rgba(0, 0, 0, .35);
}
.code-input::placeholder { color: var(--steel-hi); }
.code-input:focus { outline: none; border-color: var(--gold); }
.code-input.shake { animation: shake .4s; border-color: #E23B3B; }
.code-error { min-height: 1.3em; color: #ff6b6b; font-weight: 700; font-size: 15px; }
.btn-primary {
  width: 100%;
  padding: 16px; border-radius: 16px;
  font-family: "Cairo", sans-serif; font-weight: 900; font-size: 22px;
  background: var(--gold); color: var(--ink);
  box-shadow: 0 6px 0 var(--gold-lo);
  transition: transform .08s, box-shadow .08s;
}
.btn-primary:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--gold-lo); }
.btn-ghost { margin-top: 6px; padding: 10px 14px; color: var(--mute); font-weight: 700; font-size: 15px; text-decoration: underline; text-underline-offset: 4px; }

/* ---------- Tracker ---------- */
#tracker { gap: 10px; }
.top { display: flex; align-items: center; gap: 10px; flex: none; }
.top-logo { height: 34px; width: auto; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.who-name { font-family: "Cairo", sans-serif; font-weight: 800; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-window { color: var(--mute); font-size: 13px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--ink-2); color: var(--mute); flex: none; }
.icon-btn.on { color: var(--gold); }

.score { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex: none; }
.count-wrap { display: flex; align-items: baseline; font-family: "Cairo", sans-serif; font-weight: 900; line-height: .9; direction: ltr; }
.count { font-size: 76px; color: var(--gold); text-shadow: 0 5px 0 var(--gold-lo); display: inline-block; min-width: 1ch; }
.count.bump { animation: bump .45s cubic-bezier(.2, 1.6, .4, 1); }
.of { font-size: 28px; color: var(--steel-hi); margin-inline-start: 4px; }
.score-side { text-align: end; padding-bottom: 6px; }
.left-visits { font-family: "Cairo", sans-serif; font-weight: 800; font-size: 18px; }
.left-days { color: var(--mute); font-size: 14px; }

.bar { position: relative; height: 10px; border-radius: 99px; background: var(--ink-2); box-shadow: inset 0 2px 0 rgba(0, 0, 0, .4); flex: none; overflow: hidden; }
.bar-fill { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0; background: linear-gradient(90deg, var(--gold), var(--gold-hi)); border-radius: 99px; transition: width .6s cubic-bezier(.2, 1.3, .4, 1); }
[dir="rtl"] .bar-fill { background: linear-gradient(270deg, var(--gold), var(--gold-hi)); }
.notch { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); }

.grid-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.grid { display: flex; flex-direction: column; gap: var(--sep); }
.block { position: relative; display: grid; grid-template-columns: repeat(5, var(--cell)); grid-auto-rows: var(--cell); gap: var(--gap); }
.block-mark {
  position: absolute; inset-inline-end: calc(-1 * var(--gap) - 22px); bottom: -2px;
  font-family: "Cairo", sans-serif; font-weight: 800; font-size: 12px; color: var(--steel-hi);
}
.block-mark.done { color: var(--gold); }

.cell {
  position: relative;
  border-radius: calc(var(--cell) * .2);
  background: var(--ink-2);
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, .45), inset 0 0 0 1px var(--steel);
  display: grid; place-items: center;
  font-family: "Cairo", sans-serif; font-weight: 800; font-size: calc(var(--cell) * .3); line-height: 1;
  color: transparent;
}
.cell.on {
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%);
  box-shadow: 0 calc(var(--cell) * .08) 0 var(--gold-lo), 0 0 14px rgba(245, 178, 0, .25);
  color: rgba(20, 20, 20, .78);
  transform: translateY(calc(var(--cell) * -.04));
}
.cell .dm { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.cell .dm small { font-size: .62em; opacity: .7; }
.cell.next { box-shadow: inset 0 0 0 2px var(--gold); animation: breathe 1.6s ease-in-out infinite; }
.cell.pop { animation: pop .55s cubic-bezier(.2, 1.8, .35, 1); z-index: 2; }
.cell.pop::after {
  content: ""; position: absolute; inset: -6px; border-radius: inherit;
  border: 3px solid var(--gold-hi); animation: ring .6s ease-out forwards;
}
.cell.cascade { animation: cascade .35s cubic-bezier(.2, 1.6, .4, 1) both; }
.cell.latest { box-shadow: 0 calc(var(--cell) * .08) 0 var(--gold-lo), 0 0 0 2px var(--white), 0 0 20px rgba(255, 210, 77, .55); }

.bottom { flex: none; display: flex; flex-direction: column; gap: 8px; }
.today-chip {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; border-radius: 14px;
  background: var(--ink-2); color: var(--mute);
  font-weight: 700; font-size: 16px; text-align: center;
}
.today-chip.done { background: rgba(30, 158, 90, .16); color: #5ee39a; }
.today-chip .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex: none; }
.today-chip:not(.done) .dot { animation: blink 1.4s infinite; }

.demo-bar { display: flex; gap: 8px; }
.btn-scan {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px; border-radius: 14px;
  background: var(--gold); color: var(--ink);
  font-family: "Cairo", sans-serif; font-weight: 900; font-size: 18px;
  box-shadow: 0 5px 0 var(--gold-lo);
  transition: transform .08s, box-shadow .08s;
}
.btn-scan:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--gold-lo); }
.btn-scan:disabled { opacity: .5; }
.btn-reset { padding: 14px 18px; border-radius: 14px; background: var(--ink-2); color: var(--mute); font-weight: 700; }

.toast {
  position: fixed; inset-inline: 16px; top: max(14px, env(safe-area-inset-top)); z-index: 40;
  max-width: 448px; margin: 0 auto;
  padding: 14px 16px; border-radius: 16px;
  background: var(--white); color: var(--ink);
  font-family: "Cairo", sans-serif; font-weight: 900; font-size: 19px; text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
  transform: translateY(-140%); transition: transform .35s cubic-bezier(.2, 1.4, .4, 1);
}
.toast.show { transform: translateY(0); }

.win { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; padding: 24px; background: rgba(10, 10, 10, .78); backdrop-filter: blur(4px); }
.win-card { width: 100%; max-width: 380px; text-align: center; padding: 30px 22px 22px; border-radius: 24px; background: var(--gold); color: var(--ink); box-shadow: 0 10px 0 var(--gold-lo); animation: pop .6s cubic-bezier(.2, 1.8, .35, 1); }
.win-kicker { font-weight: 700; font-size: 18px; }
.win-title { font-family: "Cairo", sans-serif; font-weight: 900; font-size: 46px; line-height: 1.05; margin: 6px 0 10px; }
.win-sub { font-size: 17px; margin-bottom: 20px; }
.win .btn-primary { background: var(--ink); color: var(--gold); box-shadow: 0 6px 0 #000; }

.shake-screen { animation: screenShake .32s; }

@keyframes pop { 0% { transform: scale(.2) rotate(-14deg); } 60% { transform: scale(1.3) rotate(4deg); } 100% { transform: scale(1) translateY(calc(var(--cell) * -.04)); } }
@keyframes cascade { from { transform: scale(.4); opacity: 0; } to { transform: scale(1) translateY(calc(var(--cell) * -.04)); opacity: 1; } }
@keyframes ring { from { opacity: 1; transform: scale(.8); } to { opacity: 0; transform: scale(1.7); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35) rotate(-4deg); } 100% { transform: scale(1); } }
@keyframes breathe { 50% { box-shadow: inset 0 0 0 2px var(--gold), 0 0 16px rgba(245, 178, 0, .45); } }
@keyframes blink { 50% { opacity: .25; } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes screenShake { 25% { transform: translate(-4px, 2px); } 50% { transform: translate(4px, -3px); } 75% { transform: translate(-2px, 3px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
