/* TrainSkool UI motion + popups (ui-dialog.js). Loaded on every public page
   after the theme stylesheets. Motion is quick and quiet: 150–250 ms,
   ease-out, small distances; nothing bounces. prefers-reduced-motion turns
   all of it off (see the end of this file). Colours come from the brand
   tokens in studio-theme.css, with fallbacks for pages that lack them. */
:root {
  --ts-ease: cubic-bezier(.2, .8, .2, 1);
  --ts-ease-in: cubic-bezier(.4, 0, 1, 1);
  --ts-fast: 150ms;
  --ts-med: 200ms;
  --ts-slow: 250ms;
  --ts-backdrop: rgb(28 25 23 / .52);
  --ts-dlg-shadow: 0 24px 64px rgb(28 25 23 / .28), 0 2px 8px rgb(28 25 23 / .12);
}
:root[data-theme=dark] {
  --ts-backdrop: rgb(10 8 7 / .7);
  --ts-dlg-shadow: 0 24px 64px rgb(0 0 0 / .6), 0 0 0 1px #36302b;
}

/* ---- Page fade-in (pure CSS: never waits on JS, so it cannot hide content
   if a script fails; starts from .4 opacity so first paint/LCP is immediate) */
@keyframes ts-page-in { from { opacity: .4; } to { opacity: 1; } }
body > main, body > .sf-main, #main-content { animation: ts-page-in var(--ts-slow) var(--ts-ease) backwards; }

/* ---- Reveal on scroll (classes set by ui-dialog.js / course-card.js) ------ */
.js .reveal { opacity: 0; transform: translateY(12px); transition: opacity 420ms var(--ts-ease), transform 420ms var(--ts-ease); }
.js .reveal.is-in { opacity: 1; transform: none; }

/* ---- Hover / focus transitions: cards lift, buttons respond --------------- */
.sf-path-card, .dl-card, .choice-card, .sf-track, .sf-soon, .sf-track-course, .catalog-card, .sf-cat-tile {
  transition: transform var(--ts-med) var(--ts-ease), box-shadow var(--ts-med) var(--ts-ease), border-color var(--ts-med) var(--ts-ease), background-color var(--ts-med) var(--ts-ease);
}
.sf-path-card:hover, .dl-card:hover, .choice-card:hover, .sf-track:hover, .sf-soon:hover, .catalog-card:hover {
  transform: translateY(-2px); box-shadow: var(--shadow-lg, 0 16px 42px #1c191712);
}
.sf-track-course:hover { border-color: var(--line-strong, #d6d3d1); }
.primary-link, .outline-link, .outline-button, .sf-btn, .ts-btn-primary, .ts-btn-danger, .cart-checkout, .sf-card-cta, .sf-cart-btn, .sf-qv-btn, .text-link {
  transition: background-color var(--ts-fast) var(--ts-ease), border-color var(--ts-fast) var(--ts-ease), color var(--ts-fast) var(--ts-ease), box-shadow var(--ts-med) var(--ts-ease), transform var(--ts-fast) var(--ts-ease), opacity var(--ts-fast) var(--ts-ease);
}
.primary-link:hover, .sf-btn:hover, .ts-btn-primary:hover, .cart-checkout:hover { transform: translateY(-1px); }
.primary-link:active, .sf-btn:active, .ts-btn-primary:active, .ts-btn-danger:active, .outline-link:active, .outline-button:active, .cart-checkout:active { transform: translateY(0) scale(.98); }
:focus-visible { transition: outline-offset var(--ts-fast) var(--ts-ease); }

/* ---- Menus: fade + drop in when shown ------------------------------------- */
@keyframes ts-pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.bm-panel:not([hidden]), .session-menu:not([hidden]), .lang-menu:not([hidden]) { animation: ts-pop-in var(--ts-fast) var(--ts-ease) both; transform-origin: top right; }
.bm-panel:not([hidden]) { transform-origin: top left; }

/* ---- Mobile drawer: slide + fade in and out, warm blurred backdrop --------- */
@keyframes sc-slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sc-slide-out { from { transform: none; opacity: 1; } to { transform: translateX(24px); opacity: 0; } }
@keyframes ts-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ts-fade-out { from { opacity: 1; } to { opacity: 0; } }
.sc-drawer[open] { animation: sc-slide var(--ts-slow) var(--ts-ease) both; }
.sc-drawer::backdrop { background: var(--ts-backdrop); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.sc-drawer[open]::backdrop { animation: ts-fade-in var(--ts-med) ease-out both; }
.sc-drawer.is-closing { animation: sc-slide-out 180ms var(--ts-ease-in) both; }
.sc-drawer.is-closing::backdrop { animation: ts-fade-out 180ms ease-in both; }
.sc-drawer-nav a { transition: background-color var(--ts-fast) var(--ts-ease), color var(--ts-fast) var(--ts-ease); }

/* ---- Dialog ------------------------------------------------------------------
   The <dialog> fills the viewport and centres its panel, so a click outside
   the panel lands on the dialog itself = backdrop close. */
html.ts-scroll-lock, html.ts-scroll-lock body { overflow: hidden !important; }
.ts-dlg { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 16px; border: 0; background: transparent; color: var(--ink, #1c1917); overflow: auto; overscroll-behavior: contain; }
.ts-dlg[open] { display: grid; place-items: center; }
.ts-dlg::backdrop { background: var(--ts-backdrop); -webkit-backdrop-filter: blur(6px) saturate(1.1); backdrop-filter: blur(6px) saturate(1.1); }
.ts-dlg-panel { position: relative; display: flex; flex-direction: column; width: min(600px, 100%); max-height: calc(100dvh - 32px); background: var(--surface, #fff); color: var(--ink, #1c1917); border: 1px solid var(--line, #e7e5e4); border-radius: 20px; box-shadow: var(--ts-dlg-shadow); overflow: hidden; }
.ts-dlg-sm .ts-dlg-panel { width: min(440px, 100%); }
.ts-dlg-lg .ts-dlg-panel { width: min(880px, 100%); }
.ts-dlg-media .ts-dlg-panel { width: min(980px, 100%); background: #171412; color: #fafaf9; border-color: #292524; }
.ts-dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 18px 6px 24px; }
.ts-dlg-heading { min-width: 0; display: grid; gap: 4px; }
body .ts-dlg-eyebrow { margin: 0; color: var(--redesign-accent, #c2410c); font-size: .72rem !important; font-weight: 700 !important; letter-spacing: .1em; text-transform: uppercase; }
body .ts-dlg-title { margin: 0; font-family: var(--font-sans); font-size: 1.25rem; line-height: 1.3; color: inherit; }
body .ts-dlg-x { flex: none; width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 1.4rem; line-height: 1; background: var(--surface-subtle, #f5f5f4); color: var(--ink-soft, #44403c); border: 1px solid var(--line, #e7e5e4); box-shadow: none; transition: background-color var(--ts-fast) var(--ts-ease), transform var(--ts-fast) var(--ts-ease); }
body .ts-dlg-x:hover { background: var(--redesign-soft, #fff7ed); color: var(--redesign-accent, #c2410c); transform: rotate(90deg); }
.ts-dlg-media .ts-dlg-x { background: #ffffff14; border-color: #ffffff33; color: #fafaf9; }
.ts-dlg-body { padding: 8px 24px 20px; overflow: auto; min-height: 0; }
body .ts-dlg-text { margin: 0; color: var(--ink-soft, #44403c); line-height: 1.6; }
.ts-dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 14px 24px 20px; border-top: 1px solid var(--line, #e7e5e4); background: var(--surface, #fff); }
.ts-dlg-media .ts-dlg-actions { background: transparent; border-color: #292524; }
.ts-dlg-actions > a, .ts-dlg-actions > button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 10px 18px; border-radius: 12px; text-decoration: none; }
body .ts-btn-danger { background: #b91c1c; border: 1px solid #b91c1c; color: #fff; }
body .ts-btn-danger:hover { background: #991b1b; border-color: #991b1b; }

@keyframes ts-dlg-in { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes ts-dlg-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(4px) scale(.98); } }
.ts-dlg[open] .ts-dlg-panel { animation: ts-dlg-in 220ms var(--ts-ease) both; }
.ts-dlg[open]::backdrop { animation: ts-fade-in var(--ts-med) ease-out both; }
.ts-dlg.is-closing .ts-dlg-panel { animation: ts-dlg-out 160ms var(--ts-ease-in) both; }
.ts-dlg.is-closing::backdrop { animation: ts-fade-out 160ms ease-in both; }

/* Small screens: dialogs become bottom sheets (media stays centred). */
@keyframes ts-sheet-in { from { opacity: .4; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@keyframes ts-sheet-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(32px); } }
@media (max-width: 560px) {
  .ts-dlg:not(.ts-dlg-media) { padding: 0; }
  .ts-dlg:not(.ts-dlg-media)[open] { place-items: end stretch; }
  .ts-dlg:not(.ts-dlg-media) .ts-dlg-panel { width: 100%; max-height: 92dvh; border-radius: 20px 20px 0 0; border-bottom: 0; }
  .ts-dlg:not(.ts-dlg-media)[open] .ts-dlg-panel { animation-name: ts-sheet-in; animation-duration: var(--ts-slow); }
  .ts-dlg:not(.ts-dlg-media).is-closing .ts-dlg-panel { animation-name: ts-sheet-out; animation-duration: 180ms; }
  .ts-dlg-head { padding: 16px 14px 4px 18px; }
  .ts-dlg-body { padding: 6px 18px 16px; }
  .ts-dlg-actions { padding: 12px 18px calc(16px + env(safe-area-inset-bottom)); }
  .ts-dlg-actions > a, .ts-dlg-actions > button { flex: 1 1 auto; }
  .ts-dlg-signin .ts-dlg-actions > :first-child { order: 3; flex-basis: 100%; }
  .ts-dlg-media { padding: 8px; }
}

/* ---- Trailer in the shared dialog ------------------------------------------- */
.ts-dlg-media .ts-dlg-body { padding: 4px 16px 16px; }
.ts-trailer-stage { aspect-ratio: 16 / 9; width: 100%; background: #000; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.ts-trailer-stage > iframe { width: 100%; height: 100%; border: 0; display: block; }
body .ts-trailer-msg { color: #fed7aa; padding: 24px; text-align: center; margin: 0; }
.ts-trailer-stage > iframe { animation: ts-fade-in 300ms ease-out both; }

/* ---- Course quick view ------------------------------------------------------- */
.qv { display: grid; gap: 18px; }
.qv-top { display: grid; gap: 18px; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; }
.qv-media { position: relative; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: var(--surface-alt, #fff7ed); }
.qv-media > img, .qv-media > svg { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 0 !important; aspect-ratio: auto; }
body .qv-play { position: absolute; left: 12px; bottom: 12px; z-index: 1; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 14px; border-radius: 999px; background: #1c1917d9; color: #fff; border: 1px solid #ffffff40; font-size: .85rem; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
body .qv-play:hover { background: #c2410c; border-color: #c2410c; }
.qv-play-ico { width: 0; height: 0; border-style: solid; border-width: 6px 0 6px 10px; border-color: transparent transparent transparent currentColor; }
.qv-info { display: grid; gap: 10px; align-content: start; min-width: 0; }
.qv-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.qv-chip { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 10px; border-radius: 999px; background: var(--redesign-soft, #fff7ed); color: var(--redesign-accent, #c2410c); font-size: .75rem !important; font-weight: 600; }
.qv-chip.is-neutral { background: var(--surface-subtle, #f5f5f4); color: var(--ink-soft, #44403c); }
body .qv-sub { margin: 0; color: var(--ink-soft, #44403c); font-size: .95rem; line-height: 1.55; }
.qv-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.qv-fact { padding: 10px 12px; border-radius: 12px; background: var(--surface-subtle, #f5f5f4); border: 1px solid var(--line, #e7e5e4); display: grid; gap: 2px; }
.qv-fact strong { font-size: 1.05rem; color: var(--ink, #1c1917); }
.qv-fact span { font-size: .75rem; color: var(--muted, #57534e); }
.qv-price { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.qv-price strong { font-size: 1.5rem; color: var(--ink, #1c1917); letter-spacing: -.01em; }
.qv-price strong.is-free { color: var(--success, #15803d); }
.qv-price span { font-size: .8rem; color: var(--muted, #57534e); }
.qv-trainer { margin: 0; font-size: .85rem; color: var(--muted, #57534e); }
.qv-cols { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.qv-block { display: grid; gap: 8px; align-content: start; min-width: 0; }
body .qv-block h3 { margin: 0; font-family: var(--font-sans); font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted, #57534e); }
.qv-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.qv-list li { position: relative; padding-left: 22px; font-size: .9rem; line-height: 1.45; color: var(--ink, #1c1917); }
.qv-outcomes li::before { content: "\2713"; position: absolute; left: 0; top: 0; color: var(--redesign-accent, #c2410c); font-weight: 700; }
.qv-modules { counter-reset: qv; }
.qv-modules li { counter-increment: qv; padding-left: 30px; }
.qv-modules li::before { content: counter(qv); position: absolute; left: 0; top: 0; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; background: var(--redesign-soft, #fff7ed); color: var(--redesign-accent, #c2410c); font-size: .72rem; font-weight: 700; }
.qv-more { font-size: .8rem; color: var(--muted, #57534e); margin: 0; }
.qv-loading { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-subtle, #f5f5f4) 0, var(--surface-alt, #fff7ed) 50%, var(--surface-subtle, #f5f5f4) 100%); background-size: 200% 100%; animation: sf-shimmer 1.4s linear infinite; }
.qv-loading + .qv-loading { width: 80%; }
.qv-block.is-loaded { animation: ts-fade-in var(--ts-med) ease-out both; }
@media (max-width: 720px) { .qv-top, .qv-cols { grid-template-columns: minmax(0, 1fr); } }

/* Quick-view trigger on course cards: sits over the cover, above the
   stretched title link; shown on hover/focus, always on touch screens. */
body .sf-card .sf-qv-btn { position: absolute; top: 10px; right: 10px; z-index: 2; min-height: 34px; padding: 6px 12px; border-radius: 999px; background: #fffffff0; color: #1c1917; border: 1px solid #ffffff; font-size: .78rem; font-weight: 600 !important; box-shadow: 0 4px 14px #1c191733; opacity: 0; transform: translateY(-4px); }
.sf-card:hover .sf-qv-btn, .sf-card:focus-within .sf-qv-btn, body .sf-card .sf-qv-btn:focus-visible { opacity: 1; transform: none; }
body .sf-card .sf-qv-btn:hover { background: #fff; color: #c2410c; border-color: #fff; box-shadow: 0 6px 18px #1c191740; }
@media (hover: none) { body .sf-card .sf-qv-btn { opacity: 1; transform: none; } }

/* ---- Toasts -------------------------------------------------------------------- */
.ts-toasts { position: fixed; left: 50%; bottom: 24px; z-index: 1300; transform: translateX(-50%); width: min(440px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
body:has(.cart-bar) .ts-toasts { bottom: 96px; }
.ts-toast-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.ts-toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 14px; border-radius: 14px; background: #1c1917; color: #fafaf9; border: 1px solid #36302b; box-shadow: 0 14px 36px rgb(28 25 23 / .3); }
:root[data-theme=dark] .ts-toast { background: #2a2420; border-color: #4a423b; box-shadow: 0 14px 36px rgb(0 0 0 / .55); }
.ts-toast-mark { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 700; background: #fb923c; color: #1c1917; }
.ts-toast-success .ts-toast-mark { background: #4ade80; color: #052e16; }
.ts-toast-error .ts-toast-mark { background: #f87171; color: #450a0a; }
body .ts-toast-text { margin: 0; flex: 1 1 auto; min-width: 0; font-size: .9rem; line-height: 1.4; color: inherit; }
body .ts-toast-action { flex: none; min-height: 34px; padding: 6px 12px; border-radius: 10px; background: transparent; border: 1px solid #fb923c; color: #fdba74; font-size: .82rem; font-weight: 600 !important; display: inline-flex; align-items: center; text-decoration: none; box-shadow: none; }
body .ts-toast-action:hover { background: #fb923c; color: #1c1917; border-color: #fb923c; }
body .ts-toast-x { flex: none; width: 32px; height: 32px; min-height: 32px; padding: 0; border-radius: 50%; background: transparent; border: 0; color: #a8a29e; font-size: 1.2rem; line-height: 1; box-shadow: none; display: inline-flex; align-items: center; justify-content: center; }
body .ts-toast-x:hover { background: #ffffff14; color: #fafaf9; }
@keyframes ts-toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes ts-toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px); } }
.ts-toast { animation: ts-toast-in 220ms var(--ts-ease) both; }
.ts-toast.is-leaving { animation: ts-toast-out 180ms var(--ts-ease-in) both; }

/* ---- Reduced motion: no movement, no fades ----------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, *::backdrop { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
  .js .reveal { opacity: 1 !important; transform: none !important; }
  .sf-path-card:hover, .dl-card:hover, .choice-card:hover, .sf-track:hover, .sf-soon:hover, .catalog-card:hover,
  .primary-link:hover, .sf-btn:hover, .ts-btn-primary:hover, .cart-checkout:hover, body .ts-dlg-x:hover { transform: none !important; }
  body .sf-card .sf-qv-btn { opacity: 1; transform: none; }
}
