/*
 * cookiez.cloud Mini App — "Obsidian & Champagne" dark theme.
 * Ported from the battle-tested autolicence Mini App so the two products share
 * one visual language. Fixed dark (does not follow the user's Telegram theme).
 * The only additions over autolicence are the cookie-sales controls: the stock
 * line, the quantity stepper/input, the live price display, and the download
 * button on the PAID status screen (autolicence showed a license key instead).
 */
:root {
  --bg: #0b0d12;
  --bg-deep: #07080c;
  --card: #161a23;
  --card-2: #11141b;
  --surface-hover: #1e2430;
  --text: #f4f6fb;
  --text-2: #c4cad6;
  --text-3: #8a93a6;
  --accent: #d9b45a;
  --accent-soft: #ebc987;
  --accent-300: #f7e7b8;
  --primary: #2f82e8;
  --primary-hover: #1f6fe0;
  --emerald: #10b981;
  --emerald-soft: #6ee7b7;
  --danger: #e54848;
  --warning: #f4c23d;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);
  --glass: rgba(30, 36, 48, 0.55);
  --ink-on-accent: #1a1405;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55), 0 4px 12px rgba(0, 0, 0, 0.4);
  --glow-gold: 0 0 0 1px rgba(217, 180, 90, 0.45), 0 4px 20px rgba(217, 180, 90, 0.25);
  --gradient-gold: linear-gradient(135deg, #d9b45a, #ebc987);
  --gradient-brand: linear-gradient(135deg, #f7e7b8, #d9b45a);
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Sora", "Segoe UI", var(--font-ui);
  --font-mono: "JetBrains Mono", "Courier New", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(217, 180, 90, 0.06), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(47, 130, 232, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}

#app { max-width: 560px; margin: 0 auto; padding: 0 16px 40px; padding-top: var(--safe-top, 0px); }

/* Topbar / brand */
.topbar { display: flex; align-items: baseline; gap: 10px; padding: 20px 4px 16px; }
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.5px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-x { color: var(--accent); -webkit-text-fill-color: var(--accent); }
.brand-sub { color: var(--text-3); font-size: 13px; letter-spacing: 3px; text-transform: uppercase; }
/* Web mode only: the brand logo is a clickable home link. */
.web-mode .brand { cursor: pointer; }
.web-mode .brand:hover { opacity: 0.85; }
.btn-fs {
  margin-left: auto; align-self: center; flex: none; padding: 0;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-hover); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-2);
  font-size: 15px; line-height: 1; cursor: pointer;
}
.btn-fs:hover, .btn-fs:active { border-color: var(--border-strong); color: var(--accent-soft); }
.btn-fs.is-fullscreen { color: var(--accent); border-color: var(--border-strong); }

/* Cards */
.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent), var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 20px;
  margin-bottom: 16px;
}

.hero-title { font-family: var(--font-display); font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.muted { color: var(--text-2); font-size: 14px; }
.muted.small { font-size: 12px; color: var(--text-3); }
.hero .btn { margin-top: 16px; width: 100%; }

.section-title {
  font-family: var(--font-display);
  font-size: 13px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text-3); margin: 8px 4px 12px;
}

/* Stock line (cookie product) — the live "Stokta: N çerez" strip on the home card. */
.stock-line {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 14px; margin: 14px 0 4px;
}
.stock-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--emerald); box-shadow: 0 0 10px rgba(16, 185, 129, 0.6); flex: none; }
.stock-dot.out { background: var(--danger); box-shadow: 0 0 10px rgba(229, 72, 72, 0.6); }
.stock-text { font-size: 14px; color: var(--text-2); }
.stock-value { font-family: var(--font-mono); font-weight: 700; color: var(--accent-300); }

/* Quantity stepper + input (replaces autolicence's package cards). */
.qty-wrap { margin: 18px 0 6px; }
.qty-row { display: flex; align-items: stretch; gap: 10px; }
.qty-btn {
  flex: none; width: 52px; border: 1px solid var(--border); background: var(--surface-hover);
  color: var(--text); border-radius: var(--radius-md); font-size: 24px; font-weight: 600;
  cursor: pointer; transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1); line-height: 1;
}
.qty-btn:hover, .qty-btn:active { border-color: var(--border-strong); color: var(--accent-soft); }
.qty-input {
  flex: 1; min-width: 0; text-align: center; background: var(--bg-deep);
  border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text);
  font-family: var(--font-mono); font-size: 22px; font-weight: 700; padding: 12px 8px;
  -moz-appearance: textfield;
}
.qty-input::-webkit-outer-spin-button, .qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-input:focus { outline: none; border-color: rgba(217, 180, 90, 0.45); box-shadow: var(--glow-gold); }
.qty-hint { color: var(--text-3); font-size: 12px; text-align: center; margin-top: 8px; }

/* Web mode (Phase 2) mandatory email input. */
.email-group { margin: 6px 0 2px; text-align: left; }
.email-group .field-label { margin-bottom: 6px; }
.email-input {
  width: 100%; box-sizing: border-box; padding: 12px 14px;
  background: var(--bg-deep); border: 1px solid var(--border); border-radius: var(--radius-md);
  color: var(--text); font-size: 16px; /* >= 16px avoids iOS focus-zoom */ outline: none;
}
.email-input:focus { border-color: rgba(217, 180, 90, 0.45); box-shadow: var(--glow-gold); }
.email-input::placeholder { color: var(--text-3); }
.email-group .qty-hint { text-align: left; }

/* Live price display for the chosen quantity. */
.price-box {
  display: flex; align-items: baseline; justify-content: center; gap: 8px;
  margin: 16px 0 4px; padding: 14px; background: var(--bg-deep);
  border: 1px solid var(--border); border-radius: var(--radius-md);
}
.price-box .price-label { color: var(--text-3); font-size: 13px; }
.price-box .price-value { font-family: var(--font-mono); font-weight: 700; font-size: 24px; color: var(--accent); }
.price-box .usdt { color: var(--text-3); font-size: 13px; }

/* Feature 3: buy-all button (sits directly under the stock line). */
.btn-buy-all { width: 100%; margin-top: 12px; }

/* CHANGE 2: resume button for a live pending order (countdown to the 30-min expiry). */
.btn-resume { width: 100%; margin-top: 12px; }

/* CHANGE 2: cancel button beneath the resume button (full width, small gap). */
.btn-cancel { width: 100%; margin-top: 10px; }

/* Features 1 + 2: shortfall group (shown when desired qty > available stock). */
.shortfall-group {
  margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.shortfall-note {
  color: var(--text-2); font-size: 13px; text-align: center; line-height: 1.5;
}
.shortfall-note b { color: var(--accent-soft); }

/* BAN LADDER: ban block shown in place of the buy form while the user is banned (warn-tinted). */
.ban-block {
  margin-top: 16px; padding: 14px 16px;
  background: rgba(244, 194, 61, 0.10); border: 1px solid rgba(244, 194, 61, 0.35);
  border-radius: var(--radius-md);
}
.ban-msg {
  color: var(--warning); font-size: 14px; text-align: center; line-height: 1.6; margin: 0;
}

/* Feature 2 split price breakdown: A at full, S at −20%, total. */
.split-breakdown {
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 14px; margin: 2px 0 4px;
}
.split-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 4px 0; }
.split-row .split-label { color: var(--text-3); font-size: 13px; }
.split-row .split-amount { font-family: var(--font-mono); font-weight: 600; font-size: 14px; color: var(--text-2); margin-left: auto; }
.split-total-row { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--border); }
.split-total-row .split-label { color: var(--text-2); font-weight: 600; }
.split-total-row .split-amount { color: var(--accent); font-size: 18px; font-weight: 700; }
.split-total-row .usdt { color: var(--text-3); font-size: 12px; }
.shortfall-hint { color: var(--text-3); font-size: 12px; text-align: center; line-height: 1.5; margin-top: 2px; }

/* Buttons */
.btn {
  font-family: var(--font-ui); font-weight: 600; font-size: 15px;
  border: none; border-radius: var(--radius-md); padding: 12px 18px; cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1); color: var(--text);
}
.btn-lg { padding: 15px 20px; font-size: 16px; }
.btn-gold { background: var(--gradient-gold); color: var(--ink-on-accent); box-shadow: var(--glow-gold); }
.btn-gold:hover, .btn-gold:active { filter: brightness(1.05); box-shadow: 0 8px 26px rgba(217, 180, 90, 0.35); }
.btn-gold:disabled { filter: grayscale(0.6) brightness(0.7); box-shadow: none; cursor: not-allowed; }
.btn-ghost { background: var(--surface-hover); color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--border-strong); color: var(--text); }
.btn-back { margin-bottom: 12px; padding: 8px 14px; font-size: 14px; }
.status-card .btn { width: 100%; margin-top: 10px; }
.hero .btn-buy { margin-top: 18px; }

/* Key / address rows — centered value with the Copy button below it */
.field-label { color: var(--text-3); font-size: 12px; letter-spacing: 0.5px; text-transform: uppercase; margin: 14px 0 6px; text-align: center; }
.key-row { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
/* Amount on the home pending-order block (mirrors the pay screen's price-value). */
.pending-amount { font-family: var(--font-mono); font-weight: 700; font-size: 20px; color: var(--accent); text-align: center; }
.mono { font-family: var(--font-mono); font-size: 13px; color: var(--text); word-break: break-all; }
.key, .addr {
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; color: var(--accent-300); text-align: center;
}
.btn-copy { align-self: center; padding: 8px 18px; font-size: 13px; white-space: nowrap; }
.link { color: var(--primary); word-break: break-all; font-size: 14px; }
.info { margin-top: 12px; white-space: pre-line; }

.success-card { text-align: center; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; margin-bottom: 4px; }
.badge-emerald { background: rgba(16, 185, 129, 0.15); color: var(--emerald-soft); border: 1px solid rgba(16, 185, 129, 0.35); }

/* Pay */
.pay-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pay-pkg { font-family: var(--font-display); font-weight: 600; font-size: 17px; }
.pay-amount { font-family: var(--font-mono); font-weight: 700; font-size: 20px; color: var(--accent); }
.pay-amount .usdt { color: var(--text-3); font-size: 13px; }
.qr-wrap { display: flex; justify-content: center; margin: 16px 0; }
.qr-wrap img { background: #fff; padding: 10px; border-radius: var(--radius-md); box-shadow: var(--shadow-md); }
.pay-card .btn-gold { width: 100%; margin-top: 16px; }
.pay-note { text-align: center; margin-top: 20px; font-size: 12px; color: var(--text-3); line-height: 1.6; }
/* Split-order note on the pay screen (A now / S discounted backorder). */
.pay-split-note {
  background: var(--bg-deep); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 10px 12px; margin: 4px 0 12px; font-size: 13px; color: var(--text-2);
  text-align: center; line-height: 1.5;
}
.pay-split-note b { color: var(--accent-soft); }
.pay-warn { text-align: center; margin-top: 8px; font-size: 12px; color: var(--text-3); line-height: 1.6; }

/* Status */
.status-card { text-align: center; }
.status-visual { display: flex; justify-content: center; margin: 8px 0 18px; }
.status-title { font-family: var(--font-display); font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.status-key { text-align: center; margin-top: 18px; }
.status-key .mono { display: block; background: var(--bg-deep); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }

/* Download button on the PAID status screen (cookie delivery). */
.btn-download { width: 100%; margin-top: 6px; text-decoration: none; display: block; text-align: center; }
.dl-expiry { color: var(--text-3); font-size: 12px; text-align: center; margin-top: 10px; }

/* Split order: outstanding backorder note on the PAID status screen. */
.status-backorder {
  margin-top: 16px; padding: 14px; background: var(--bg-deep);
  border: 1px solid var(--border); border-radius: var(--radius-md); text-align: center;
}
.backorder-badge {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 4px 12px;
  border-radius: 999px; margin-bottom: 8px;
  background: rgba(217, 180, 90, 0.15); color: var(--accent-soft);
  border: 1px solid rgba(217, 180, 90, 0.35);
}
.status-backorder .muted b { color: var(--accent-soft); }

.spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid rgba(47, 130, 232, 0.2); border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 22px rgba(47, 130, 232, 0.3);
}
@keyframes spin { to { transform: rotate(360deg); } }
.check-mark, .cross-mark { width: 54px; height: 54px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 30px; }
.check-mark { background: rgba(16, 185, 129, 0.15); color: var(--emerald); box-shadow: 0 0 24px rgba(16, 185, 129, 0.35); }
.cross-mark { background: rgba(229, 72, 72, 0.15); color: var(--danger); box-shadow: 0 0 24px rgba(229, 72, 72, 0.3); }

/* Affiliate */
.aff-entry { width: 100%; margin-top: 14px; }
.aff-stats { display: flex; gap: 10px; margin: 18px 0 4px; }
.aff-stat {
  flex: 1; text-align: center; background: var(--bg-deep);
  border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 8px;
}
.aff-stat-value { font-family: var(--font-mono); font-weight: 700; font-size: 18px; color: var(--accent); }
.aff-stat-label { color: var(--text-3); font-size: 11px; letter-spacing: 0.3px; margin-top: 4px; }
.aff-input {
  width: 100%; background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; color: var(--text);
  font-size: 13px; text-align: center;
}
.aff-input:focus { outline: none; border-color: rgba(217, 180, 90, 0.45); box-shadow: var(--glow-gold); }
.aff-input::placeholder { color: var(--text-3); }
.aff-hint { color: var(--text-3); font-size: 12px; text-align: center; margin: 8px 0 4px; }
#screen-affiliate .btn-gold { width: 100%; margin-top: 14px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 32px);
  background: var(--card-2); border: 1px solid var(--border-strong); color: var(--text);
  padding: 13px 22px; border-radius: 16px; box-shadow: var(--shadow-lg);
  font-size: 14px; line-height: 1.45; text-align: center; z-index: 50;
}

.hidden { display: none !important; }
.screen { animation: fade 0.28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
