/* =====================================================================
   CLX Trading app layer. Loaded in addition to the website's own styles; it only adds things and
   refines a few touch/safe-area details. It uses the site's own colour and font variables
   (--gold, --gold-hi, --line, --text ...) so the look always stays in sync with the website.
   ===================================================================== */

:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --tabbar-h: 62px;
}

/* ---------- touch polish (website and app) ---------- */
html { -webkit-tap-highlight-color: transparent; }
a, button, summary, label, .opt, .shot, [data-video-toggle] { touch-action: manipulation; }
button, .btn, .nav-links a, .pwa-tabbar a { -webkit-touch-callout: none; }

/* Comfortable tap targets (44px is the usual minimum) on touch screens. */
@media (pointer: coarse) {
  .btn-sm { min-height: 44px; }
  .brand { min-height: 44px; align-items: center; }
  .nav-links a:not(.btn) { min-height: 44px; display: flex; align-items: center; }
  .link-btn { min-height: 44px; padding-inline: 10px; display: inline-flex; align-items: center; }
  .site-footer li a, .legal-row li a { display: inline-flex; align-items: center; min-height: 44px; }
  .site-footer li + li { margin-top: 0; }
  .faq summary { min-height: 48px; }
  .consent { min-height: 44px; align-items: center; }
  .lb-close { min-width: 44px; min-height: 44px; }
}

/* ---------- launch / loading screen (only when opened as an installed app) ---------- */
#clx-splash { display: none; }
html.is-standalone #clx-splash {
  display: grid;
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  place-items: center;
  background:
    radial-gradient(55% 45% at 92% 0%, rgba(212, 175, 55, .16), transparent 70%),
    radial-gradient(52% 50% at 0% 100%, rgba(47, 123, 255, .18), transparent 70%),
    #0a0a0a;
  opacity: 1;
  transition: opacity .45s ease, visibility .45s ease;
  /* Failsafe: even if scripts never run, the screen clears itself after a few seconds. */
  animation: clxSplashFailsafe .01s linear 3.4s forwards;
}
#clx-splash.out { opacity: 0; visibility: hidden; }
#clx-splash .clx-splash-inner { display: grid; justify-items: center; gap: 24px; padding-bottom: 4vh; }
#clx-splash img { width: min(46vw, 200px); height: auto; animation: clxPulse 1.8s ease-in-out infinite; }
#clx-splash .bar { width: min(46vw, 200px); height: 3px; border-radius: 3px; background: rgba(255, 255, 255, .1); overflow: hidden; }
#clx-splash .bar::after { content: ""; display: block; height: 100%; width: 40%; background: linear-gradient(90deg, #d4af37, #f5c542); animation: clxLoad 1.1s ease-in-out infinite; }
@keyframes clxSplashFailsafe { to { opacity: 0; visibility: hidden; } }
@keyframes clxPulse { 0%, 100% { transform: scale(1); opacity: .92; } 50% { transform: scale(1.035); opacity: 1; } }
@keyframes clxLoad { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }

/* ---------- installed-app layout ---------- */
html.is-standalone {
  /* The status bar is transparent in the installed app, so the header makes room for it. */
  --nav-h: calc(68px + var(--safe-t));
  overscroll-behavior-y: none;
}
html.is-standalone .topbar { padding-top: var(--safe-t); }
html.is-standalone .site-header { padding-top: var(--safe-t); }
html.is-standalone body { padding-left: var(--safe-l); padding-right: var(--safe-r); }

/* ---------- bottom tab bar (installed app, phones and small tablets) ---------- */
.pwa-tabbar { display: none; }
@media (max-width: 900px) {
  html.is-standalone .pwa-tabbar {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 58;
    padding: 6px calc(6px + var(--safe-r)) calc(6px + var(--safe-b)) calc(6px + var(--safe-l));
    background: rgba(10, 10, 10, .9);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    backdrop-filter: blur(16px) saturate(140%);
    border-top: 1px solid var(--line, rgba(255, 255, 255, .09));
    transition: transform .25s ease;
  }
  html.is-standalone.pwa-typing .pwa-tabbar { transform: translateY(110%); } /* out of the way of the keyboard */
  html.is-standalone body { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
  html.is-standalone .wa-fab { bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); }
  html.is-standalone.pwa-typing .wa-fab { bottom: max(18px, var(--safe-b)); }
}
.pwa-tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 50px; padding: 4px 2px; border-radius: 12px;
  color: var(--muted, #a3a39e); text-decoration: none;
  font: 600 11px/1.1 var(--sans, system-ui, sans-serif); letter-spacing: .01em;
  transition: color .2s ease, background .2s ease, transform .15s ease;
}
.pwa-tabbar a:active { transform: scale(.95); }
.pwa-tabbar svg { width: 22px; height: 22px; }
.pwa-tabbar a[aria-current="true"] { color: var(--gold-hi, #f5c542); background: rgba(212, 175, 55, .1); }
.pwa-tabbar a.join { color: #0a0a0a; background: linear-gradient(180deg, #f6cf5c, #d4af37); }
.pwa-tabbar a.join[aria-current="true"] { color: #0a0a0a; }

/* ---------- install card, update toast, offline pill ---------- */
.pwa-card, .pwa-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  z-index: 70;
  width: min(calc(100% - 32px), 470px);
  transform: translate(-50%, 24px);
  opacity: 0;
  visibility: hidden;
  transition: transform .35s cubic-bezier(.22, 1, .36, 1), opacity .3s ease, visibility .3s;
}
.pwa-card.show, .pwa-toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
@media (max-width: 640px) {
  /* Sit above the round WhatsApp button so nothing overlaps. */
  .pwa-card, .pwa-toast { bottom: calc(86px + var(--safe-b)); }
  html.is-standalone .pwa-card, html.is-standalone .pwa-toast { bottom: calc(var(--tabbar-h) + var(--safe-b) + 84px); }
}
.pwa-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 14px 14px 16px;
  border: 1px solid var(--line-gold, rgba(212, 175, 55, .32));
  border-radius: 20px;
  background: rgba(14, 14, 14, .95);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .9), 0 0 0 1px rgba(255, 255, 255, .02) inset;
  color: var(--text, #f4f4f1);
}
.pwa-card img { flex: none; width: 46px; height: 46px; border-radius: 12px; }
.pwa-card .txt { min-width: 0; flex: 1; }
.pwa-card .txt b { display: block; font: 700 17px/1.2 var(--display, system-ui); letter-spacing: .02em; }
.pwa-card .txt small { display: block; margin-top: 2px; color: var(--soft, #d2d2cd); font-size: 13px; line-height: 1.35; }
.pwa-card .acts { flex: none; display: flex; align-items: center; gap: 6px; }
.pwa-card .pwa-x {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  color: var(--muted, #a3a39e); font-size: 22px; line-height: 1; cursor: pointer;
}
.pwa-card .pwa-x:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.pwa-toast {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px 12px 18px;
  border: 1px solid var(--line-gold, rgba(212, 175, 55, .32));
  border-radius: 16px;
  background: rgba(14, 14, 14, .96);
  color: var(--text, #f4f4f1);
  font-size: 14.5px;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, .9);
}
.pwa-offline {
  position: fixed; left: 50%; top: calc(var(--nav-h, 68px) + 10px); z-index: 61;
  transform: translate(-50%, -12px); opacity: 0; visibility: hidden;
  padding: 8px 16px; border-radius: 999px; white-space: nowrap;
  border: 1px solid rgba(245, 197, 66, .5); background: rgba(24, 20, 8, .95); color: #f7e2a0;
  font: 600 13px/1.2 var(--sans, system-ui, sans-serif);
  transition: transform .3s ease, opacity .3s ease, visibility .3s;
}
.pwa-offline.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

/* ---------- "how to install" sheet (iPhone, and in-app browsers) ---------- */
dialog#pwaHelp {
  width: min(92vw, 440px); padding: 26px 24px 22px; border: 1px solid var(--line-gold, rgba(212, 175, 55, .32));
  border-radius: 24px; background: #121212; color: var(--text, #f4f4f1);
  box-shadow: 0 40px 120px rgba(0, 0, 0, .85);
}
dialog#pwaHelp::backdrop { background: rgba(0, 0, 0, .8); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
#pwaHelp h2 { font: 700 30px/1.05 var(--display, system-ui); margin: 0 0 6px; }
#pwaHelp p { color: var(--soft, #d2d2cd); font-size: 15.5px; line-height: 1.5; margin: 0; }
#pwaHelp ol { margin: 18px 0 20px; padding: 0; list-style: none; display: grid; gap: 14px; counter-reset: s; }
#pwaHelp li { display: flex; gap: 14px; align-items: flex-start; font-size: 16px; line-height: 1.4; counter-increment: s; }
#pwaHelp li::before {
  content: counter(s); flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--gold, #d4af37); color: #000; font: 800 15px var(--sans, system-ui, sans-serif);
}
#pwaHelp li svg { display: inline-block; width: 1.15em; height: 1.15em; vertical-align: -.2em; color: var(--gold-hi, #f5c542); }
#pwaHelp .row { display: flex; gap: 10px; flex-wrap: wrap; }
#pwaHelp .row .btn { flex: 1; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  #clx-splash img, #clx-splash .bar::after { animation: none; }
  .pwa-card, .pwa-toast, .pwa-offline, .pwa-tabbar, .pwa-tabbar a { transition: none; }
}
