/* ============================================================
   Paper Desk - motion
   Everything here runs only when <html data-motion="on">.
   The page sets that from the device setting or the Animations switch in Profile.
   ============================================================ */
html[data-motion="on"] {
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --out-expo: cubic-bezier(.16, 1, .3, 1);
}

/* ---------- 1. Page entrance: everything arrives in a short, staggered sequence ---------- */
@keyframes m-rise   { from { opacity: 0; transform: translateY(34px) scale(.975); filter: blur(5px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes m-left   { from { opacity: 0; transform: translateX(-26px); } to { opacity: 1; transform: none; } }
@keyframes m-right  { from { opacity: 0; transform: translateX(34px); } to { opacity: 1; transform: none; } }
@keyframes m-pop    { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
@keyframes m-up     { from { opacity: 0; transform: translateY(100%); } to { opacity: 1; transform: none; } }

html[data-motion="on"] .main > * { animation: m-rise .8s var(--out-expo) backwards; }
html[data-motion="on"] .main > *:nth-child(2) { animation-delay: .08s; }
html[data-motion="on"] .main > *:nth-child(3) { animation-delay: .16s; }
html[data-motion="on"] .main > *:nth-child(4) { animation-delay: .24s; }
html[data-motion="on"] .main > *:nth-child(5) { animation-delay: .32s; }
html[data-motion="on"] .main > *:nth-child(n+6) { animation-delay: .4s; }
html[data-motion="on"] .main > .passbook { animation: none; }

/* Passbook cells drop in one after another */
html[data-motion="on"] .passbook .pb-cell { animation: m-rise .7s var(--out-expo) backwards; }
html[data-motion="on"] .passbook .pb-cell:nth-child(1) { animation-delay: .15s; }
html[data-motion="on"] .passbook .pb-cell:nth-child(2) { animation-delay: .25s; }
html[data-motion="on"] .passbook .pb-cell:nth-child(3) { animation-delay: .35s; }
html[data-motion="on"] .passbook .pb-cell:nth-child(4) { animation-delay: .45s; }

/* Two-column panels arrive from opposite sides */
html[data-motion="on"] .two-col > .panel:nth-child(odd)  { animation: m-left .8s var(--out-expo) .2s backwards; }
html[data-motion="on"] .two-col > .panel:nth-child(even) { animation: m-right .8s var(--out-expo) .3s backwards; }
html[data-motion="on"] .trade > .chain-panel { animation: m-left .8s var(--out-expo) .1s backwards; }
html[data-motion="on"] .trade > .order-panel { animation: m-right .8s var(--out-expo) .25s backwards; }

/* Rows inside lists and tables */
html[data-motion="on"] :is(.activity, .brk, .notes, .hist, .ord-list, .day-list) > li { animation: m-left .55s var(--out-expo) backwards; }
html[data-motion="on"] :is(.activity, .brk, .notes, .hist, .ord-list, .day-list) > li:nth-child(1) { animation-delay: .35s; }
html[data-motion="on"] :is(.activity, .brk, .notes, .hist, .ord-list, .day-list) > li:nth-child(2) { animation-delay: .42s; }
html[data-motion="on"] :is(.activity, .brk, .notes, .hist, .ord-list, .day-list) > li:nth-child(3) { animation-delay: .49s; }
html[data-motion="on"] :is(.activity, .brk, .notes, .hist, .ord-list, .day-list) > li:nth-child(4) { animation-delay: .56s; }
html[data-motion="on"] :is(.activity, .brk, .notes, .hist, .ord-list, .day-list) > li:nth-child(5) { animation-delay: .63s; }
html[data-motion="on"] :is(.activity, .brk, .notes, .hist, .ord-list, .day-list) > li:nth-child(n+6) { animation-delay: .7s; }
html[data-motion="on"] .tbl tbody tr { animation: m-left .5s var(--out-expo) backwards; }
html[data-motion="on"] .tbl tbody tr:nth-child(1) { animation-delay: .35s; }
html[data-motion="on"] .tbl tbody tr:nth-child(2) { animation-delay: .42s; }
html[data-motion="on"] .tbl tbody tr:nth-child(3) { animation-delay: .49s; }
html[data-motion="on"] .tbl tbody tr:nth-child(4) { animation-delay: .56s; }
html[data-motion="on"] .tbl tbody tr:nth-child(n+5) { animation-delay: .63s; }
html[data-motion="on"] .cal-day { animation: m-pop .5s var(--spring) backwards; }
html[data-motion="on"] .cal-day:nth-child(7n+9)  { animation-delay: .35s; }
html[data-motion="on"] .cal-day:nth-child(7n+10) { animation-delay: .41s; }
html[data-motion="on"] .cal-day:nth-child(7n+11) { animation-delay: .47s; }
html[data-motion="on"] .cal-day:nth-child(7n+12) { animation-delay: .53s; }
html[data-motion="on"] .cal-day:nth-child(7n+13) { animation-delay: .59s; }
html[data-motion="on"] .cal-day:nth-child(7n+14) { animation-delay: .65s; }
html[data-motion="on"] .cal-day:nth-child(7n+15) { animation-delay: .71s; }

/* Sidebar and tab bar */
html[data-motion="on"] .brand { animation: m-pop .7s var(--spring) backwards; }
html[data-motion="on"] .side-nav .nav-link { animation: m-left .6s var(--out-expo) backwards; }
html[data-motion="on"] .side-nav > :nth-child(1) { animation-delay: .1s; }
html[data-motion="on"] .side-nav > :nth-child(2) { animation-delay: .16s; }
html[data-motion="on"] .side-nav > :nth-child(3) { animation-delay: .22s; }
html[data-motion="on"] .side-nav > :nth-child(4) { animation-delay: .28s; }
html[data-motion="on"] .side-nav > :nth-child(5) { animation-delay: .34s; }
html[data-motion="on"] .side-nav > :nth-child(6) { animation-delay: .4s; }
html[data-motion="on"] .side-nav > :nth-child(n+7) { animation-delay: .46s; }
html[data-motion="on"] .side-foot { animation: m-left .7s var(--out-expo) .5s backwards; }
html[data-motion="on"] .tabbar { animation: m-up .6s var(--out-expo) .1s backwards; }

/* Sign in, sign up and the landing page */
html[data-motion="on"] .auth-main > * { animation: m-rise .8s var(--out-expo) backwards; }
html[data-motion="on"] .auth-main > *:nth-child(2) { animation-delay: .1s; }
html[data-motion="on"] .auth-main > *:nth-child(3) { animation-delay: .2s; }
html[data-motion="on"] .auth-side-inner { animation: m-right .9s var(--out-expo) .3s backwards; }
html[data-motion="on"] .field { animation: m-rise .6s var(--out-expo) backwards; }
html[data-motion="on"] .auth-main .field:nth-of-type(1) { animation-delay: .25s; }
html[data-motion="on"] .auth-main .field:nth-of-type(2) { animation-delay: .33s; }
html[data-motion="on"] .auth-main .field:nth-of-type(3) { animation-delay: .41s; }
html[data-motion="on"] .auth-main .field:nth-of-type(n+4) { animation-delay: .49s; }
html[data-motion="on"] .hero > * { animation: m-rise .9s var(--out-expo) backwards; }
html[data-motion="on"] .hero > *:nth-child(2) { animation: m-right 1s var(--out-expo) .25s backwards; }
@keyframes m-drift { to { background-position: 48px 48px; } }
html[data-motion="on"] .auth-side::before { animation: m-drift 8s linear infinite; }

/* ---------- 2. Hover and press ---------- */
html[data-motion="on"] .panel, html[data-motion="on"] .pos, html[data-motion="on"] .passbook {
  transition: transform .3s var(--out-expo), box-shadow .3s var(--out-expo), border-color .2s;
}
html[data-motion="on"] .panel:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--ink) 22%, var(--line)); }
html[data-motion="on"] .order-panel:hover, html[data-motion="on"] .chain-panel:hover { transform: none; }
html[data-motion="on"] .pos:hover { transform: translateY(-5px) rotate(-.2deg); box-shadow: var(--shadow); }
html[data-motion="on"] .passbook .pb-cell { transition: background-color .25s; }
html[data-motion="on"] .passbook .pb-cell:hover { background: var(--surface-2); }

html[data-motion="on"] .btn { transition: transform .2s var(--spring), box-shadow .25s, background-color .2s, border-color .2s; position: relative; overflow: hidden; }
html[data-motion="on"] .btn:hover { transform: translateY(-2px); }
html[data-motion="on"] .btn:active { transform: scale(.94); }
html[data-motion="on"] .btn-primary::before {
  content: ''; position: absolute; top: 0; bottom: 0; width: 46%; left: -60%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .55), transparent);
  transform: skewX(-18deg); pointer-events: none;
}
html[data-motion="on"] .btn-primary:hover::before { animation: m-shine .8s var(--out-expo); }
@keyframes m-shine { to { left: 130%; } }
html[data-motion="on"] .btn-primary:not(:disabled):hover { box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .16), 0 14px 26px -12px rgba(242, 194, 27, .95); }
.ripple { position: absolute; border-radius: 50%; background: currentColor; opacity: .22; transform: scale(0); pointer-events: none; animation: m-ripple .65s ease-out forwards; }
@keyframes m-ripple { to { transform: scale(1); opacity: 0; } }

html[data-motion="on"] .nav-link, html[data-motion="on"] .tab { transition: transform .25s var(--out-expo), background-color .2s, color .2s; }
html[data-motion="on"] .nav-link .ic, html[data-motion="on"] .tab .ic { transition: transform .35s var(--spring); }
html[data-motion="on"] .nav-link:hover { transform: translateX(6px); }
html[data-motion="on"] .nav-link:hover .ic { transform: scale(1.25) rotate(-8deg); }
html[data-motion="on"] .tab:active .ic { transform: scale(1.3) translateY(-3px); }
html[data-motion="on"] .nav-link.is-active .ic { animation: m-pop .6s var(--spring); }
html[data-motion="on"] .brand:hover .brand-mark { animation: m-wiggle .6s ease-in-out; }
@keyframes m-wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg) scale(1.08); } 75% { transform: rotate(10deg) scale(1.08); } }
html[data-motion="on"] .icon-btn { transition: transform .3s var(--spring), background-color .2s; }
html[data-motion="on"] .icon-btn:hover { transform: rotate(25deg) scale(1.12); }

html[data-motion="on"] .chip { transition: transform .2s var(--spring), background-color .15s, border-color .15s, color .15s; }
html[data-motion="on"] .chip:hover { transform: translateY(-3px); }
html[data-motion="on"] .chip.is-picked { animation: m-pop .35s var(--spring); }
html[data-motion="on"] .seg-btn { transition: background-color .25s, color .25s, transform .2s var(--spring); }
html[data-motion="on"] .seg-btn:active { transform: scale(.92); }
html[data-motion="on"] .seg-btn.is-on { animation: m-pop .3s var(--spring); }
html[data-motion="on"] .subtab { transition: color .2s, border-color .25s, transform .2s var(--spring); }
html[data-motion="on"] .subtab:hover { transform: translateY(-2px); }
html[data-motion="on"] .field input, html[data-motion="on"] .f-item input, html[data-motion="on"] .f-item select { transition: border-color .2s, box-shadow .3s var(--out-expo), transform .2s; }
html[data-motion="on"] .field input:focus { transform: translateY(-1px); }
html[data-motion="on"] .hist-item, html[data-motion="on"] .activity li, html[data-motion="on"] .brk li, html[data-motion="on"] .tbl tbody tr { transition: background-color .2s, transform .25s var(--out-expo); }
html[data-motion="on"] .hist-item:hover, html[data-motion="on"] .activity li:hover, html[data-motion="on"] .brk li:hover { transform: translateX(5px); }
html[data-motion="on"] .tbl tbody tr:hover { background: var(--surface-2); }
html[data-motion="on"] .cal-day { transition: transform .25s var(--spring), box-shadow .25s; }
html[data-motion="on"] .cal-day:hover { transform: scale(1.12); box-shadow: var(--shadow); z-index: 2; position: relative; }
html[data-motion="on"] .faq summary::after { transition: transform .3s var(--spring); }
html[data-motion="on"] .faq details[open] p { animation: m-rise .45s var(--out-expo); }

/* ---------- 3. Always-on signals that something is alive ---------- */
/* The ATM row of the option chain stays a calm, steady highlight (see app.css). A pulsing row looked like a frozen screen. */
@keyframes m-badge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
html[data-motion="on"] .badge { animation: m-badge 1.8s ease-in-out infinite; }
@keyframes m-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
html[data-motion="on"] .hero [data-ticket] { animation: m-float 5s ease-in-out infinite; }
html[data-motion="on"] .pill.is-live { animation: m-pill 3s ease-in-out infinite; }
@keyframes m-pill { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--up) 14%, transparent); } }

/* ---------- 4. Live price changes ---------- */
/* Live prices change every few seconds, so these flashes are colour-only: no movement, no scaling, no fading out.
   The chain rows are updated in place (trading.js), so a flash plays only on the price that really changed. */
@keyframes m-flash-up   { 0% { background-color: color-mix(in srgb, var(--up) 38%, transparent); } 100% { background-color: transparent; } }
@keyframes m-flash-down { 0% { background-color: color-mix(in srgb, var(--down) 38%, transparent); } 100% { background-color: transparent; } }
@keyframes m-tint-up    { 0% { color: var(--up); } }
@keyframes m-tint-down  { 0% { color: var(--down); } }
/* Option chain prices: only the number changes colour (green up, red down). The box never changes. */
@keyframes m-px-up   { 0%, 50% { color: var(--up); } }
@keyframes m-px-down { 0%, 50% { color: var(--down); } }
html[data-motion="on"] .px.fx-up { animation: m-px-up 1s ease-out; }
html[data-motion="on"] .px.fx-down { animation: m-px-down 1s ease-out; }
html[data-motion="on"] .idx-px.fx-up { animation: m-px-up 1s ease-out; }
html[data-motion="on"] .idx-px.fx-down { animation: m-px-down 1s ease-out; }
html[data-motion="on"] .pos-pnl.fx-up strong, html[data-motion="on"] .sel-price.fx-up { animation: m-tint-up .9s ease-out; }
html[data-motion="on"] .pos-pnl.fx-down strong, html[data-motion="on"] .sel-price.fx-down { animation: m-tint-down .9s ease-out; }
/* The selected contract keeps its solid highlight; a small press effect plays once when it is chosen */
@keyframes m-selpop { from { transform: scale(.94); } to { transform: none; } }
html[data-motion="on"] .chain-row .px.is-sel { animation: m-selpop .25s var(--out-expo); }
html[data-motion="on"] .chain-row .px.is-sel.fx-up, html[data-motion="on"] .chain-row .px.is-sel.fx-down { animation: none; }

/* ---------- 5. Trade ticket, cards, dialogs, messages ---------- */
html[data-motion="on"] .order-form:not([hidden]) { animation: m-right .55s var(--spring); }
html[data-motion="on"] .order-form:not([hidden]) .sel { animation: m-pop .5s var(--spring) .1s backwards; }
html[data-motion="on"] .exits { transition: background-color .3s, border-color .3s; }
html[data-motion="on"] .pos-new { animation: m-rise .7s var(--out-expo) backwards; }
html[data-motion="on"] .pos-list .pos-new:nth-child(2) { animation-delay: .1s; }
html[data-motion="on"] .pos-list .pos-new:nth-child(3) { animation-delay: .2s; }
html[data-motion="on"] .pos-list .pos-new:nth-child(4) { animation-delay: .3s; }
html[data-motion="on"] .pos-list .pos-new:nth-child(n+5) { animation-delay: .4s; }
html[data-motion="on"] .toast, html[data-motion="on"] .alert { animation: m-drop .6s var(--spring); }
@keyframes m-drop { from { opacity: 0; transform: translateY(-24px) scale(.94); } to { opacity: 1; transform: none; } }
html[data-motion="on"] .alert-error { animation: m-drop .6s var(--spring), m-shake .5s ease-in-out .25s; }
@keyframes m-shake { 0%, 100% { translate: 0; } 20% { translate: -7px; } 40% { translate: 6px; } 60% { translate: -4px; } 80% { translate: 3px; } }
html[data-motion="on"] .dlg[open] { animation: m-dlg .5s var(--spring); }
html[data-motion="on"] .dlg[open]::backdrop { animation: m-fade .3s ease-out; }
@keyframes m-dlg { from { opacity: 0; transform: translateY(40px) scale(.88); } to { opacity: 1; transform: none; } }
@keyframes m-fade { from { opacity: 0; } to { opacity: 1; } }
html[data-motion="on"] .sk { background: linear-gradient(90deg, var(--line) 0%, var(--surface-2) 50%, var(--line) 100%); background-size: 200% 100%; animation: m-shimmer 1.2s linear infinite; }
@keyframes m-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Chart and bars */
html[data-motion="on"] .eq-line { stroke-dasharray: 1; stroke-dashoffset: 1; animation: m-draw 1.6s var(--out-expo) .4s forwards; }
html[data-motion="on"] .eq-area { opacity: 0; animation: m-fade-to 1s ease-out 1.2s forwards; }
html[data-motion="on"] .eq-dot { transition: fill .15s, r .2s; }
html[data-motion="on"] .eq-dot:hover { r: 8; }
@keyframes m-draw { to { stroke-dashoffset: 0; } }
@keyframes m-fade-to { to { opacity: 1; } }
html[data-motion="on"] .capbar-track i { animation: m-grow 1.3s var(--out-expo) .4s backwards; transform-origin: left; }
@keyframes m-grow { from { transform: scaleX(0); } to { transform: none; } }

/* ---------- 6. Scroll reveal (set up by motion.js, only below the first screen) ---------- */
html[data-motion="on"].js-motion [data-reveal] { opacity: 0; transform: translateY(44px) scale(.97); transition: opacity .8s var(--out-expo), transform .8s var(--out-expo); }
html[data-motion="on"].js-motion [data-reveal].in { opacity: 1; transform: none; }

/* ---------- 7. Leaving a page ---------- */
html[data-motion="on"] .main { transition: opacity .22s ease-in, transform .22s ease-in; }
html[data-motion="on"] .main.is-leaving { opacity: 0; transform: translateY(-14px) scale(.99); }

/* ---------- 8. Success card (buy and sell) and confetti ---------- */
.done-wrap { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(8, 14, 30, .42); backdrop-filter: blur(3px); opacity: 0; transition: opacity .25s; }
.done-wrap.is-in { opacity: 1; }
.done-card { width: min(340px, calc(100vw - 40px)); padding: 28px 24px 24px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .5); transform: translateY(30px) scale(.85); transition: transform .5s var(--spring); }
.done-wrap.is-in .done-card { transform: none; }
.done-card h3 { margin: 14px 0 4px; font-size: 1.15rem; }
.done-card p { margin: 0; color: var(--ink-2); font-size: .92rem; }
.done-amt { display: block; margin-top: 8px; font-size: 1.7rem; font-weight: 600; }
.done-ring { width: 76px; height: 76px; margin: 0 auto; }
.done-ring circle { fill: color-mix(in srgb, var(--up) 14%, transparent); stroke: var(--up); stroke-width: 3; stroke-dasharray: 189; stroke-dashoffset: 189; transform-origin: center; transform: rotate(-90deg); animation: m-ring .7s var(--out-expo) .1s forwards; }
.done-ring path { fill: none; stroke: var(--up); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: m-tick .45s ease-out .6s forwards; }
.done-loss .done-ring circle { fill: color-mix(in srgb, var(--down) 12%, transparent); stroke: var(--down); }
.done-loss .done-ring path { stroke: var(--down); }
@keyframes m-ring { to { stroke-dashoffset: 0; } }
@keyframes m-tick { to { stroke-dashoffset: 0; } }
html[data-motion="on"] .done-card { animation: m-bump-in .5s var(--spring); }
@keyframes m-bump-in { 0% { transform: scale(.85); } 100% { transform: scale(1); } }
.confetti { position: fixed; z-index: 100; width: 9px; height: 9px; border-radius: 2px; pointer-events: none; will-change: transform, opacity; }

/* ---------- Touch screens: no hover lift (a tap would leave the card shifted) ---------- */
@media (max-width: 640px), (hover: none) {
  html[data-motion="on"] .pos:hover, html[data-motion="on"] .panel:hover { transform: none; }
}
