/* Page-specific, two-dimensional motion. Load AFTER quiet-ui.css and page-transition.css.
   Visible content is the baseline; JS may opt in to a fresh-enter class AFTER inserting
   a node, but nothing here needs JS to become visible. Never animate test imagery. */
:root {
  --pm-ease: cubic-bezier(.2,.8,.2,1);
  --pm-ease-s: cubic-bezier(.65,0,.25,1);
  --pm-hover: #f2eee7;
  --pm-current: #eee4d9;
  --pm-accent: #a65035;
  --pm-line: #dedbd2;
}
@media (prefers-reduced-motion: no-preference) {
  /* Same-origin, same-site full documents only; browser ignores unsupported syntax.
     This complements, and deliberately overrides, the old page-transition.css root fade. */
  @view-transition { navigation: auto; }
  ::view-transition-group(root) { animation-duration: 360ms; animation-timing-function: var(--pm-ease); }
  ::view-transition-old(root) { animation: pm-page-old 240ms var(--pm-ease-s) both; }
  ::view-transition-new(root) { animation: pm-page-new 360ms var(--pm-ease) both; }
  @keyframes pm-page-old { to { opacity: 0; transform: translateX(-7px); } }
  @keyframes pm-page-new { from { opacity: 0; transform: translateX(11px); } }
  /* Existing page-transition.css names this element; keep its old snapshot inert. */
  ::view-transition-group(site-bg) { animation-duration: 1ms; }

  /* Homepage: native anchor scrolling, including browser history/back navigation. */
  html:has(#home-page) { scroll-behavior: smooth !important; scroll-padding-top: 94px; }
  #home-page :is(#about,#games,#tools,#articles,#contact) { scroll-margin-top: 96px; }
  #home-page :is(#about,#games,#tools,#articles,#contact):target {
    animation: pm-anchor 420ms var(--pm-ease) both;
  }
  @keyframes pm-anchor { from { background-color: #eee4d9; } to { background-color: transparent; } }

  /* Fluent-inspired hover: background, rule and indicator move together, no spring or 3D. */
  :is(.fs-links a,.art-links a,.videos-nav-links a,.fs-card .site-link,
       .series-card,.video-item,.encrypt-tab,#navigation .nav-button,
       .cvt-seg-button,.cvt-btn,.cvt-key,.rcmd-qz li a,
       .copy-ip,.art-back,.back-link) {
    transition: background-color 280ms var(--pm-ease), border-color 280ms var(--pm-ease),
      color 280ms var(--pm-ease), box-shadow 280ms var(--pm-ease),
      opacity 280ms var(--pm-ease), transform 280ms var(--pm-ease) !important;
  }
  :is(.fs-links a,.art-links a,.videos-nav-links a,#navigation .nav-button,
       .video-item,.encrypt-tab) { position: relative; }
  :is(.fs-links a,.art-links a,.videos-nav-links a,#navigation .nav-button,
       .video-item,.encrypt-tab)::before {
    content: ''; position: absolute; pointer-events: none; background: var(--pm-accent);
    transform: scaleX(0); transform-origin: left center;
    transition: transform 310ms var(--pm-ease), background-color 310ms var(--pm-ease);
  }
  :is(.fs-links a,.art-links a,.videos-nav-links a,.encrypt-tab)::before {
    left: 0; right: 0; bottom: 0; height: 2px;
  }
  :is(#navigation .nav-button,.video-item)::before {
    left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 3px;
    transform: scaleY(0); transform-origin: center top;
  }
  :is(.fs-links a,.art-links a,.videos-nav-links a,.encrypt-tab):is(:hover,:focus-visible,.on,[aria-selected='true'],[aria-current])::before {
    transform: scaleX(1);
  }
  :is(#navigation .nav-button,.video-item):is(:hover,:focus-visible,.active,[aria-current])::before {
    transform: scaleY(1);
  }
  :is(.fs-links a,.art-links a,.videos-nav-links a,#navigation .nav-button,.video-item,.encrypt-tab):is(:hover,:focus-visible) {
    background-color: var(--pm-hover) !important; border-color: var(--pm-line) !important;
  }
  :is(#navigation .nav-button,.video-item,.encrypt-tab):is(.active,.on,[aria-current],[aria-selected='true']) {
    background-color: var(--pm-current) !important; border-color: #cfb4a1 !important;
  }
  :is(.fs-links a,.art-links a,.videos-nav-links a,#navigation .nav-button,.video-item,.encrypt-tab):active {
    background-color: var(--pm-current) !important;
    transition-duration: 110ms !important;
  }
  .fs-card .site-link:is(:hover,:focus-visible),.series-card:is(:hover,:focus-visible) {
    background-color: var(--pm-hover) !important; border-color: #cfb4a1 !important;
  }

  /* File/text switches use selected tab as the moving cue; content enters as a sheet. */
  #panel-file:not([hidden]), #panel-text:not([hidden]) {
    animation: pm-encrypt-panel 330ms var(--pm-ease) both;
  }
  @keyframes pm-encrypt-panel {
    from { opacity: .65; clip-path: inset(0 0 0 3% round 8px); transform: translateX(8px); }
    to { opacity: 1; clip-path: inset(0 0 0 0 round 8px); transform: translateX(0); }
  }
  .file-drop:is(:hover,.over) { transition: background-color 280ms var(--pm-ease), border-color 280ms var(--pm-ease) !important; }
  .encrypt-status:not(:empty), .file-preview:not(:empty) { animation: pm-status 300ms var(--pm-ease) both; }

  /* IQ: initial setup -> question -> outcome; never touch #picimg or the progress fill. */
  body.au-iqtest :is(#start,#result):not([hidden]),
  body.au-iqtest #quiz:not([hidden]) :is(#qtop,#opts) {
    animation: pm-iq-screen 390ms var(--pm-ease) both;
  }
  @keyframes pm-iq-screen { from { opacity: .8; transform: translateY(12px); } }
  body.au-iqtest #opts > :is(button,label):not([hidden]) {
    transition: background-color 280ms var(--pm-ease), border-color 280ms var(--pm-ease), color 280ms var(--pm-ease) !important;
  }
  body.au-iqtest #result .big { animation: pm-iq-score 450ms var(--pm-ease-s) both; }
  @keyframes pm-iq-score { from { opacity: .72; transform: translateY(10px) scale(.98); } }

  /* Color prep -> fullscreen stage -> report. Stage canvas is NEVER transformed,
     faded, filtered, or animated: doing so would invalidate the perceptual test. */
  body:has(#cvt-app) .cvt-start:not([hidden]) { animation: pm-color-prep 360ms var(--pm-ease) both; }
  @keyframes pm-color-prep { from { opacity: .72; clip-path: inset(0 0 5% 0 round 12px); } }
  #cvt-stage :is(.cvt-stage-top,.cvt-prompt,.cvt-stage-note,.cvt-pad,.cvt-stage-bottom) {
    animation: pm-color-stage 300ms var(--pm-ease) both;
  }
  @keyframes pm-color-stage { from { opacity: .72; transform: translateY(6px); } }
  #cvt-app.cvt-app--result :is(.cvt-result-title,.cvt-result-summary) {
    animation: pm-color-report 420ms var(--pm-ease) both;
  }
  @keyframes pm-color-report { from { opacity: .7; transform: translateY(9px); } }
  /* Pausing removes the dialog; subsequent preparation uses its own transition. */

  /* Status state: labels and totals signal a data refresh without moving the card. */
  body.status-page :is(#statusText,#playerCount,#serverVersion,#refreshTime,#copyStatus):not(:empty) {
    transition: color 300ms var(--pm-ease), background-color 300ms var(--pm-ease);
  }
  body.status-page .status-dot { transition: background-color 360ms var(--pm-ease), box-shadow 360ms var(--pm-ease); }

  /* List load and episode selection; no transforms on the actual video/player. */
  #seriesList > .series-card { animation: pm-series 380ms var(--pm-ease) both; }
  #seriesList > .series-card:nth-child(2n) { animation-delay: 45ms; }
  @keyframes pm-series { from { opacity: .55; transform: translateY(10px); } }
  #videoList > .video-row { animation: pm-episode 330ms var(--pm-ease) both; }
  @keyframes pm-episode { from { opacity: .65; clip-path: inset(0 0 0 12px); } }
  .videos-meta :is(#videoTitle,#videoInfo,#downloadStatus) { transition: color 300ms var(--pm-ease); }

  /* Article content is often inserted asynchronously; animate article heading and
     readable text only, never the hero image or its QR/media descendants. */
  #article-head:not([hidden]) { animation: pm-article-head 400ms var(--pm-ease) both; }
  @keyframes pm-article-head { from { opacity: .7; transform: translateY(10px); } }
  #article-content:not(:empty) > :is(h1,h2,h3,p,blockquote,ul,ol):first-child {
    animation: pm-article-read 460ms var(--pm-ease) both;
  }
  @keyframes pm-article-read { from { opacity: .78; transform: translateY(9px); } }

  /* Favorability: leave JS numeric timing in charge; CSS only supports color state. */
  body.au-favorability #num { transition: color 340ms var(--pm-ease), text-shadow 340ms var(--pm-ease); }

  /* Admin section replaces editor DOM: animate the new heading/cards, not the
     sticky save bar or modal; auth view itself gets one short arrival. */
  #auth-view:not([hidden]) .auth-card { animation: pm-auth 380ms var(--pm-ease) both; }
  @keyframes pm-auth { from { opacity: .7; transform: translateY(12px); } }
  #app-view:not([hidden]) #editor:not([hidden]) > .panel,
  #app-view:not([hidden]) #security:not([hidden]) > .panel,
  #app-view:not([hidden]) .page-header h1 { animation: pm-admin 350ms var(--pm-ease) both; }
  @keyframes pm-admin { from { opacity: .72; transform: translateX(9px); } }
  #app-view :is(.notice,.error-panel,.conflict):not([hidden]) { animation: pm-status 310ms var(--pm-ease) both; }
  @keyframes pm-status { from { opacity: .7; transform: translateY(5px); } }
}
@media (prefers-reduced-motion: reduce) {
  html:has(#home-page) { scroll-behavior: auto !important; }
  /* Explicitly undo older cross-document animations, independent of load order. */
  ::view-transition-group(root),::view-transition-old(root),::view-transition-new(root) {
    animation-duration: .01ms !important; animation-delay: 0ms !important;
  }
  :is(.fs-links a,.art-links a,.videos-nav-links a,.fs-card .site-link,
       .series-card,.video-item,.encrypt-tab,#navigation .nav-button,
       .cvt-seg-button,.cvt-btn,.cvt-key,.rcmd-qz li a,.copy-ip,.art-back,.back-link)::before,
  :is(.fs-links a,.art-links a,.videos-nav-links a,.fs-card .site-link,
       .series-card,.video-item,.encrypt-tab,#navigation .nav-button,
       .cvt-seg-button,.cvt-btn,.cvt-key,.rcmd-qz li a,.copy-ip,.art-back,.back-link) {
    transition-duration: .01ms !important; animation-duration: .01ms !important;
  }
}
