/* WhatsApp login — cinematic arena platform (magenta L / cyan R) + grounded sprite */
:root {
  --ochre: #c9a227;
  --umber: #8a6240;
  --river-slate: #3a2048;
  --night-indigo: #0a0614;
  --magenta-glow: #e83c8c;
  --cyan-glow: #3ec8f0;
  --card-glass: rgba(18, 10, 28, 0.82);
  --card-rim: rgba(232, 60, 140, 0.35);
  --mist: rgba(232, 60, 140, 0.08);
}

body.wa-login-kasi {
  /* Arena cavern plate; brand fonts/CTAs stay — override paper ink for dark glass */
  --ink: #f2e8f4;
  --ink-soft: #d4c0e0;
  --muted: #b8a0c8;
  --surface: rgba(18, 10, 28, 0.92);
  --line: rgba(232, 60, 140, 0.4);
  --paper-deep: #1a0e28;
  position: relative;
  background-color: #0a0614;
  background-image:
    linear-gradient(
      180deg,
      rgba(10, 6, 20, 0.28) 0%,
      rgba(8, 2, 18, 0.18) 42%,
      rgba(6, 4, 14, 0.42) 100%
    ),
    image-set(
      url('/visual-kit/nightmare/bg-arena-platform.jpg?v=20261027wizard2') 1x,
      url('/visual-kit/nightmare/bg-arena-platform@2x.jpg?v=20261027wizard2') 2x
    ),
    url('/visual-kit/nightmare/bg-arena-platform.jpg?v=20261027wizard2');
  background-size: cover, cover, cover;
  /* Platform stays grounded; neon L/R stay in frame */
  background-position: center bottom, center bottom, center bottom;
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-attachment: fixed, fixed, fixed;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
}

#login-atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background-color: #0a0614;
  background-image:
    image-set(
      url('/visual-kit/nightmare/bg-arena-platform.jpg?v=20261027wizard2') 1x,
      url('/visual-kit/nightmare/bg-arena-platform@2x.jpg?v=20261027wizard2') 2x
    ),
    url('/visual-kit/nightmare/bg-arena-platform.jpg?v=20261027wizard2');
  background-size: cover, cover;
  background-position: center bottom, center bottom;
  background-repeat: no-repeat, no-repeat;
}

#login-atmosphere canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  background: transparent !important;
}

/* —— Depth layers (Phase 2–3): under UI, under tokoloshe, never over QR —— */
#login-svg-parallax,
#login-midground,
#login-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

#login-svg-parallax {
  z-index: 1;
}

#login-midground {
  z-index: 1;
  opacity: 0.85;
}

#login-vignette {
  z-index: 1;
  mix-blend-mode: multiply;
  opacity: 0.9;
}

#login-svg-parallax svg,
#login-midground svg,
#login-vignette svg {
  display: block;
  width: 100%;
  height: 100%;
}

.svg-parallax-layer {
  transform-box: fill-box;
  transform-origin: center center;
  will-change: transform;
}

body.login-svg-mobile .svg-parallax-layer {
  will-change: auto;
}

body.login-svg-mobile #login-midground {
  opacity: 0.7;
}

.svg-holo-panel {
  animation: login-holo-scan 4.8s ease-in-out infinite;
}

@keyframes login-holo-scan {
  0%, 100% { opacity: 0.42; }
  50% { opacity: 0.72; }
}

body.login-svg-reduced .svg-holo-panel,
body.login-svg-reduced .svg-parallax-layer {
  animation: none !important;
  transform: none !important;
}

body.login-svg-reduced #login-midground {
  opacity: 0.55;
}

body.login-svg-reduced #login-vignette {
  opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
  .svg-holo-panel {
    animation: none;
  }
  .svg-parallax-layer {
    transform: none !important;
  }
}

/* Soft CSS ground band — sand plate upgrade (keeps QR readable) */
body.wa-login-kasi::after {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: min(36vh, 280px);
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 70% 45% at 50% 92%, rgba(201, 162, 39, 0.14) 0%, transparent 70%),
    linear-gradient(
      90deg,
      rgba(232, 60, 140, 0.12) 0%,
      transparent 28%,
      transparent 72%,
      rgba(62, 200, 240, 0.12) 100%
    ),
    linear-gradient(
      180deg,
      transparent 0%,
      rgba(8, 4, 16, 0.18) 40%,
      rgba(42, 28, 18, 0.28) 72%,
      rgba(4, 2, 10, 0.55) 100%
    );
}

/* Mobile: full-width plate so magenta/cyan neon edges stay visible (no side crop).
   Tall viewports: layer a soft cover fill above the grounded plate. */
@media (max-width: 720px) {
  body.wa-login-kasi {
    background-attachment: scroll, scroll, scroll;
    background-image:
      linear-gradient(
        180deg,
        rgba(10, 6, 20, 0.55) 0%,
        rgba(8, 2, 18, 0.2) 38%,
        rgba(6, 4, 14, 0.15) 100%
      ),
      url('/visual-kit/nightmare/bg-arena-platform.jpg?v=20261027wizard2'),
      url('/visual-kit/nightmare/bg-arena-platform.jpg?v=20261027wizard2');
    /* Layer2 cover fills height; layer3 100%-width plate grounded — neon L/R preserved on plate */
    background-size: cover, cover, 100% auto;
    background-position: center bottom, center 62%, center bottom;
  }
  #login-atmosphere {
    background-image:
      url('/visual-kit/nightmare/bg-arena-platform.jpg?v=20261027wizard2'),
      url('/visual-kit/nightmare/bg-arena-platform.jpg?v=20261027wizard2');
    background-size: cover, 100% auto;
    background-position: center 62%, center bottom;
  }
  /* Compact shell so QR stays scannable above the fold */
  .shell {
    width: min(740px, calc(100% - 1.1rem));
    margin: 0.65rem auto 0.85rem;
  }
  .card {
    margin-top: 0.75rem !important;
    padding: 0.85rem 0.9rem 1rem !important;
  }
  .link-howto {
    margin-top: 0.45rem;
    padding: 0.45rem 0.65rem;
  }
  /* Collapse long howto — one-line summary; expand via details */
  .link-howto ol.steps {
    display: none;
  }
  .link-howto::after {
    content: 'WhatsApp → Settings → Linked devices → Link a device → scan QR.';
    display: block;
    margin-top: 0.3rem;
    font-size: 0.82rem;
    color: var(--ink-soft, #d4c0e0);
    line-height: 1.35;
  }
  .qr-stage {
    width: min(220px, 72vw);
    margin-top: 0.7rem !important;
    padding: 10px !important;
  }
  .tokoloshe-twin-panel {
    margin-top: 0.65rem;
    padding: 0.4rem 0.55rem;
  }
  .companion-caption {
    margin-bottom: 0.75rem;
    padding-bottom: env(safe-area-inset-bottom, 0);
    font-size: 0.7rem;
  }
  #login-tokoloshe {
    overflow: visible;
  }
  .foot-links {
    display: none;
  }
}

@media (max-width: 420px) {
  body.wa-login-kasi h1 {
    font-size: 1.15rem !important;
    margin: 0.4rem 0 0.35rem !important;
  }
  body.wa-login-kasi .lede {
    font-size: 0.88rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .qr-stage {
    width: min(200px, 68vw);
  }
}

#login-tokoloshe {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: visible;
}

#login-tokoloshe canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.shell {
  position: relative;
  z-index: 2;
}

/* Glass card over cosmic night — readable QR, brand CTAs intact */
.card {
  position: relative;
  z-index: 3;
  backdrop-filter: blur(12px) saturate(1.15);
  -webkit-backdrop-filter: blur(12px) saturate(1.15);
  background: var(--card-glass);
  border: 1px solid var(--card-rim);
  color: #f2e8f4;
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.45),
    0 0 40px rgba(232, 60, 140, 0.12),
    inset 0 1px 0 rgba(255, 200, 240, 0.08);
  transition:
    border-color 0.35s ease,
    box-shadow 0.35s ease,
    transform 0.35s ease;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(
      ellipse 95% 55% at 50% -8%,
      rgba(232, 60, 140, 0.14) 0%,
      transparent 58%
    ),
    radial-gradient(
      ellipse 50% 40% at 100% 100%,
      rgba(80, 40, 160, 0.1) 0%,
      transparent 55%
    );
  z-index: 0;
}

.card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background-image:
    radial-gradient(rgba(232, 60, 140, 0.04) 1px, transparent 1px);
  background-size: 18px 18px;
  opacity: 0.35;
  z-index: 0;
  mask-image: linear-gradient(180deg, rgba(0,0,0,0.4) 0%, transparent 70%);
}

.card > * {
  position: relative;
  z-index: 1;
}

body.wa-login-kasi.tok-pointer-near-ui .card {
  border-color: var(--dust-gold, #c9a227);
  box-shadow:
    0 14px 44px rgba(26, 21, 16, 0.14),
    0 0 40px rgba(232, 122, 58, 0.1);
}

body.wa-login-kasi.tok-celebrate .card {
  border-color: var(--good, #2f7a4a);
  box-shadow:
    0 14px 48px rgba(26, 21, 16, 0.12),
    0 0 48px rgba(47, 122, 74, 0.18);
  animation: tok-celebrate-pulse 1.2s ease-out;
}

@keyframes tok-celebrate-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

/* QR stays above companion — high contrast for scan */
.qr {
  position: relative;
  z-index: 5;
  isolation: isolate;
  background: #fff !important;
  box-shadow:
    0 0 0 3px #fff,
    0 0 0 5px rgba(26, 21, 16, 0.85),
    0 8px 28px rgba(26, 21, 16, 0.18);
  transition: box-shadow 0.25s ease, transform 0.2s ease, opacity 0.3s ease;
  cursor: pointer;
}

.qr:hover,
.qr:focus-visible,
body.wa-login-kasi.tok-pointer-near-qr .qr {
  box-shadow:
    0 0 0 3px #fff,
    0 0 0 5px var(--neon-soft, #e87a3a),
    0 10px 32px rgba(26, 21, 16, 0.22);
  outline: 2px solid var(--neon-soft, #e87a3a);
  outline-offset: 2px;
}

.tokoloshe-fallback-login {
  position: fixed;
  right: 6%;
  bottom: 12%;
  z-index: 3;
  width: min(180px, 28vw);
  pointer-events: none;
  filter: drop-shadow(0 12px 24px rgba(26, 21, 16, 0.25));
}

.tokoloshe-fallback-login img {
  width: 100%;
  height: auto;
  display: block;
  background: transparent;
}

.tokoloshe-fallback-login.tokoloshe-fallback-live {
  pointer-events: auto;
  cursor: pointer;
}

.tokoloshe-fallback-login.tokoloshe-fallback-live img {
  animation: tok-fallback-breathe 2.4s ease-in-out infinite;
}

.tokoloshe-fallback-login.tokoloshe-fallback-live[data-anim='walk'] img,
.tokoloshe-fallback-login.tokoloshe-fallback-live[data-anim='leap'] img,
.tokoloshe-fallback-login.tokoloshe-fallback-live[data-anim='pounce'] img {
  animation: tok-fallback-hop 0.55s ease-in-out infinite;
}

.tokoloshe-fallback-login.tokoloshe-fallback-live[data-anim='crouch'] img {
  animation: tok-fallback-crouch 1.2s ease-in-out infinite;
}

@keyframes tok-fallback-breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-4px) scale(1.02); }
}
@keyframes tok-fallback-hop {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes tok-fallback-crouch {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.92) translateY(4px); }
}

@media (max-width: 720px) {
  .tokoloshe-fallback-login.tokoloshe-fallback-live img {
    max-width: 120px;
  }
}

body.wa-login-kasi.tok-pointer-near-ui #status {
  text-shadow: 0 0 12px rgba(232, 122, 58, 0.25);
}

body.wa-login-kasi.tok-celebrate .status.connected,
body.wa-login-kasi.tok-celebrate .status.ready {
  color: var(--good, #2f7a4a);
}

body.wa-login-kasi.tok-shake .card {
  animation: tok-shake 0.45s ease;
}

@keyframes tok-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@media (prefers-reduced-motion: reduce) {
  body.wa-login-kasi.tok-shake .card,
  body.wa-login-kasi.tok-celebrate .card,
  body.wa-login-kasi.tok-celebrate .status.connected,
  body.wa-login-kasi.tok-celebrate .status.ready {
    animation: none;
  }
  .tokoloshe-fallback-login.tokoloshe-fallback-live img {
    animation: none;
  }
}

.qr:focus-visible {
  outline: 2px solid var(--neon-soft, #e87a3a);
  outline-offset: 3px;
}

@media (hover: hover) {
  .qr:hover {
    transform: none;
  }
}

.qr-stage {
  position: relative;
  z-index: 6;
}

/* Speech bubble — dark glass over nebula; z above content, below flag rail (28) for clicks */
.tokoloshe-bubble {
  position: fixed;
  z-index: 26;
  max-width: min(260px, calc(100vw - 1.5rem));
  padding: 0.75rem 1rem 0.85rem;
  border-radius: 0;
  background: rgba(18, 10, 28, 0.92);
  border: 1px solid rgba(232, 60, 140, 0.4);
  color: #f2e8f4;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.42;
  letter-spacing: 0.01em;
  box-shadow:
    0 14px 36px rgba(26, 21, 16, 0.16),
    0 0 24px rgba(232, 122, 58, 0.08);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.96);
  transition:
    opacity 0.28s ease,
    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.2s ease,
    box-shadow 0.2s ease;
  cursor: pointer;
  will-change: opacity, transform;
}

.tokoloshe-bubble::after {
  content: '';
  position: absolute;
  bottom: -9px;
  left: 42%;
  width: 16px;
  height: 16px;
  background: inherit;
  border-right: 1px solid var(--line, #d4c4b0);
  border-bottom: 1px solid var(--line, #d4c4b0);
  transform: rotate(45deg);
  box-shadow: 3px 3px 10px rgba(26, 21, 16, 0.1);
}

/* Bubble above twin: caret points down (default). Below twin: flip caret up. */
.tokoloshe-bubble.place-below::after,
.tokoloshe-bubble:not(.place-above).place-below::after {
  bottom: auto;
  top: -9px;
  border-right: none;
  border-bottom: none;
  border-left: 1px solid var(--line, #d4c4b0);
  border-top: 1px solid var(--line, #d4c4b0);
  box-shadow: -2px -2px 8px rgba(26, 21, 16, 0.1);
}

.tokoloshe-bubble.place-above::after {
  bottom: -9px;
  top: auto;
  border-left: none;
  border-top: none;
  border-right: 1px solid var(--line, #d4c4b0);
  border-bottom: 1px solid var(--line, #d4c4b0);
}

.tokoloshe-bubble.tok-bubble-left::after {
  left: 22%;
}

.tokoloshe-bubble.tok-bubble-right::after {
  left: auto;
  right: 22%;
}

.tokoloshe-bubble.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.tokoloshe-bubble:not(.show) {
  transform: translateY(10px) scale(0.96);
}

@media (prefers-reduced-motion: reduce) {
  .tokoloshe-bubble {
    transition: opacity 0.15s ease;
    will-change: auto;
  }
  .tokoloshe-bubble:not(.show) {
    transform: none;
  }
  .tokoloshe-bubble.show {
    transform: none;
  }
}

.tokoloshe-bubble.show:hover,
.tokoloshe-bubble.show:focus-visible {
  border-color: var(--dust-gold, #c9a227);
  box-shadow:
    0 10px 28px rgba(26, 21, 16, 0.14),
    0 0 28px rgba(240, 196, 58, 0.18);
  outline: none;
}

.tokoloshe-bubble.celebrate {
  border-color: var(--good, #2f7a4a);
  box-shadow:
    0 10px 28px rgba(26, 21, 16, 0.14),
    0 0 28px rgba(47, 122, 74, 0.2);
}

.tokoloshe-twin-panel {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0;
  border: 1px solid rgba(232, 60, 140, 0.35);
  background: rgba(12, 6, 22, 0.75);
  color: #f2e8f4;
  font-size: 0.85rem;
  transition:
    border-color 0.25s ease,
    box-shadow 0.25s ease,
    transform 0.2s ease,
    background 0.25s ease;
  cursor: pointer;
}

.tokoloshe-twin-panel:hover,
.tokoloshe-twin-panel:focus-visible {
  border-color: var(--dust-gold, #c9a227);
  box-shadow: 0 0 18px rgba(232, 122, 58, 0.12);
  background: #fff;
  transform: translateY(-1px);
  outline: none;
}

.tokoloshe-twin-panel:focus-visible {
  outline: 2px solid var(--neon-soft, #e87a3a);
  outline-offset: 2px;
}

.tokoloshe-twin-panel strong {
  display: block;
  color: var(--neon-soft, #e87a3a);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tokoloshe-twin-portrait {
  width: 56px;
  height: 56px;
  border-radius: 0;
  object-fit: cover;
  object-position: 0 0;
  background: var(--paper-deep, #e8d4b8);
  border: 1px solid var(--line, #d4c4b0);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.tokoloshe-twin-panel:hover .tokoloshe-twin-portrait {
  border-color: var(--neon-soft, #e87a3a);
  box-shadow: 0 0 10px rgba(232, 122, 58, 0.2);
}

#tokoloshe-mute[aria-pressed='true'] {
  border-color: var(--line, #d4c4b0);
  color: var(--muted, #7a6a58);
}

body.wa-login-kasi.tok-kb-focus .card {
  border-color: var(--dust-gold, #c9a227);
}

.companion-caption {
  position: relative;
  z-index: 2;
  width: min(740px, calc(100% - 2rem));
  margin: 0 auto 2rem;
  font-size: 0.78rem;
  color: rgba(220, 190, 230, 0.72);
  line-height: 1.5;
}

/* Twin mood chip — live status/anim sync */
.tokoloshe-twin-panel[data-mood='joyful'] {
  border-color: rgba(47, 122, 74, 0.55);
  box-shadow: 0 0 18px rgba(47, 122, 74, 0.18);
}
.tokoloshe-twin-panel[data-mood='wary'] {
  border-color: rgba(200, 80, 80, 0.5);
}
.tokoloshe-twin-panel[data-mood='focused'],
.tokoloshe-twin-panel[data-mood='curious'] {
  border-color: rgba(232, 60, 140, 0.4);
}
.tokoloshe-twin-panel[data-mood='playful'],
.tokoloshe-twin-panel[data-mood='active'] {
  border-color: rgba(62, 200, 240, 0.45);
  box-shadow: 0 0 16px rgba(62, 200, 240, 0.12);
}
.tokoloshe-twin-panel[data-mood='drowsy'] {
  border-color: rgba(120, 100, 140, 0.45);
}
