/* Touch-up layer for every page: small motion + quality-of-life. Loaded after each page's own CSS.
   Everything here is optional polish; the pages work the same without it. */
/* One motion system for the whole site: 3 speeds, 2 curves (+ a spring for presses only).
   ease = fast start, gentle settle (expo out). ease-io = for loops that come and go. */
:root {
  --tu-ease: cubic-bezier(.16, 1, .3, 1);
  --tu-ease-io: cubic-bezier(.65, 0, .35, 1);
  --tu-spring: cubic-bezier(.34, 1.45, .64, 1);
  --tu-fast: 140ms; --tu-med: 260ms; --tu-slow: 560ms;
}
@property --ga { syntax: "<number>"; inherits: false; initial-value: 0; }

/* Page-to-page fade (Chrome/Edge; other browsers just navigate normally) */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--tu-med); animation-timing-function: var(--tu-ease); }

/* Lenis smooth scroll (desktop mouse only, added by touchup.js) */
html.lenis, html.lenis body { height: auto; }
html.lenis { scrollbar-gutter: stable; }   /* no page jump when a pop-up pauses scrolling */
.lenis.lenis-smooth { scroll-behavior: auto !important; }
.lenis.lenis-smooth [data-lenis-prevent] { overscroll-behavior: contain; }
.lenis.lenis-stopped { overflow: clip; }

@media (prefers-reduced-motion: no-preference) {
  html:not(.lenis) { scroll-behavior: smooth; }

  /* Entrance: header settles in, home logo ball drops and spins into place */
  .wrap > .topbar, .wrap > .hero > h1, .wrap > .hero > p { animation: tu-rise var(--tu-slow) var(--tu-ease) both; }
  .wrap > .hero > h1 { animation-delay: 70ms; }
  .wrap > .hero > p { animation-delay: 140ms; }
  .wrap > .hero > img { animation: tu-ball .9s var(--tu-spring) both; }
  @keyframes tu-rise { from { opacity: 0; transform: translateY(10px); filter: blur(4px); } }
  @keyframes tu-ball { from { opacity: 0; transform: translateY(-36px) rotate(-180deg) scale(.75); } }

  /* Scroll reveal: plays once, only for things that start below the screen (JS adds the classes) */
  .tu-rv:not(#_) { opacity: 0; transform: translateY(12px) scale(.985); transition: none; }
  .tu-rv.tu-in:not(#_) { opacity: 1; transform: none;
    transition: opacity var(--tu-slow) var(--tu-ease), transform var(--tu-slow) var(--tu-ease); transition-delay: var(--tu-d, 0ms); }
  /* Cards redrawn in place (search, mutation tabs) fade up quickly instead of popping */
  .tu-swap { animation: tu-swap var(--tu-med) var(--tu-ease) both; animation-delay: var(--tu-d, 0ms); }
  @keyframes tu-swap { from { opacity: 0; transform: translateY(6px) scale(.98); } }

  /* Everything you hover or press uses the same timing */
  .grid .card, .tool, .gcard, .tcard, .bcard, .urow, .empty-slot, .upd, .lp-card {
    transition: transform var(--tu-med) var(--tu-ease), box-shadow var(--tu-med) var(--tu-ease), opacity var(--tu-fast) ease,
      background-color var(--tu-med) ease, border-color var(--tu-med) ease, filter var(--tu-med) ease; }
  .pill-btn, .opt, .jump-btn, .tab, .chip-b, .bt, .mode, .go, .more, .help-btn, .tip-btn, .res-more, .trait-all, .toast-undo, .close, .tu-top, .slot-x {
    transition: transform var(--tu-med) var(--tu-spring), box-shadow var(--tu-med) var(--tu-ease), filter var(--tu-med) ease,
      opacity var(--tu-fast) ease, background-color var(--tu-med) ease, border-color var(--tu-med) ease, color var(--tu-fast) ease; }
  :is(.go, .pill-btn, .help-btn, .tip-btn, .more, .jump-btn, .mode, .bt, .chip-b, .send, .tu-top, .opt, .tab, .close, .res-more, .trait-all):active {
    transition-duration: 70ms; transition-timing-function: ease-out; }

  /* Buttons: the shine stripes stay put and a soft light follows the mouse instead */
  .pill-btn::after, .tab::after, .opt::after, .jump-btn::after {
    transform: none !important;
    background:
      radial-gradient(110px circle at var(--bx, 50%) var(--by, 50%), rgba(255,255,255, calc(.42 * var(--ga))), transparent 70%),
      repeating-linear-gradient(115deg, transparent 0 18px, rgba(255,255,255,.12) 18px 26px, transparent 26px 44px);
    transition: --ga var(--tu-med) var(--tu-ease); }
  :is(.pill-btn, .tab, .opt, .jump-btn):hover::after { --ga: 1; }
  /* Same light on the buttons that had no shine layer (home, crates, small buttons) */
  :is(.go, .help-btn, .tip-btn, .more, .chip-b, .bt, .mode, .res-more, .trait-all) { position: relative; isolation: isolate; overflow: hidden; }
  :is(.go, .help-btn, .tip-btn, .more, .chip-b, .bt, .mode, .res-more, .trait-all)::after {
    content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; border-radius: inherit;
    background: radial-gradient(120px circle at var(--bx, 50%) var(--by, 50%), rgba(255,255,255, calc(.42 * var(--ga))), transparent 70%);
    transition: --ga var(--tu-med) var(--tu-ease); }
  :is(.go, .help-btn, .tip-btn, .more, .chip-b, .bt, .mode, .res-more, .trait-all):hover::after, a.tool:hover .go::after { --ga: 1; }

  /* Banner star: a slow breath with a rare soft sparkle (timing varies per star, set in JS) */
  .flare { transform-origin: 50% 50%; animation: tu-breathe var(--fd, 7s) var(--tu-ease-io) var(--fdl, 0s) infinite; }
  @keyframes tu-breathe {
    0%, 100% { opacity: .82; transform: scale(.96); filter: brightness(1); }
    45% { opacity: 1; transform: scale(1); filter: brightness(1.12); }
    88% { opacity: .9; transform: scale(.98); filter: brightness(1.05); }
    92% { opacity: 1; transform: scale(1.07); filter: brightness(1.45); }
    96% { opacity: .9; transform: scale(.99); filter: brightness(1.08); }
  }

  /* Banner light: a soft, blurred sheen that fades in and out. Each banner has its own timing and it only runs on screen */
  .tu-shine { position: absolute; inset: -30% -10%; z-index: 1; pointer-events: none; opacity: 0;
    background: linear-gradient(100deg, transparent 34%, rgba(190,225,255,.10) 42%, rgba(235,246,255,.34) 49%, rgba(255,255,255,.42) 50%, rgba(235,246,255,.34) 51%, rgba(190,225,255,.10) 58%, transparent 66%);
    filter: blur(5px); mix-blend-mode: screen; transform: translateX(-75%) skewX(-8deg);
    animation: tu-sweep var(--sd, 11s) var(--tu-ease-io) var(--sdl, 1s) infinite; animation-play-state: paused; }
  .tu-on > .tu-shine { animation-play-state: running; }
  @keyframes tu-sweep {
    0% { opacity: 0; transform: translateX(-75%) skewX(-8deg); }
    3% { opacity: 1; }
    17% { opacity: 1; }
    20%, 100% { opacity: 0; transform: translateX(75%) skewX(-8deg); }
  }

  /* Background: light rays drift very slowly; the balls roll with your scroll instead of spinning forever */
  body::after { animation: tu-rays 38s var(--tu-ease-io) infinite alternate; transform-origin: 50% 0; }
  @keyframes tu-rays { from { transform: rotate(-1.2deg) scale(1.04); opacity: .85; } to { transform: rotate(1.2deg) scale(1.04); opacity: 1; } }
  .bg-balls img { animation: none !important; will-change: transform; }
  .bg-balls .b1 { transform: translate3d(0, calc(var(--sy, 0) * -0.06px), 0) rotate(calc(var(--sy, 0) * 0.03deg)); }
  .bg-balls .b2 { transform: translate3d(0, calc(var(--sy, 0) * -0.12px), 0) rotate(calc(var(--sy, 0) * -0.045deg)); }
  .bg-balls .b3 { transform: translate3d(0, calc(var(--sy, 0) * -0.2px), 0) rotate(calc(var(--sy, 0) * 0.08deg)); }

  /* Pop-ups grow out of the button you pressed (JS sets transform-origin) and shrink back into it */
  dialog { opacity: 0; transform: scale(.9);
    transition: opacity var(--tu-med) var(--tu-ease), transform var(--tu-slow) var(--tu-ease), overlay var(--tu-med) allow-discrete, display var(--tu-med) allow-discrete; }
  dialog[open] { opacity: 1; transform: none; }
  @starting-style { dialog[open] { opacity: 0; transform: scale(.9); } }
  dialog:not([open]) { transition-duration: var(--tu-fast), var(--tu-med), var(--tu-med), var(--tu-med); }
  dialog::backdrop { opacity: 0; transition: opacity var(--tu-med) ease, overlay var(--tu-med) allow-discrete, display var(--tu-med) allow-discrete; }
  dialog[open]::backdrop { opacity: 1; }
  @starting-style { dialog[open]::backdrop { opacity: 0; } }

  /* FAQ bot: new messages slide in from their side */
  .msg { animation: tu-msg var(--tu-med) var(--tu-ease) both; }
  .msg.me { animation-name: tu-msg-me; }
  @keyframes tu-msg { from { opacity: 0; transform: translate(-10px, 6px); } }
  @keyframes tu-msg-me { from { opacity: 0; transform: translate(10px, 6px); } }

  /* Home tool cards: icon tilts on hover */
  .tool .ic { transition: transform var(--tu-slow) var(--tu-spring); }
  a.tool:hover .ic, a.tool:focus-visible .ic { transform: rotate(-6deg) scale(1.08); }

  /* Result settles with one short pulse after you stop changing inputs */
  .tu-bump { animation: tu-bump 220ms var(--tu-ease); }
  @keyframes tu-bump { 35% { transform: scale(1.04); } }

  /* Toast slides with the same curve */
  .toast { transition: opacity var(--tu-med) var(--tu-ease), transform var(--tu-slow) var(--tu-ease) !important; }
}

/* Unit cards tilt toward the pointer like trading cards (JS adds .tu-tilt; mouse only, never with reduced motion).
   A soft glare follows the pointer; cards showing a mutation other than Normal get a rainbow foil sheen. */
.tu-tilt { transition: transform .12s ease-out, box-shadow .2s ease !important; will-change: transform; }
.tu-glare { position: absolute; inset: 0; z-index: 4; pointer-events: none; border-radius: inherit; opacity: 0; transition: opacity .3s ease;
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 50%), rgba(255,255,255,.34), rgba(255,255,255,0) 55%); mix-blend-mode: screen; }
.tu-tilt > .tu-glare { opacity: 1; }
.tu-holo > .tu-glare {
  background:
    radial-gradient(circle at var(--gx, 50%) var(--gy, 50%), rgba(255,255,255,.34), rgba(255,255,255,0) 50%),
    linear-gradient(115deg, transparent 22%, rgba(255,95,200,.34) 36%, rgba(95,215,255,.34) 50%, rgba(150,255,120,.34) 64%, transparent 78%);
  background-size: 100% 100%, 260% 100%; background-position: 0 0, var(--gx, 50%) 0; mix-blend-mode: screen; }

/* Buttons feel pressed (all motion settings: it's feedback, not decoration) */
:is(.go, .pill-btn, .help-btn, .more, .jump-btn, .mode, .bt, .chip-b, .send, .tu-top):active { transform: translateY(2px) scale(.98); }

/* "Last used" tag on the home tool you opened last */
.tu-last { position: absolute; top: 16px; right: 16px; padding: 3px 10px; border-radius: 8px; border: 2px solid #03071a;
  background: linear-gradient(180deg, #b9f75a, #6fd12a); color: #03071a; font-size: 13px; font-weight: 700; }

/* "New since your last visit" */
.tu-news-chip { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; padding: 6px 14px; border-radius: 999px;
  border: 2px solid rgba(67,240,92,.55); background: rgba(67,240,92,.12); color: #b9f75a; font-weight: 600; font-size: 15px; text-decoration: none; }
.tu-news-chip i { width: 8px; height: 8px; border-radius: 50%; background: #43f05c; box-shadow: 0 0 10px #43f05c; }
.tu-news-chip:hover, .tu-news-chip:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.upd.tu-unseen { border-color: #6fd12a; box-shadow: 0 3px 0 #03071a, 0 0 16px rgba(111,209,42,.35); }
#updates { scroll-margin-top: 50px; }

/* Back to top */
.tu-top { position: fixed; right: 16px; bottom: 16px; z-index: 40; width: 50px; height: 50px; border-radius: 14px; cursor: pointer;
  border: 3px solid #03071a; color: #fff; display: grid; place-items: center;
  background: linear-gradient(180deg, #6fb0ff, #2f6fe8 55%, #1d4fc4); box-shadow: 0 4px 0 #03071a, inset 0 2px 0 rgba(255,255,255,.4);
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s ease, transform .25s var(--tu-ease); }
.tu-top.show { opacity: 1; transform: none; pointer-events: auto; }
.tu-top:hover, .tu-top:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.tu-top svg { width: 22px; height: 22px; }
body:has(dialog[open]) .tu-top { display: none; }
/* Calculator on phones: the result bar sits at the bottom, so lift the button above it */
@media (max-width: 760px) { .tu-top { bottom: 20px; width: 46px; height: 46px; } }

/* Keyboard hint inside search boxes */
.tu-kbd { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); pointer-events: none;
  font: 700 12px/1 ui-monospace, Consolas, monospace; color: #93a6d6; border: 1.5px solid #3a5290; border-radius: 6px; padding: 4px 7px; }
@media (hover: none) { .tu-kbd { display: none; } }

/* ---------- Phones and tablets: same look, lighter on the GPU ----------
   1) The page gradient no longer uses background-attachment: fixed (Android repaints it on every
      scroll frame); it sits on its own fixed layer under the 3D canvas instead.
   2) The film grain stops blending (overlay) with the moving canvas; plain low opacity looks the same.
   3) Looping banner light and star drop blur, blend and filter, which repaint every frame. */
@media (pointer: coarse), (max-width: 700px) {
  html.pz-on body { background: #040a26; }
  html.pz-on body::after {
    display: block; z-index: -1; animation: none; transform: none;
    -webkit-mask-image: none; mask-image: none;
    background:
      radial-gradient(ellipse 85% 75% at 50% 45%, transparent 40%, rgba(1,3,16,.85) 100%),
      radial-gradient(760px 620px at 50% 38%, rgba(60,140,255,.55), rgba(30,80,230,.18) 55%, transparent 75%),
      radial-gradient(420px 360px at 50% 34%, rgba(150,210,255,.30), transparent 70%),
      linear-gradient(180deg, #0f2a86 0%, #0a1d66 35%, #07154a 70%, #040a26 100%);
  }
  body { background-attachment: scroll; }
  body::before { mix-blend-mode: normal; opacity: .07; transform: translateZ(0); }
  .tu-shine { filter: none; mix-blend-mode: normal; will-change: transform, opacity; }
  @keyframes tu-breathe {
    0%, 100% { opacity: .82; transform: scale(.96); }
    45% { opacity: 1; transform: scale(1); }
    88% { opacity: .9; transform: scale(.98); }
    92% { opacity: 1; transform: scale(1.07); }
    96% { opacity: .9; transform: scale(.99); }
  }
  .flare { will-change: transform, opacity; }
  dialog::backdrop { backdrop-filter: none; background: rgba(3,7,26,.8); }
}

/* ----- Scrolling stays where the mouse is (16 Nov) -----
   While a pop-up is open the page behind it stays still (the wheel used to scroll the page underneath),
   and lists inside pop-ups (and the FAQ chat) no longer hand their leftover scroll to the page. */
html:has(dialog[open]) { overflow: hidden; scrollbar-gutter: stable; }
dialog, dialog *, .msgs { overscroll-behavior: contain; }

/* ----- Edge fades on sideways strips (16 Nov) ----- */
@property --fl { syntax: '<length>'; inherits: false; initial-value: 0px; }
@property --fr { syntax: '<length>'; inherits: false; initial-value: 0px; }
.tu-fade { --fl: 0px; --fr: 0px; transition: --fl .25s ease, --fr .25s ease;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%); }
.tu-fade-l { --fl: 56px; }
.tu-fade-r { --fr: 56px; }
@media (max-width: 480px) { .tu-fade-l { --fl: 48px; } .tu-fade-r { --fr: 56px; } }

/* ----- Lite mode (16 Nov): no 3D, no moving effects; the still background stays ----- */
html.lite .pz { display: none !important; }
html.lite *, html.lite *::before, html.lite *::after { animation: none !important; transition: none !important; }
html.lite .tu-rv { opacity: 1 !important; transform: none !important; }
html.lite .tu-shine, html.lite .tool::after { display: none !important; }

/* Switch: chunky game style, same ink outline as the other buttons */
.fx-switch { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 12px; border-radius: 12px; cursor: pointer;
  border: 3px solid #03071a; background: linear-gradient(180deg, #24407f, #13245a); color: #fff; box-shadow: 0 3px 0 #03071a;
  font: 700 14px/1 "Fredoka", system-ui, sans-serif; }
.fx-switch:hover, .fx-switch:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.fx-track { position: relative; width: 36px; height: 20px; border-radius: 999px; background: #0a1440; box-shadow: inset 0 0 0 2px #2a4a92; }
.fx-knob { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #a9bae6; transition: transform .2s cubic-bezier(.2,.9,.25,1.15), background .2s; }
.fx-switch[aria-pressed="true"] .fx-track { background: #2f6d12; box-shadow: inset 0 0 0 2px #6fd12a; }
.fx-switch[aria-pressed="true"] .fx-knob { transform: translateX(16px); background: #b9f75a; }
.fx-state { min-width: 22px; color: #a9bae6; font-weight: 600; }
.fx-switch[aria-pressed="true"] .fx-state { color: #b9f75a; }

/* Bottom-left on bigger screens (back-to-top sits bottom-right); phones use the footer switch */
.fx-float { position: fixed; left: 16px; bottom: 16px; z-index: 40; }
@media (max-width: 760px) { .fx-float { display: none; } }
.fx-foot { display: flex; justify-content: center; margin: 0 0 10px; }

/* One-time offer */
.fx-toast { position: fixed; left: 50%; bottom: 80px; z-index: 60; transform: translateX(-50%); width: min(520px, calc(100% - 32px));
  display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px; border-radius: 14px; color: #dbe4ff;
  background: #0c1745; border: 3px solid #4f8cff; box-shadow: 0 0 0 3px #03071a, 0 6px 0 3px #03071a;
  font: 500 15px/1.35 "Fredoka", system-ui, sans-serif; }
.fx-toast span { flex: 1; min-width: 0; }
.fx-toast b { color: #fff; }
.fx-toast button { cursor: pointer; border: 3px solid #03071a; border-radius: 10px; font: 700 15px "Fredoka", system-ui, sans-serif; }
.fx-yes { padding: 8px 14px; color: #fff; background: linear-gradient(180deg, #b9f75a, #6fd12a 55%, #3f9a12); -webkit-text-stroke: 2px #03071a; paint-order: stroke fill; }
.fx-no { width: 36px; height: 36px; color: #a9bae6; background: #13245a; }
.fx-toast button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
