@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&family=Fira+Sans:wght@400;500;600;700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  --black: #000;
  --surface: #0b0b0c;
  --surface-raised: #121214;
  --surface-hover: #19191c;
  --white: #fff;
  --muted: #a1a1aa;
  --dim: #71717a;
  --line: #27272a;
  --line-strong: #3f3f46;
  --danger: #f87171;
  --radius: 14px;
  --radius-small: 9px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --shadow: 0 24px 70px rgba(0, 0, 0, .42);
}

html { background: var(--black); scroll-behavior: smooth; overflow-x: hidden; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--black);
  color: var(--white);
  font-family: 'Fira Sans', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body > :not(.ambient-canvas) { position: relative; z-index: 1; }
a, button, input, textarea { font: inherit; }
a { color: inherit; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
html, body, label { cursor: auto; }
a, button, select { cursor: pointer; }
input, textarea { cursor: text; }
.btn-disabled, .btn:disabled, [disabled] { cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--white);
  outline-offset: 3px;
}

.ambient-canvas { position: fixed; inset: 0; z-index: 0; width: 100%; height: 100%; pointer-events: none; opacity: 1; filter: contrast(1.12); }

/* Navigation */
.nav {
  position: fixed !important;
  inset: 0 0 auto;
  z-index: 20 !important;
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 72px;
  padding: 12px clamp(18px, 4vw, 56px);
  background: rgba(0, 0, 0, .76);
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.nav-logo { flex: 0 0 auto; color: var(--white); text-decoration: none; font-family: 'Fira Code', monospace; font-size: .92rem; font-weight: 700; letter-spacing: .08em; }
.nav-logo span { display: inline-block; }
.nav-links { display: flex; align-items: center; gap: 4px; margin-right: auto; }
.nav-links a, .nav-admin-link { padding: 8px 11px; color: var(--muted); text-decoration: none; font-size: .86rem; white-space: nowrap; border-radius: 8px; transition: color .2s ease, background .2s ease; }
.nav-links a:hover, .nav-links a[aria-current="page"], .nav-admin-link:hover, .nav-admin-link[aria-current="page"] { color: var(--white); background: rgba(255, 255, 255, .08); }
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-user { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .82rem; }
.nav-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line-strong); }
.balance-pill { display: inline-flex; align-items: baseline; gap: 5px; padding: 7px 10px; color: var(--white); text-decoration: none; background: var(--surface-raised); border: 1px solid var(--line); border-radius: 8px; transition: border-color .2s ease, background .2s ease; }
.balance-pill:hover { background: var(--surface-hover); border-color: var(--line-strong); }
.balance-value { font-family: 'Fira Code', monospace; font-size: .8rem; font-weight: 600; }
.balance-label { color: var(--muted); font-size: .72rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; gap: 8px; padding: 10px 18px; border: 1px solid transparent; border-radius: var(--radius-small); font-size: .9rem; font-weight: 600; text-decoration: none; transition: transform .2s var(--ease), background .2s ease, border-color .2s ease, color .2s ease; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: scale(.97); }
.btn-primary { color: var(--black); background: var(--white); border-color: var(--white); }
.btn-primary:hover { background: #e4e4e7; }
.btn-secondary { color: var(--white); background: transparent; border-color: var(--line-strong); }
.btn-secondary:hover, .btn-ghost:hover { background: rgba(255, 255, 255, .08); border-color: #71717a; }
.btn-ghost { color: var(--muted); background: transparent; border-color: transparent; }
.btn-small { min-height: 36px; padding: 7px 12px; font-size: .78rem; }
.btn-large { min-height: 52px; padding-inline: 24px; }
.btn-disabled, .btn:disabled { color: #71717a; background: #18181b; border-color: #27272a; cursor: not-allowed; opacity: .8; }
.btn-disabled:hover, .btn:disabled:hover { transform: none; }

/* Shared layout */
.page { width: min(1160px, calc(100% - 40px)); margin: 0 auto; padding: 132px 0 80px; }
.eyebrow { margin: 0 0 16px; color: var(--muted); font-family: 'Fira Code', monospace; font-size: .72rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }
.display-title { max-width: 800px; margin: 0; font-size: clamp(2.3rem, 5.5vw, 4.5rem); line-height: 1.04; letter-spacing: -.04em; }
.lede { max-width: 620px; margin: 26px 0 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.2rem); line-height: 1.65; }
.section { width: min(1160px, calc(100% - 40px)); margin: 0 auto; padding: 88px 0; }
.section-heading { max-width: 620px; margin-bottom: 34px; }
.section-heading h2 { margin: 0 0 10px; font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1.05; letter-spacing: -.045em; }
.section-heading p { margin: 0; color: var(--muted); }
.rule { height: 1px; margin: 0; background: var(--line); border: 0; }

/* Home */
.hero { min-height: min(600px, 100svh); display: grid; align-content: center; width: min(1160px, calc(100% - 40px)); margin: 0 auto; padding: 116px 0 48px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 36px; }
.hero-note { margin: 18px 0 0; color: var(--dim); font-family: 'Fira Code', monospace; font-size: .72rem; }
.hero-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.feature-card { min-height: 180px; padding: 24px; background: rgba(11, 11, 12, .72); border: 1px solid var(--line); border-radius: var(--radius); }
.feature-index { display: block; margin-bottom: 16px; color: var(--dim); font-family: 'Fira Code', monospace; font-size: .75rem; }
.feature-card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.feature-card p { margin: 0; color: var(--muted); font-size: .9rem; }
.social-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.social-link { display: inline-grid; place-items: center; width: 44px; height: 44px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; text-decoration: none; transition: color .2s ease, border-color .2s ease, background .2s ease, transform .2s var(--ease); }
.social-link:hover { color: var(--white); background: rgba(255,255,255,.08); border-color: var(--line-strong); transform: translateY(-2px); }
.social-link:active { transform: scale(.95); }
.social-icon { width: 20px; height: 20px; fill: currentColor; }

/* FAQ */
.faq-list { max-width: 760px; }
.faq-item { margin-bottom: 10px; background: rgba(11, 11, 12, .72); border: 1px solid var(--line); border-radius: var(--radius-small); overflow: hidden; }
.faq-item summary { padding: 16px 20px; cursor: pointer; font-weight: 600; font-size: .95rem; list-style: none; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: '+'; float: right; color: var(--muted); font-family: 'Fira Code', monospace; }
.faq-item[open] summary::after { content: '\2212'; }
.faq-item p { margin: 0; padding: 0 20px 18px; color: var(--muted); font-size: .9rem; line-height: 1.6; }

/* Cards, forms, tables */
.surface { background: rgba(11, 11, 12, .84); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form-card { width: min(560px, 100%); padding: clamp(24px, 5vw, 44px); }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; color: var(--white); font-size: .84rem; font-weight: 600; }
.form-hint { margin: 7px 0 0; color: var(--dim); font-size: .76rem; }
.form-input, .form-textarea { width: 100%; min-height: 48px; padding: 12px 14px; color: var(--white); background: var(--surface-raised); border: 1px solid var(--line-strong); border-radius: var(--radius-small); outline: none; }
.form-input::placeholder, .form-textarea::placeholder { color: var(--dim); }
.form-input:focus, .form-textarea:focus { border-color: var(--white); box-shadow: 0 0 0 3px rgba(255,255,255,.12); }
.form-textarea { min-height: 110px; resize: vertical; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.summary-row { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; padding: 18px 0; border-top: 1px solid var(--line); }
.summary-row strong { font-family: 'Fira Code', monospace; font-size: 1.18rem; }
.summary-row span { color: var(--muted); font-size: .85rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-small); }
table { width: 100%; min-width: 650px; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); font-size: .82rem; white-space: nowrap; }
th { color: var(--muted); font-family: 'Fira Code', monospace; font-size: .68rem; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; background: rgba(255,255,255,.025); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255,255,255,.035); }
code, .mono { font-family: 'Fira Code', monospace; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.empty-state { padding: 40px 20px; color: var(--muted); text-align: center; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line-strong); border-top-color: var(--white); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }

/* Login and success */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 110px 20px 60px; }
.login-card { width: min(460px, 100%); padding: clamp(26px, 6vw, 52px); text-align: center; }
.login-mark { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 24px; color: var(--black); background: var(--white); border-radius: 50%; font-family: 'Fira Code', monospace; font-weight: 700; }
.login-card h1, .success-card h1 { margin: 0 0 10px; font-size: clamp(1.8rem, 5vw, 2.8rem); letter-spacing: -.05em; }
.login-card p, .success-card p { margin: 0 0 28px; color: var(--muted); }
.login-card .btn { width: 100%; }
.user-panel { display: grid; gap: 16px; justify-items: center; }
.user-avatar-large { width: 72px; height: 72px; border: 2px solid var(--line-strong); border-radius: 50%; object-fit: cover; }
.success-card { max-width: 560px; padding: clamp(28px, 6vw, 60px); text-align: center; }
.success-mark { display: grid; place-items: center; width: 70px; height: 70px; margin: 0 auto 24px; color: var(--black); background: var(--white); border-radius: 50%; font-size: 1.7rem; }

/* Top up */
.topup-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, .72fr); gap: 24px; align-items: start; }
.topup-card { padding: clamp(24px, 4vw, 38px); }
.topup-card h1 { margin: 0 0 12px; font-size: clamp(2rem, 5vw, 3.4rem); letter-spacing: -.06em; line-height: 1; }
.topup-card > p { margin: 0 0 30px; color: var(--muted); }
.credit-total { margin: 20px 0 26px; padding: 20px; background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-small); }
.credit-total .total-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .1em; }
.credit-total strong { display: block; font-family: 'Fira Code', monospace; font-size: clamp(1.8rem, 5vw, 2.8rem); }
.credit-total small { color: var(--muted); }
.balance-card { padding: 24px; }
.balance-card .balance-number { display: block; margin: 8px 0 4px; font-family: 'Fira Code', monospace; font-size: 2.3rem; font-weight: 600; }
.balance-card p { margin: 0; color: var(--muted); font-size: .85rem; }
.history-section { margin-top: 26px; }
.history-section h2 { margin: 0 0 14px; font-size: 1rem; }

/* Checkout payment methods */
.pay-group { padding: 0; border: 0; }
.pay-group legend { margin-bottom: 10px; color: var(--white); font-size: .84rem; font-weight: 600; }
.pay-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease;
}
.pay-option:last-child { margin-bottom: 0; }
.pay-option:hover { border-color: var(--line-strong); }
.pay-option:has(input:checked) { border-color: var(--white); background: var(--surface-hover); }
.pay-option input { width: 18px; height: 18px; margin: 0; accent-color: var(--white); }
.pay-badge {
  flex: 0 0 auto;
  padding: 4px 9px;
  border-radius: 6px;
  color: var(--black);
  background: var(--white);
  font-family: 'Fira Code', monospace;
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .08em;
}
.pay-badge-fk { color: var(--white); background: transparent; border: 1px solid var(--line-strong); }
.pay-option:has(input:checked) .pay-badge-fk { color: var(--black); background: var(--white); border-color: var(--white); }
.pay-meta { display: flex; flex-direction: column; min-width: 0; }
.pay-meta strong { font-size: .9rem; }
.pay-meta small { color: var(--muted); font-size: .76rem; line-height: 1.4; }

/* Admin */
.admin-page { padding-top: 128px; }
.admin-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.admin-header h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1; letter-spacing: -.06em; }
.admin-tabs { display: flex; gap: 4px; margin-bottom: 20px; padding: 4px; width: fit-content; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.admin-tab { min-height: 40px; padding: 8px 14px; color: var(--muted); background: transparent; border: 0; border-radius: 7px; font-size: .8rem; cursor: pointer; }
.admin-tab:hover { color: var(--white); }
.admin-tab.active { color: var(--black); background: var(--white); }
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.panel-card { padding: 24px; }
.panel-card h2 { margin: 0 0 6px; font-size: 1.15rem; }
.panel-card > p { margin: 0 0 20px; color: var(--muted); font-size: .84rem; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.credit-add { display: flex; gap: 7px; align-items: center; }
.credit-add input { width: 105px; min-height: 36px; padding: 7px 9px; color: var(--white); background: var(--surface-raised); border: 1px solid var(--line-strong); border-radius: 7px; }

/* Footer and feedback */
.footer { padding: 38px 20px; color: var(--dim); border-top: 1px solid var(--line); text-align: center; font-family: 'Fira Code', monospace; font-size: .7rem; }
.footer p { margin: 0; }
.footer a img { display: inline-block; width: 96px; height: auto; opacity: .45; margin-bottom: 14px; transition: opacity .15s ease; }
.footer a img:hover { opacity: .9; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 100; width: max-content; max-width: min(420px, calc(100vw - 32px)); padding: 13px 18px; color: var(--white); background: #18181b; border: 1px solid var(--line-strong); border-radius: 9px; box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: opacity .2s ease, transform .2s var(--ease); font-size: .82rem; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { color: #fecaca; border-color: #7f1d1d; }
.reveal { opacity: 1; transform: none; }
.js-ready .reveal { opacity: 0; transform: translateY(16px); transition: opacity .55s ease, transform .55s var(--ease); }
.js-ready .reveal.is-visible { opacity: 1; transform: none; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .nav { gap: 12px; }
  .nav-user span, .nav-admin-link { display: none; }
  .topup-layout { grid-template-columns: 1fr; }
  .hero-grid { grid-template-columns: 1fr; }
  .feature-card { min-height: 0; }
  .feature-index { margin-bottom: 22px; }
}
@media (max-width: 560px) {
  .nav { min-height: 64px; padding-inline: 14px; flex-wrap: wrap; row-gap: 8px; }
  .nav-logo { order: 1; font-size: .75rem; }
  .nav-right { order: 2; margin-left: auto; }
  .nav-links { order: 3; width: 100%; margin-right: 0; justify-content: center; padding-bottom: 4px; }
  .page, .hero { padding-top: 148px; }
  .center-page { padding-top: 148px; }
  .nav-links a { padding-inline: 7px; font-size: .78rem; }
  .nav-right { gap: 5px; }
  .balance-pill { padding: 6px 7px; }
  .page, .section, .hero { width: min(100% - 28px, 1160px); }
  .hero { min-height: min(620px, 100svh); padding-top: 148px; padding-bottom: 42px; }
  .display-title { font-size: clamp(2rem, 11vw, 3.2rem); }
  .hero-actions, .form-actions { flex-direction: column; align-items: stretch; }
  .hero-actions .btn, .form-actions .btn { width: 100%; }
  .admin-header { align-items: flex-start; flex-direction: column; }
  .admin-header .btn { width: 100%; }
  .admin-tabs { width: 100%; }
  .admin-tab { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .reveal, .js-ready .reveal { opacity: 1; transform: none; }
  .ambient-canvas { display: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .nav { background: var(--black); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .surface, .feature-card { background: var(--surface); }
}

/* --- Affiliate codes & referrals --- */
.code-input { text-transform: uppercase; font-family: 'Fira Code', monospace; letter-spacing: .04em; }
.hint-error { color: var(--danger, #f87171) !important; }
.strike { color: var(--dim); font-weight: 400; font-size: .62em; text-decoration: line-through; }

.referral-card h2 { margin: 0 0 10px; font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.08; letter-spacing: -.03em; }
.referral-card > p { margin: 0 0 22px; color: var(--muted); max-width: 640px; }
.referral-code-row { display: flex; gap: 12px; align-items: center; margin: 0 0 24px; }
.affiliate-code { display: inline-block; padding: 12px 18px; font-family: 'Fira Code', monospace; font-size: 1.15rem; font-weight: 600; letter-spacing: .08em; color: var(--black); background: var(--white); border-radius: 8px; }

.referral-edit-form { margin-bottom: 28px; }
.referral-edit-input { display: flex; gap: 10px; }
.referral-edit-input .form-input { flex: 1; min-width: 0; }
.referral-edit-input .btn { white-space: nowrap; }

.earnings-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 30px; }
.earnings-stat { padding: 18px 20px; background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-small); }
.earnings-stat span { display: block; margin-bottom: 6px; color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; }
.earnings-stat strong { font-family: 'Fira Code', monospace; font-size: 1.7rem; font-weight: 600; }
.cashout-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 30px; }
.cashout-row .form-hint { margin: 0; flex: 1; min-width: 200px; }
.referral-history-title { margin: 0 0 12px; font-size: 1rem; }

.affiliate-form { margin-bottom: 8px; }
.affiliate-form-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; align-items: end; }
@media (max-width: 1100px) {
  .affiliate-form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .affiliate-form-grid { grid-template-columns: 1fr; }
}
.check-label { display: inline-flex; gap: 8px; align-items: center; min-height: 48px; color: var(--muted); cursor: pointer; }

.table-toolbar { margin: 0 0 12px; max-width: 420px; }
.table-toolbar .form-input { min-height: 42px; }
.table-toolbar-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; max-width: none; }
.table-toolbar-row input { flex: 1; min-width: 200px; }
.table-toolbar-row select { width: auto; min-width: 150px; }

.src-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .74rem; letter-spacing: .04em; border: 1px solid var(--line-strong); white-space: nowrap; }
.src-badge.src-paid { color: var(--white); border-color: rgba(255, 255, 255, .35); }
.src-badge.src-free { color: var(--muted); }
.src-badge.src-spend { color: var(--danger); border-color: rgba(248, 113, 113, .4); }

.affiliate-create-box { padding: 28px 22px; text-align: center; background: var(--surface-raised); border: 1px dashed var(--line-strong); border-radius: var(--radius-small); }
.affiliate-create-box p { margin: 0 auto 18px; max-width: 460px; color: var(--muted); }
.check-label input { width: 18px; height: 18px; accent-color: var(--white); }

@media (max-width: 560px) {
  .referral-edit-input { flex-direction: column; }
  .referral-edit-input .btn { width: 100%; }
}

/* Redeem page */
.deal-card { margin-top: 24px; padding: 28px 24px; text-align: center; background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-small); }
.deal-card .btn { width: 100%; }
.deal-code { margin: 0 0 16px; color: var(--muted); font-family: 'Fira Code', monospace; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; }
.deal-credits { margin-bottom: 4px; color: var(--muted); }
.deal-credits strong { display: block; margin-bottom: 2px; font-family: 'Fira Code', monospace; font-size: clamp(2rem, 6vw, 3rem); font-weight: 700; letter-spacing: -.02em; }
.deal-price { margin-bottom: 22px; font-family: 'Fira Code', monospace; font-size: 1.15rem; font-weight: 600; }
.deal-note { margin: 0 0 18px; color: var(--danger); font-size: .8rem; }
.deal-success { border-color: rgba(255, 255, 255, .25); }
