/* ══════════════════════════════════════════════════════════════
   衡序 OS — Interaction Pro (Desktop FX Layer)
   技術：GSAP ScrollTrigger · Anime.js · Iconify · Glassmorphism
   僅桌面版 ≥1024px 生效，手機版完全不受影響
══════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────
   0. CSS Custom Properties — Desktop FX tokens
───────────────────────────────────────────── */
@media (min-width: 1024px) {
  :root {
    --fx-glow-color: rgba(16, 185, 129, 0.08);
    --fx-glow-size: 350px;
    --fx-glass-bg: rgba(255, 255, 255, 0.52);
    --fx-glass-border: rgba(255, 255, 255, 0.35);
    --fx-glass-blur: 24px;
    --fx-glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255,255,255,0.6);
    --fx-sonar-color: rgba(16, 185, 129, 0.4);
    --fx-marquee-speed: 30s;
    --fx-accent-glow: 0 0 40px rgba(16, 185, 129, 0.15);
  }
  [data-theme="dark"] {
    --fx-glow-color: rgba(52, 211, 153, 0.06);
    --fx-glass-bg: rgba(26, 29, 39, 0.65);
    --fx-glass-border: rgba(255, 255, 255, 0.08);
    --fx-glass-blur: 28px;
    --fx-glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255,255,255,0.04);
    --fx-sonar-color: rgba(52, 211, 153, 0.3);
    --fx-accent-glow: 0 0 40px rgba(52, 211, 153, 0.08);
  }

/* ─────────────────────────────────────────────
   1. FLASHLIGHT / SPOTLIGHT — 跟隨游標光暈
───────────────────────────────────────────── */

  /* Global flashlight layer — follows cursor */
  .fx-flashlight {
    position: fixed;
    width: var(--fx-glow-size);
    height: var(--fx-glow-size);
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transform: translate(-50%, -50%);
    background: radial-gradient(
      circle,
      var(--fx-glow-color) 0%,
      rgba(16, 185, 129, 0.03) 40%,
      transparent 70%
    );
    transition: opacity 0.4s ease;
    will-change: left, top;
    mix-blend-mode: screen;
  }
  [data-theme="dark"] .fx-flashlight {
    mix-blend-mode: normal;
  }
  .fx-flashlight.active {
    opacity: 1;
  }

  /* Card-level glow on hover — reveals a subtle inner light */
  .fx-card-glow {
    position: relative;
    overflow: hidden;
  }
  .fx-card-glow::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    opacity: 0;
    background: radial-gradient(
      600px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
      rgba(16, 185, 129, 0.06),
      transparent 40%
    );
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
  }
  [data-theme="dark"] .fx-card-glow::before {
    background: radial-gradient(
      600px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
      rgba(52, 211, 153, 0.05),
      transparent 40%
    );
  }
  .fx-card-glow:hover::before {
    opacity: 1;
  }

/* ── Section 2 (Glassmorphism) moved to webgl-fx.css for mobile+desktop ── */

/* ─────────────────────────────────────────────
   3. SONAR PULSE — 聲納脈衝動畫
───────────────────────────────────────────── */

  /* Sonar ring on CTA / FAB buttons */
  .fx-sonar {
    position: relative;
  }
  .fx-sonar::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: inherit;
    border: 2px solid var(--fx-sonar-color);
    animation: fx-sonar-ring 2.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
    pointer-events: none;
  }
  @keyframes fx-sonar-ring {
    0% {
      transform: scale(1);
      opacity: 0.6;
    }
    100% {
      transform: scale(1.5);
      opacity: 0;
    }
  }

  /* Double sonar — AI hub card icon */
  .sb-ai-card-icon .ai-pulse,
  .fx-sonar-double::after,
  .fx-sonar-double::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: inherit;
    pointer-events: none;
  }
  .fx-sonar-double::after {
    border: 2px solid rgba(124, 58, 237, 0.35);
    animation: fx-sonar-ring 2.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
  }
  .fx-sonar-double::before {
    border: 2px solid rgba(124, 58, 237, 0.2);
    animation: fx-sonar-ring 2.5s cubic-bezier(0, 0.2, 0.8, 1) 0.8s infinite;
  }

  /* Status dot sonar */
  .fx-sonar-dot {
    position: relative;
  }
  .fx-sonar-dot::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--em-500);
    top: 50%;
    right: -16px;
    transform: translateY(-50%);
    animation: fx-dot-ping 2s ease-out infinite;
  }
  @keyframes fx-dot-ping {
    0% { box-shadow: 0 0 0 0 var(--fx-sonar-color); }
    70% { box-shadow: 0 0 0 10px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
  }

/* ─────────────────────────────────────────────
   4. INFINITE MARQUEE — 無限跑馬燈
───────────────────────────────────────────── */

  .fx-marquee-wrap {
    overflow: hidden;
    white-space: nowrap;
    position: relative;
    padding: 10px 0;
    margin: 0 0 20px;
    border-top: 1px solid var(--fx-glass-border);
    border-bottom: 1px solid var(--fx-glass-border);
    border-radius: 10px;
    background: rgba(16, 185, 129, 0.02);
  }
  [data-theme="dark"] .fx-marquee-wrap {
    background: rgba(52, 211, 153, 0.02);
    border-color: rgba(255, 255, 255, 0.04);
  }

  /* Fade masks on edges */
  .fx-marquee-wrap::before,
  .fx-marquee-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 80px;
    z-index: 2;
    pointer-events: none;
  }
  .fx-marquee-wrap::before {
    left: 0;
    background: linear-gradient(to right, var(--bg), transparent);
  }
  .fx-marquee-wrap::after {
    right: 0;
    background: linear-gradient(to left, var(--bg), transparent);
  }
  [data-theme="dark"] .fx-marquee-wrap::before {
    background: linear-gradient(to right, #080b10, transparent);
  }
  [data-theme="dark"] .fx-marquee-wrap::after {
    background: linear-gradient(to left, #080b10, transparent);
  }

  .fx-marquee-track {
    display: inline-flex;
    animation: fx-marquee var(--fx-marquee-speed) linear infinite;
    will-change: transform;
  }
  .fx-marquee-track:hover {
    animation-play-state: paused;
  }

  .fx-marquee-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 28px;
    font-size: 12px;
    font-weight: 500;
    color: var(--txt2);
    white-space: nowrap;
    flex-shrink: 0;
  }
  .fx-marquee-item .fx-mq-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .fx-marquee-item .fx-mq-val {
    font-family: var(--M);
    font-weight: 700;
    color: var(--txt);
  }

  @keyframes fx-marquee {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
  }

/* ─────────────────────────────────────────────
   5. VERTICAL TEXT CLIP SLIDE — 垂直文字剪裁滑動
───────────────────────────────────────────── */

  .fx-vtext {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(16, 185, 129, 0.12);
    position: absolute;
    pointer-events: none;
    user-select: none;
  }
  [data-theme="dark"] .fx-vtext {
    color: rgba(52, 211, 153, 0.08);
  }

  /* Dashboard left vertical deco */
  .dash-left {
    position: relative;
  }
  .fx-vtext-left {
    left: -26px;
    top: 80px;
    font-size: 10px;
    letter-spacing: 0.25em;
  }

  /* Right column vertical deco */
  .dash-right {
    position: relative;
  }
  .fx-vtext-right {
    right: -20px;
    top: 40px;
    font-size: 9px;
    letter-spacing: 0.3em;
  }

  /* Clip-path reveal animation */
  .fx-clip-reveal {
    clip-path: inset(100% 0 0 0);
    animation: fx-clip-in 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }
  @keyframes fx-clip-in {
    to { clip-path: inset(0 0 0 0); }
  }

  /* Slide-up reveal for cards */
  .fx-reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .fx-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
  }

/* ─────────────────────────────────────────────
   6. SIDEBAR ENHANCEMENTS — 側邊欄動效升級
───────────────────────────────────────────── */

  /* Active item glow line */
  .bnav .ni.active::before {
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.4),
                0 0 24px rgba(16, 185, 129, 0.15) !important;
  }

  /* Nav item hover ripple */
  .bnav .ni {
    position: relative;
    overflow: hidden;
  }
  .bnav .ni::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
      circle at var(--ripple-x, 50%) var(--ripple-y, 50%),
      rgba(255, 255, 255, 0.08),
      transparent 60%
    );
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
  }
  .bnav .ni:hover::after {
    opacity: 1;
  }

  /* Sidebar section label — subtle entrance */
  .sb-section-label {
    overflow: hidden;
  }

  /* Sidebar bottom glow */
  .sb-bottom {
    position: relative;
  }
  .sb-bottom::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 18px;
    right: 18px;
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent,
      rgba(16, 185, 129, 0.3),
      transparent
    );
  }

/* ─────────────────────────────────────────────
   7. MICRO-INTERACTIONS — 細部動效
───────────────────────────────────────────── */

  /* Button press with spring */
  .sbtn {
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
  }
  .sbtn:hover {
    transform: translateY(-1px) !important;
    box-shadow: 0 6px 24px rgba(6, 78, 59, 0.25) !important;
  }
  .sbtn:active {
    transform: scale(0.97) translateY(0) !important;
  }

  /* Chip hover spring */
  .chip {
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
  }
  .chip:hover {
    transform: translateY(-1px);
  }

  /* List item hover — smooth slide */
  .li {
    transition: all 0.15s ease !important;
  }
  .li:hover {
    background: rgba(16, 185, 129, 0.03) !important;
    padding-left: 18px !important;
  }
  [data-theme="dark"] .li:hover {
    background: rgba(52, 211, 153, 0.04) !important;
  }

  /* Period toggle pill glow */
  .ptb.act {
    box-shadow: 0 0 16px rgba(255, 255, 255, 0.1);
  }

  /* Quick-add pills — stagger entrance (handled by JS) */
  .qa .qab {
    opacity: 0;
    transform: translateY(8px);
  }
  .qa .qab.fx-entered {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  }

/* ─────────────────────────────────────────────
   7b. MICRO-INTERACTIONS
───────────────────────────────────────────── */

  /* Form input focus micro-lift */
  .fi {
    transition: border-color .2s, box-shadow .2s, transform .2s cubic-bezier(.4,0,.2,1) !important;
  }
  .fi:focus {
    transform: translateY(-1px);
  }

  /* Project card active press feedback */
  .pdc:active {
    transform: scale(.98) !important;
    transition-duration: .1s !important;
  }

/* ─────────────────────────────────────────────
   8. TOPBAR LIVE CLOCK + BREADCRUMB
───────────────────────────────────────────── */

  .fx-topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-left: auto;
  }
  .fx-clock {
    font-family: var(--M);
    font-size: 12px;
    font-weight: 500;
    color: var(--txt2);
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .fx-clock-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--em-500);
    animation: fx-dot-ping 2.5s ease-out infinite;
  }

  .fx-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--txt2);
  }
  .fx-breadcrumb-sep {
    font-size: 10px;
    opacity: 0.4;
  }
  .fx-breadcrumb-current {
    font-weight: 600;
    color: var(--txt);
  }

/* ─────────────────────────────────────────────
   9. SCROLL PROGRESS BAR
───────────────────────────────────────────── */

  .fx-scroll-progress {
    position: fixed;
    top: 56px; /* below topbar */
    left: 256px; /* after sidebar */
    right: 0;
    height: 2px;
    z-index: 49;
    background: transparent;
    pointer-events: none;
  }
  .fx-scroll-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--em-500), var(--em-400), #34d399);
    border-radius: 0 2px 2px 0;
    transition: width 0.1s ease-out;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.3);
  }

/* ─────────────────────────────────────────────
   10. PAGE TRANSITIONS — 頁面切換動畫加強
───────────────────────────────────────────── */

/* ── Page transition moved to webgl-fx.css (WebGL liquid wipe) ── */

  /* Stagger children inside pages */
  .fx-stagger > * {
    opacity: 0;
    transform: translateY(16px);
  }
  .fx-stagger.fx-entered > * {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  }

/* ─────────────────────────────────────────────
   11. DASHBOARD LAYOUT REFINEMENT
───────────────────────────────────────────── */

  /* Right column separator — gradient line */
  .dash-right {
    border-left: none !important;
    position: relative;
  }
  .dash-right::before {
    content: '';
    position: absolute;
    left: 0;
    top: 28px;
    bottom: 28px;
    width: 1px;
    background: linear-gradient(
      180deg,
      transparent,
      var(--gray-200),
      var(--gray-200),
      transparent
    );
  }
  [data-theme="dark"] .dash-right::before {
    background: linear-gradient(
      180deg,
      transparent,
      rgba(255, 255, 255, 0.06),
      rgba(255, 255, 255, 0.06),
      transparent
    );
  }

/* ── Sections 12-14 (Glass) moved to webgl-fx.css ── */

}
/* end @media (min-width: 1024px) */

/* ─── Wider desktop (≥ 1280px) FX overrides ─── */
@media (min-width: 1280px) {
  :root {
    --fx-glow-size: 420px;
  }

  .fx-marquee-wrap {
    margin: 0 0 24px;
    padding: 12px 0;
  }

  .fx-vtext-left {
    left: -32px;
    font-size: 11px;
  }

  .dash-pi {
    grid-template-columns: 1fr 360px !important;
    gap: 0 44px !important;
  }

  /* Larger KPI text on wide screens */
  .pc-v {
    font-size: 2.2rem !important;
  }
  .pc-sv {
    font-size: 1.1rem !important;
  }

  .fx-scroll-progress {
    left: 268px; /* match wider sidebar */
  }
}

/* ─── Ultra-wide (≥ 1536px) ─── */
@media (min-width: 1536px) {
  .dash-pi {
    grid-template-columns: 1fr 400px !important;
  }

  .fx-marquee-wrap {
    margin: 0 0 28px;
  }

  .pc-v {
    font-size: 2.8rem !important;
  }
  .pc-sv {
    font-size: 1.25rem !important;
  }
  .photo-grid {
    grid-template-columns: repeat(5, 1fr) !important;
  }
}

/* ─── Reduced motion preference ─── */
@media (prefers-reduced-motion: reduce) {
  .fx-flashlight,
  .fx-sonar::after,
  .fx-sonar-double::after,
  .fx-sonar-double::before {
    animation: none !important;
  }
  .fx-marquee-track {
    animation: none !important;
  }
  .fx-clip-reveal {
    animation: none !important;
    clip-path: none !important;
  }
  .page {
    animation: none !important;
  }
}
