/* ═══════════════════════════════════════════════════════════════
   Tadamon Cards
   Motifs: the club's vertical kit stripes; the metal of each tier
   (bronze, silver, gold, blue, black, dark gold) as the UI's material;
   a scoreboard-style condensed face for numbers.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --font: "Barlow", ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --display: "Barlow Condensed", "Barlow", ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", sans-serif;

  --gold: #f2c95c;
  --gold-metal: linear-gradient(135deg, #e2c87a, #fae8a8 50%, #e2c87a);
  --card-ratio: 0.7069;                       /* 757 / 1071 */
  --card-radius: 5% / 3.5%;

  --tab-h: 62px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  /* light theme */
  color-scheme: light;
  --bg: #f3f6fe;
  --surface: #ffffff;
  --surface-2: #e8eefc;
  --line: rgba(20, 40, 110, .12);
  --text: #0b1430;
  --muted: #56628a;
  --accent: #1d50df;
  --accent-hover: #1841b8;
  --stripe: rgba(29, 80, 223, .055);
  --halo: rgba(87, 129, 235, .22);
  --overlay: rgba(6, 12, 32, .78);
  --danger: #c22a3a;
  --ok: #17803d;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #070c1c;
  --surface: #0f1834;
  --surface-2: #17224a;
  --line: rgba(150, 175, 255, .15);
  --text: #eef2ff;
  --muted: #94a2cc;
  --accent: #5781eb;
  --accent-hover: #6d92f0;
  --stripe: rgba(87, 129, 235, .075);
  --halo: rgba(29, 80, 223, .38);
  --overlay: rgba(3, 6, 18, .84);
  --danger: #ff6b7a;
  --ok: #55d68a;
}

/* ── base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
html.no-scroll, html.no-scroll body { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 400 16px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

/* kit stripes fading down the page */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 520px at 50% -8%, var(--halo), transparent 70%),
    repeating-linear-gradient(90deg, var(--stripe) 0 32px, transparent 32px 64px);
  -webkit-mask-image: linear-gradient(#000, rgba(0,0,0,.4) 60%, transparent);
  mask-image: linear-gradient(#000, rgba(0,0,0,.4) 60%, transparent);
}

h1, h2, h3, p, dl, dd, dt, ol, ul { margin: 0; padding: 0; }
img { max-width: 100%; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
code { font-family: ui-monospace, Menlo, monospace; font-size: .92em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

/* ── buttons & inputs ─────────────────────────────────────── */
.btn {
  appearance: none; -webkit-appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 50px; padding: 0 22px;
  border: 1px solid transparent; border-radius: 14px;
  font: 600 17px/1 var(--font);
  cursor: pointer;
  transition: transform .12s ease, background-color .2s, box-shadow .2s, opacity .2s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-quiet { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn-google { width: 100%; background: #fff; color: #1f1f1f; border-color: #dadce0; }
.btn-danger { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn-danger { color: #2a0409; }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: var(--danger); }

.btn-text {
  appearance: none; background: none; border: 0; padding: 8px 4px;
  font-weight: 600; color: var(--muted); cursor: pointer;
}
.link {
  appearance: none; background: none; border: 0; padding: 0;
  color: var(--accent); font-weight: 600; cursor: pointer;
}
.link:hover { text-decoration: underline; }

.icon-btn {
  appearance: none; display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: transparent; border: 0; color: var(--text); cursor: pointer;
  transition: background-color .2s;
}
.icon-btn:hover { background: var(--surface-2); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"] {
  appearance: none; -webkit-appearance: none;
  width: 100%; height: 50px; padding: 0 14px;
  font: 400 16px/1 var(--font);                 /* 16px stops iOS zooming into fields */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  transition: border-color .2s, box-shadow .2s;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.form-error { min-height: 22px; margin: -4px 0 10px; font-size: 14px; color: var(--danger); }
.form-error.ok { color: var(--ok); }

/* ── splash ───────────────────────────────────────────────── */
#splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 300; }
#splash > img { width: 84px; animation: breathe 1.6s ease-in-out infinite; }
.setup { max-width: 420px; padding: 24px; text-align: center; }
.setup h1 { font: 700 34px/1.1 var(--display); margin-bottom: 10px; }

@keyframes breathe { 50% { transform: scale(1.08); opacity: .8; } }

/* ═══════════════ auth ═══════════════ */
.auth {
  min-height: 100vh; min-height: 100dvh;
  display: grid; align-items: center;
  padding: calc(var(--safe-t) + 20px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 20px);
}
.auth__hero { display: none; }
.auth__panel { width: 100%; max-width: 400px; margin: 0 auto; }
.auth__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; font: 700 26px/1 var(--display); letter-spacing: .01em; }
.auth__brand img { width: 44px; height: 44px; object-fit: contain; }
.auth h1 { font: 700 44px/1 var(--display); letter-spacing: .005em; margin-bottom: 8px; }
.auth__tagline { color: var(--muted); margin-bottom: 26px; max-width: 34ch; }
.or { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--muted); font-size: 14px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth__links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; margin-top: 18px; font-size: 15px; color: var(--muted); }

@media (min-width: 900px) {
  .auth { grid-template-columns: 1fr 1fr; gap: 48px; max-width: 1080px; margin: 0 auto; }
  .auth__hero { display: grid; place-items: center; }
  .auth__packwrap { width: min(320px, 30vw); animation: floaty 6s ease-in-out infinite; filter: drop-shadow(0 36px 40px rgba(0,0,0,.4)); transform: rotate(-5deg); }
  .auth__panel { margin: 0; }
}

/* ═══════════════ app shell ═══════════════ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  height: calc(56px + var(--safe-t));
  padding: var(--safe-t) calc(var(--safe-r) + 12px) 0 calc(var(--safe-l) + 16px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(16px); backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar__brand { display: flex; align-items: center; gap: 10px; font: 700 23px/1 var(--display); letter-spacing: .01em; margin-right: auto; }
.topbar__brand img { width: 32px; height: 32px; object-fit: contain; }
.topbar__nav { display: none; gap: 4px; }
.topbar__nav a { padding: 8px 14px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.topbar__nav a:hover { color: var(--text); }
.topbar__nav a.active { color: var(--text); background: var(--surface-2); }
#theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] #theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] #theme-toggle .i-moon { display: none; }

.views {
  max-width: 1040px; margin: 0 auto;
  padding: 22px calc(var(--safe-r) + 18px) calc(var(--tab-h) + var(--safe-b) + 36px) calc(var(--safe-l) + 18px);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(18px); backdrop-filter: saturate(1.4) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabbar a.active { color: var(--accent); }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .topbar__nav { display: flex; position: absolute; left: 50%; transform: translateX(-50%); }
  .views { padding-bottom: 60px; padding-top: 34px; }
}

/* ═══════════════ home ═══════════════ */
.home { display: grid; gap: 6px; grid-template-areas: "clock" "pack" "actions"; justify-items: center; text-align: center; }
.home__clock { grid-area: clock; width: 100%; }
.home__pack { grid-area: pack; position: relative; display: grid; place-items: center; width: 100%; padding: 10px 0 26px; }
.home__actions { grid-area: actions; width: 100%; max-width: 440px; display: grid; gap: 26px; justify-items: center; }

.clock-label { color: var(--muted); font-weight: 500; }
.clock {
  font: 700 clamp(68px, 21vw, 112px)/.95 var(--display);
  letter-spacing: .01em; font-variant-numeric: tabular-nums;
  margin: 2px 0 12px;
}
.clock-bar { width: min(280px, 70%); height: 4px; margin: 0 auto; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.clock-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .6s linear; }
.is-ready .clock { color: var(--text); background: var(--gold-metal); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
:root[data-theme="light"] .is-ready .clock { background: linear-gradient(135deg, #b8912a, #d9b04a 50%, #b8912a); -webkit-background-clip: text; background-clip: text; }
.is-ready .clock-bar i { background: var(--gold-metal); }

.pack-glow {
  position: absolute; width: min(420px, 90vw); aspect-ratio: 1; top: 50%; left: 50%;
  transform: translate(-50%, -52%); border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, rgba(242, 201, 92, .55), transparent 72%);
  opacity: 0; transition: opacity .6s;
}
.is-ready .pack-glow { opacity: 1; animation: glowPulse 2.6s ease-in-out infinite; }

.pack-float { animation: floaty 5.5s ease-in-out infinite; }
.pack {
  appearance: none; -webkit-appearance: none; display: block; position: relative;
  padding: 0; margin: 0; border: 0; background: transparent; cursor: pointer;
  width: min(60vw, 290px, 28dvh);
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform .18s ease-out;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
  filter: drop-shadow(0 28px 30px rgba(0, 0, 0, .38));
}
.pack img { display: block; width: 100%; height: auto; pointer-events: none; transition: filter .5s; -webkit-user-drag: none; }
.is-locked .pack img { filter: grayscale(.6) brightness(.7); }
.pack-shine {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: linear-gradient(105deg, transparent 32%, rgba(255,255,255,.7) 50%, transparent 68%);
  background-size: 260% 100%; background-position: var(--sx, 50%) 0;
  -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: center; mask-position: center;
  transition: opacity .3s;
}
.is-ready .pack:hover .pack-shine, .is-ready .pack:focus-visible .pack-shine { opacity: .85; }
.is-locked .pack { cursor: default; }

.btn-open {
  width: 100%; height: 60px; font: 700 23px/1 var(--display); letter-spacing: .03em;
  background: var(--surface-2); color: var(--muted); border-color: var(--line);
}
.btn-open .i-lock { flex: none; }
.is-ready .btn-open { background: var(--gold-metal); color: #3a2f08; border-color: transparent; box-shadow: 0 12px 30px -10px rgba(242, 201, 92, .75); animation: readyPulse 2.6s ease-in-out infinite; }
.is-ready .btn-open .i-lock { display: none; }
.is-busy .btn-open { opacity: .7; animation: none; }

.ledger { display: flex; justify-content: center; gap: 30px; }
.ledger dd { font: 700 38px/1 var(--display); font-variant-numeric: tabular-nums; }
.ledger dt { font-size: 14px; color: var(--muted); margin-top: 2px; }

.tiers { width: 100%; display: grid; gap: 14px; text-align: left; }
.tier-row {
  display: grid; grid-template-columns: 12px 1fr auto; column-gap: 12px; row-gap: 6px; align-items: center;
  padding: 2px 0;
}
.tier-row__sw { grid-row: 1; width: 12px; height: 17px; border-radius: 3px; background: linear-gradient(135deg, var(--ta), var(--tb) 50%, var(--ta)); box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset; }
.tier-row__name { font-weight: 600; }
.tier-row__n { font: 500 15px/1 var(--font); color: var(--muted); font-variant-numeric: tabular-nums; }
.tier-row__n b { color: var(--text); font-weight: 600; }
.tier-row__bar { grid-column: 2 / -1; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.tier-row__bar i { display: block; height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--ta), var(--tb)); min-width: 0; transition: width .6s; }
:root[data-theme="dark"] .tier-row__bar i, .tier-row__bar i { box-shadow: 0 0 0 1px rgba(255,255,255,.1) inset; }

@media (min-width: 900px) {
  .home { grid-template-columns: 1fr 1fr; grid-template-areas: "pack clock" "pack actions"; align-items: start; justify-items: stretch; text-align: left; column-gap: 40px; padding-top: 6px; }
  .home__pack { grid-row: 1 / span 2; align-self: center; }
  .home__clock { align-self: end; padding-top: 10px; }
  .clock { font-size: clamp(90px, 9vw, 128px); }
  .clock-bar { margin: 0; width: 100%; max-width: 440px; }
  .home__actions { justify-items: stretch; align-self: start; padding-top: 10px; }
  .pack { width: min(44vw, 340px, 56dvh); }
  .ledger { justify-content: flex-start; }
}

/* ═══════════════ pages: shared ═══════════════ */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.page-head h1 { font: 700 44px/1 var(--display); letter-spacing: .005em; }
.page-head__count { font: 500 22px/1 var(--display); color: var(--muted); }
.page-head__count b { font: 700 44px/1 var(--display); color: var(--text); font-variant-numeric: tabular-nums; }
.page-sub { color: var(--muted); margin-bottom: 18px; }

/* ═══════════════ collection ═══════════════ */
.chips {
  display: flex; gap: 8px; margin: 14px -18px 4px; padding: 4px 18px 10px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: 600 15px/1 var(--font); cursor: pointer; white-space: nowrap;
  transition: background-color .2s, color .2s, border-color .2s;
}
.chip small { font: 500 13px/1 var(--font); color: var(--muted); font-variant-numeric: tabular-nums; }
.chip__sw { width: 10px; height: 14px; border-radius: 2px; background: linear-gradient(135deg, var(--ta), var(--tb) 50%, var(--ta)); box-shadow: 0 0 0 1px rgba(255,255,255,.14) inset; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.on small { color: inherit; opacity: .7; }

.tier-sec { margin-top: 26px; }
.tier-sec__head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.tier-sec__head p { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.tier-sec__head p b { color: var(--text); }
.tier-flag {
  display: inline-flex; align-items: center; height: 34px; padding: 0 22px 0 14px;
  font: 700 20px/1 var(--display); letter-spacing: .02em;
  color: var(--ink);
  background: linear-gradient(135deg, var(--ta), var(--tb) 50%, var(--ta));
  clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 50%, 100% 100%, 0 100%);
}

.grid { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(5, 1fr); gap: 12px; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(7, 1fr); gap: 14px; } }

.tile {
  position: relative; display: block; width: 100%; padding: 0; margin: 0; border: 0;
  aspect-ratio: 757 / 1071; border-radius: var(--card-radius); overflow: hidden;
  background: var(--surface-2); cursor: pointer; content-visibility: auto; contain-intrinsic-size: auto 150px;
  transition: transform .18s ease, box-shadow .18s ease;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; }
button.tile:hover { transform: translateY(-3px); box-shadow: 0 14px 24px -10px rgba(0,0,0,.5); }
button.tile:active { transform: scale(.97); }
.tile__x {
  position: absolute; top: 6px; right: 6px; min-width: 26px; padding: 3px 7px; border-radius: 999px;
  font: 700 14px/1 var(--display); text-align: center; color: #fff; background: rgba(6, 12, 32, .82);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.tile--locked { cursor: default; background: linear-gradient(135deg, var(--ta), var(--tb) 50%, var(--ta)); }
.tile--locked::before { content: ""; position: absolute; inset: 0; background: rgba(5, 9, 24, .58); }
.tile__q { position: absolute; inset: 0; display: grid; place-items: center; font: 700 clamp(40px, 11vw, 64px)/1 var(--display); color: rgba(255,255,255,.88); }
.tile__no { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font: 600 13px/1 var(--display); letter-spacing: .06em; color: rgba(255,255,255,.55); }

/* ═══════════════ leaderboard ═══════════════ */
.lb-me { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.lb-me:empty { display: none; }
.lb-me__rank { font: 700 54px/1 var(--display); color: var(--accent); min-width: 2ch; }
.lb-me p { color: var(--muted); font-size: 15px; }
.lb { list-style: none; border-top: 1px solid var(--line); }
.lb li {
  display: grid; grid-template-columns: 38px 42px 1fr auto; align-items: center; gap: 12px;
  padding: 12px 8px; border-bottom: 1px solid var(--line);
}
.lb li.me { background: var(--surface-2); border-radius: 12px; border-bottom-color: transparent; }
.lb__empty { display: block !important; padding: 28px 8px !important; color: var(--muted); text-align: center; }
.lb__rank { font: 700 26px/1 var(--display); text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb__rank--medal {
  display: grid; place-items: center; width: 34px; height: 34px; margin: 0 auto; border-radius: 50%;
  font-size: 21px; color: var(--ink); background: linear-gradient(135deg, var(--ta), var(--tb) 50%, var(--ta));
  box-shadow: 0 2px 8px -2px rgba(0,0,0,.4);
}
.lb__who { min-width: 0; display: grid; gap: 6px; }
.lb__who b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb__bar { display: block; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.lb li.me .lb__bar { background: var(--bg); }
.lb__bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.lb__score { font: 700 26px/1 var(--display); font-variant-numeric: tabular-nums; }
.lb__score small { font: 500 15px/1 var(--display); color: var(--muted); margin-left: 2px; }

.avatar { position: relative; display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; overflow: hidden; background: var(--surface-2); flex: none; }
.avatar b { font: 700 16px/1 var(--display); color: var(--muted); }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar--xl { width: 76px; height: 76px; }
.avatar--xl b { font-size: 28px; }

#lb-refresh.spin svg { animation: spin .9s linear infinite; }

/* ═══════════════ profile ═══════════════ */
.profile { max-width: 560px; }
.profile__head { display: flex; align-items: center; gap: 18px; margin-bottom: 8px; }
.profile__head h1 { font: 700 36px/1.05 var(--display); overflow-wrap: anywhere; }
.group { padding: 22px 0; border-bottom: 1px solid var(--line); }
.group h2 { font: 700 22px/1.1 var(--display); letter-spacing: .01em; margin-bottom: 12px; }
.group p { color: var(--muted); }
.group .hint { font-size: 14px; margin-top: 8px; }
.group--danger { border-bottom: 0; }
.group--danger p { margin-bottom: 14px; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { flex: 1; min-width: 0; }
.seg { display: inline-flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--surface-2); }
.seg button { appearance: none; border: 0; background: transparent; height: 40px; padding: 0 20px; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.18); }

/* ═══════════════ overlays ═══════════════ */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  opacity: 0; transition: opacity .22s ease;
  overscroll-behavior: contain;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.overlay.open { opacity: 1; }

/* ── the 3D card ───────────────────────────────────────────── */
.c3d {
  position: relative; width: var(--cw, 100%); aspect-ratio: 757 / 1071;
  perspective: 1200px; -webkit-perspective: 1200px;
  touch-action: none; cursor: grab; outline: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.c3d.is-drag { cursor: grabbing; }
.c3d:focus-visible { outline: 3px solid var(--accent); outline-offset: 6px; border-radius: 8px; }

.c3d__inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d; -webkit-transform-style: preserve-3d;
  will-change: transform;
  transform: translate3d(0, 0, 0); 
  --thick: 4px; /* 👈 Set card thickness here */
}

.c3d__face {
  position: absolute; inset: 0; overflow: hidden; border-radius: var(--card-radius);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: #1b2244;
}

/* Push outer faces to the edge boundaries */
.c3d__front { transform: translateZ(var(--thick)); }
.c3d__back { transform: rotateY(180deg) translateZ(var(--thick)); }

/* 🚀 HIGH PERFORMANCE ULTRA-LEAN EDGE COMPONENT */
.c3d__face, 
.c3d__edge, 
.c3d__edge::before, 
.c3d__edge::after {
  /* 🚫 PREVENT FLICKER & REPAINTS */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  position: absolute; inset: 0;
  border-radius: var(--card-radius);
  background: #0005a0; /* Core interior dark paper color */
  transform-style: preserve-3d;
  pointer-events: none;
}

/* Draw 3 distinct core slices to simulate depth efficiently */
.c3d__edge { transform: translateZ(0px); }
.c3d__edge::before { content: ""; transform: translateZ(calc(var(--thick) * -0.5)); background: #0005a0; }
.c3d__edge::after { content: ""; transform: translateZ(calc(var(--thick) * 0.5)); background: #0005a0; }

.c3d__face img { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; -webkit-user-drag: none; }
.c3d__glare, .c3d__sheen { position: absolute; inset: 0; pointer-events: none; }
.c3d__glare {
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 50%), rgba(255,255,255,.55), rgba(255,255,255,0) 58%);
  opacity: var(--go, .12);
}
.c3d__sheen {
  background: linear-gradient(112deg, transparent 30%, rgba(255,255,255,.22) 44%, rgba(255,255,255,.04) 52%, transparent 66%);
  background-size: 260% 100%; background-position: var(--sx, 50%) 0; opacity: .9;
}
.c3d__shadow {
  position: absolute; left: 10%; right: 10%; bottom: -3%; height: 8%; border-radius: 50%;
  background: rgba(0,0,0,.6); filter: blur(16px); pointer-events: none;
}
.c3d__glow {
  position: absolute; inset: -12%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, var(--glow, #fff), transparent);
  filter: blur(18px); opacity: 0; transition: opacity .7s ease;
}
.c3d.is-front .c3d__glow { opacity: var(--glow-o, .3); }
.c3d.is-enter { animation: cardIn .55s cubic-bezier(.2, .9, .3, 1.15) both; }


/* ── viewer ────────────────────────────────────────────────── */
.viewer { --cw: min(78vw, 420px); --cw: min(78vw, calc((100dvh - var(--safe-t) - var(--safe-b) - 230px) * .7069), 420px); z-index: 120; }
.viewer__close { position: absolute; top: calc(var(--safe-t) + 10px); right: calc(var(--safe-r) + 10px); z-index: 2; color: #fff; background: rgba(255,255,255,.12); }
.viewer__close:hover { background: rgba(255,255,255,.22); }
.viewer__stage { flex: 1; width: 100%; display: grid; place-items: center; padding: 64px 0 8px; min-height: 0; }
.viewer__foot { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; width: min(520px, 100%); padding: 0 8px 16px; color: #fff; }
.viewer__foot .icon-btn { color: #fff; }
.viewer__meta { text-align: center; }
.viewer__meta-row { display: flex; justify-content: center; align-items: center; gap: 10px; min-height: 30px; }
.viewer__owned { font-weight: 600; font-size: 15px; color: rgba(255,255,255,.85); }
.viewer__hint { margin-top: 8px; font-size: 14px; color: rgba(255,255,255,.6); }

.tier-chip {
  display: inline-flex; align-items: center; height: 30px; padding: 0 14px; border-radius: 999px;
  font: 700 17px/1 var(--display); letter-spacing: .02em; color: var(--ink);
  background: linear-gradient(135deg, var(--ta), var(--tb) 50%, var(--ta));
  box-shadow: 0 0 0 1px rgba(255,255,255,.2) inset;
}
.badge { display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 999px; font: 700 16px/1 var(--display); letter-spacing: .03em; }
.badge--new { background: #fff; color: #0b1430; }
.badge--dupe { background: rgba(255,255,255,.14); color: #fff; }

/* ── pack opening ──────────────────────────────────────────── */
.opener {
  z-index: 110; justify-content: stretch; color: #fff;
  background:
    radial-gradient(60% 46% at 50% 44%, color-mix(in srgb, var(--flash, #1d50df) 42%, transparent), transparent 72%),
    #050a1a;
  transition: opacity .25s ease, background .6s ease;
  --cw: min(74vw, 400px); --cw: min(74vw, calc((100dvh - var(--safe-t) - var(--safe-b) - 280px) * .7069), 400px);
}
.opener__stage { position: relative; flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; min-height: 0; }
.opener.hit::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at 50% 42%, var(--flash), transparent 62%); animation: hit .9s ease-out forwards; }

/* ── PACK REVEAL ───────────────────────────────────────────── */

.tear {
  position: relative;
  flex: 1;
  width: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}

/* Pack */
.tear__pack {
  width: min(58vw, 300px, 40dvh);

  /* Keep animation on the compositor */
  transform: translate3d(0, 0, 0);
  transform-origin: center center;
  backface-visibility: hidden;

  /* Only animate transform/opacity */
  will-change: transform, opacity;

  /* Keep the shadow, but don't make it huge */
  filter: drop-shadow(
    0 20px 25px rgba(0, 0, 0, .45)
  );
}

.tear__pack img {
  display: block;
  width: 100%;
  height: auto;

  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* ── SHAKE ────────────────────────────────────────────────── */

.tear__pack.shake {
  animation:
    packShake
    1.15s
    cubic-bezier(.36, .07, .19, .97)
    both;
}

@keyframes packShake {
  0%,
  100% {
    transform:
      translate3d(0, 0, 0)
      rotate(0deg);
  }

  10% {
    transform:
      translate3d(-5px, 0, 0)
      rotate(-1.5deg);
  }

  20% {
    transform:
      translate3d(5px, 0, 0)
      rotate(1.5deg);
  }

  30% {
    transform:
      translate3d(-6px, 0, 0)
      rotate(-2deg);
  }

  40% {
    transform:
      translate3d(6px, 0, 0)
      rotate(2deg);
  }

  50% {
    transform:
      translate3d(-5px, 0, 0)
      rotate(-1.5deg);
  }

  60% {
    transform:
      translate3d(5px, 0, 0)
      rotate(1.5deg);
  }

  70% {
    transform:
      translate3d(-7px, 0, 0)
      rotate(-2.5deg);
  }

  80% {
    transform:
      translate3d(7px, 0, 0)
      rotate(2.5deg);
  }

  90% {
    transform:
      translate3d(-3px, 0, 0)
      rotate(-1deg);
  }
}

/* ── BURST ────────────────────────────────────────────────── */

.tear__pack.burst {
  animation:
    packBurst
    .52s
    cubic-bezier(.15, .8, .2, 1)
    forwards;
}

@keyframes packBurst {
  0% {
    transform:
      translate3d(0, 0, 0)
      scale(1)
      rotate(0deg);
    opacity: 1;
  }

  25% {
    transform:
      translate3d(0, -3px, 0)
      scale(1.08)
      rotate(-2deg);
    opacity: 1;
  }

  100% {
    transform:
      translate3d(0, -10px, 0)
      scale(1.3)
      rotate(3deg);
    opacity: 0;
  }
}

/* ── FLASH ────────────────────────────────────────────────── */

.tear__flash {
  position: absolute;
  inset: 0;

  pointer-events: none;

  opacity: 0;

  background:
    radial-gradient(
      circle at 50% 50%,
      #fff 0,
      rgba(255, 255, 255, .55) 25%,
      transparent 65%
    );

  transform: scale3d(.8, .8, 1);
  will-change: transform, opacity;
}

.tear__flash.go {
  animation:
    flash
    .5s
    ease-out
    forwards;
}

@keyframes flash {
  0% {
    opacity: 0;
    transform: scale3d(.8, .8, 1);
  }

  20% {
    opacity: 1;
    transform: scale3d(1, 1, 1);
  }

  100% {
    opacity: 0;
    transform: scale3d(1.35, 1.35, 1);
  }
}

.reveal { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; padding: 6px 16px 22px; min-height: 0; }
.reveal__bar { width: min(520px, 100%); display: flex; justify-content: space-between; align-items: center; min-height: 48px; }
.reveal__count { font: 600 20px/1 var(--display); letter-spacing: .03em; color: rgba(255,255,255,.85); }
.reveal .btn-text { color: rgba(255,255,255,.7); }
.reveal__card { flex: 1; width: 100%; display: grid; place-items: center; min-height: 0; transition: transform .22s ease, opacity .22s ease; }
.reveal__card.leave { transform: translateX(-60px) scale(.94); opacity: 0; }
.reveal__info { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 34px; margin: 4px 0 6px; opacity: 0; transform: translateY(8px); transition: opacity .35s ease, transform .35s ease; }
.reveal__info.in { opacity: 1; transform: none; }
.reveal__hint { position: absolute; left: 0; right: 0; bottom: calc(46px + var(--safe-b)); text-align: center; color: rgba(255,255,255,.65); font-size: 15px; margin: 0; }
.reveal__next { width: min(360px, 100%); background: #fff; color: #0b1430; }
.reveal__next:hover { background: #e9efff; }

.summary { width: 100%; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; align-items: center; padding: 34px 20px 24px; }
.summary h2 { font: 700 44px/1 var(--display); letter-spacing: .01em; }
.summary__sub { margin: 8px 0 22px; color: rgba(255,255,255,.75); text-align: center; }
.summary__grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; width: min(560px, 100%); margin-bottom: 26px; }
.summary__grid .sum-card { grid-column: span 2; }
.summary__grid .sum-card:nth-child(4) { grid-column: 2 / span 2; }
.summary__grid .sum-card:nth-child(5) { grid-column: 4 / span 2; }
@media (min-width: 640px) {
  .summary__grid { grid-template-columns: repeat(5, 1fr); }
  .summary__grid .sum-card, .summary__grid .sum-card:nth-child(4), .summary__grid .sum-card:nth-child(5) { grid-column: auto; }
}
.sum-card {
  position: relative; display: block; padding: 0; border: 0; cursor: pointer; overflow: hidden;
  aspect-ratio: 757 / 1071; border-radius: var(--card-radius); background: var(--ta, #222);
  box-shadow: 0 0 0 2px var(--glow), 0 12px 30px -10px var(--glow);
  animation: cardIn .5s cubic-bezier(.2, .9, .3, 1.15) both;
}
.sum-card img { display: block; width: 100%; height: 100%; object-fit: cover; }
.sum-card__new { position: absolute; top: 6px; left: 6px; padding: 4px 8px; border-radius: 999px; background: #fff; color: #0b1430; font: 700 13px/1 var(--display); letter-spacing: .04em; }
.summary__done { max-width: 360px; background: #fff; color: #0b1430; }

/* ── delete dialog ─────────────────────────────────────────── */
.dialog { z-index: 130; justify-content: center; padding: 20px; overflow-y: auto; }
.dialog__card { width: min(440px, 100%); padding: 26px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 30px 80px -20px rgba(0,0,0,.6); transform: translateY(12px) scale(.98); transition: transform .22s ease; }
.dialog.open .dialog__card { transform: none; }
.dialog__card h2 { font: 700 30px/1.1 var(--display); margin-bottom: 8px; }
.dialog__card > p { margin-bottom: 16px; color: var(--muted); }
.dialog__actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ── toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; z-index: 400; bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  max-width: min(440px, calc(100vw - 32px)); padding: 13px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 500; font-size: 15px; line-height: 1.35;
  box-shadow: 0 16px 40px -12px rgba(0,0,0,.5);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: transform .25s ease, opacity .25s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .toast.error { color: #2a0409; }
@media (min-width: 900px) { .toast { bottom: 28px; } }

/* ── motion ────────────────────────────────────────────────── */
@keyframes floaty { 50% { transform: translateY(-12px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes glowPulse { 50% { opacity: .55; transform: translate(-50%, -52%) scale(1.08); } }
@keyframes readyPulse { 50% { box-shadow: 0 16px 42px -8px rgba(242, 201, 92, .95); } }
@keyframes cardIn { from { opacity: 0; transform: translateY(44px) scale(.88); } to { opacity: 1; transform: none; } }
@keyframes shake {
  0%   { transform: translate(0, 0) rotate(0) scale(1); }
  8%   { transform: translate(-7px, 0) rotate(-3deg) scale(1.01); }
  16%  { transform: translate(7px, 0) rotate(3deg) scale(1.02); }
  24%  { transform: translate(-9px, 0) rotate(-4deg) scale(1.03); }
  32%  { transform: translate(9px, 0) rotate(4deg) scale(1.04); }
  44%  { transform: translate(-11px, 0) rotate(-5deg) scale(1.06); }
  56%  { transform: translate(11px, 0) rotate(5deg) scale(1.08); }
  72%  { transform: translate(-6px, 0) rotate(-2deg) scale(1.11); }
  100% { transform: translate(0, 0) rotate(0) scale(1.15); }
}
@keyframes burst { to { transform: scale(1.7) translateY(-6%); opacity: 0; filter: brightness(2.6) blur(3px); } }
@keyframes flash { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }
@keyframes hit { 0% { opacity: .9; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .pack-float, .auth__packwrap, #splash > img, .is-ready .btn-open, .is-ready .pack-glow { animation: none !important; }
  .tear__pack.shake { animation: none !important; }
  .c3d.is-enter, .sum-card { animation-duration: .01s !important; }
}

.tile__x--lower {
  top: 18%;
}
