/* ═══════════════════════════════════════════════════════════════
   site.css — shared tokens + primitives
   Baked in: Impeccable design laws, Motion Principles duration/easing system,
   Anthropic frontend-design polish doctrine.
   ─────────────────────────────────────────────────────────────── */

:root {
  /* ── Motion duration system (100/300/500 rule from Motion Principles) ── */
  --dur-feedback: 120ms;   /* hover, press */
  --dur-state: 220ms;      /* toggle, swap */
  --dur-layout: 380ms;     /* reflow, FLIP */
  --dur-entrance: 600ms;   /* scroll reveal, hero stage */
  --dur-exit: 180ms;       /* 75% of state duration */

  /* ── Easing curves (exponential, no bounce/elastic per Impeccable bans) ── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);          /* entrance, reveal */
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);           /* exit */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);      /* toggle */
  --ease-linear: linear;                              /* progress, scroll-driven */

  /* ── Color: OKLCH where supported, sRGB fallback ── */
  --accent: #9747ff;
  --accent-oklch: oklch(60% 0.25 295);
  --accent-soft: rgba(151, 71, 255, 0.18);
  --accent-mist: rgba(151, 71, 255, 0.08);

  /* ── Scroll velocity blur (driven by site.js, capped at 2px for legibility) ── */
  --scroll-blur: 0px;

  /* ── Focus ring (WCAG 2.2 Focus Appearance compliance) ── */
  --focus-ring: 0 0 0 2px var(--accent), 0 0 0 4px rgba(255, 255, 255, 0.9);
}

[data-theme="dark"] {
  --focus-ring: 0 0 0 2px var(--accent), 0 0 0 4px rgba(15, 15, 16, 0.9);
}

/* ═══ ACCESSIBILITY UTILITIES ═══ */

/* Skip-to-content link: hidden until keyboard focus */
.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 9999;
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  border-radius: 8px;
  transform: translateY(-150%);
  transition: transform var(--dur-state) var(--ease-out);
}
.skip-link:focus-visible {
  transform: translateY(0);
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Visually hide while remaining screen-reader available */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Universal focus-visible ring (replaces invisible browser default) */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
  transition: outline-offset var(--dur-feedback) var(--ease-out);
}
/* Inputs and rounded surfaces get a subtle box-shadow ring instead */
input:focus-visible,
textarea:focus-visible,
button.theme-toggle:focus-visible,
button.theme-btn:focus-visible,
button.burger:focus-visible,
.skip-link:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* Fixed-header anchor offset so #about etc. don't scroll under the header */
section[id],
[id="top"] {
  scroll-margin-top: 80px;
}

/* ═══ SCROLL MOTION BLUR (premium scroll feel) ═══
   Applied only to non-body-text elements so legibility is preserved.
   Velocity is computed in site.js and capped at 2px (--scroll-blur).
   Disabled under prefers-reduced-motion via the media query below.
   ─────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  .scroll-blur,
  .proj-card,
  .blog-c,
  .post-item,
  .tl-item,
  .stack-item,
  .cb-inner,
  .ghmap-card,
  .info-card,
  .hero-social a,
  .ftr-so a,
  .proj-num {
    filter: blur(var(--scroll-blur));
    will-change: filter;
    transition: filter 240ms var(--ease-out);
  }
}

/* Reduced-motion: zero out scroll blur and any keyframe animation we control */
@media (prefers-reduced-motion: reduce) {
  :root { --scroll-blur: 0px !important; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ═══ PAGE TRANSITIONS (View Transitions API) ═══
   Cross-page animation when navigating /blog ↔ /blog/<post>.
   Falls back to no-op on browsers without the API.
   ─────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 260ms;
    animation-timing-function: var(--ease-out);
  }
  ::view-transition-old(root) {
    animation-name: vt-fade-out;
  }
  ::view-transition-new(root) {
    animation-name: vt-fade-in;
  }
  @keyframes vt-fade-out {
    to { opacity: 0; transform: translateY(-4px); }
  }
  @keyframes vt-fade-in {
    from { opacity: 0; transform: translateY(8px); }
  }
}

/* ═══ BLOG POST CONTENT REVEAL ═══
   Staggered fade-up for each top-level block inside <article>.
   JS (site.js → initPostReveals) tags blocks with .post-reveal and
   toggles .in-view as they scroll into frame. No-op under reduced motion.
   ─────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  .post-reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity var(--dur-entrance) var(--ease-out),
                transform var(--dur-entrance) var(--ease-out);
  }
  .post-reveal.in-view {
    opacity: 1;
    transform: none;
  }
}

/* ═══ MINIMUM TOUCH TARGET (WCAG 2.2 Target Size) ═══ */
@media (max-width: 768px) {
  .theme-toggle,
  .theme-btn,
  .hero-social a,
  .ftr-so a {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ═══ PROJECT CARD CURSOR GRADIENT ═══ */
@media (prefers-reduced-motion: no-preference) {
  .proj-card {
    position: relative;
    overflow: hidden;
    isolation: isolate;
  }
  .proj-card::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: radial-gradient(
      520px circle at var(--mx, 50%) var(--my, 50%),
      rgba(151, 71, 255, 0.14),
      transparent 42%
    );
    opacity: 0;
    transition: opacity var(--dur-state) var(--ease-out);
    pointer-events: none;
  }
  .proj-card:hover::before { opacity: 1; }
}

/* ═══ CONTACT FORM STATES ═══ */
.contact-form button[disabled] {
  opacity: 0.6;
  cursor: progress;
}
.contact-form .form-status {
  min-height: 22px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  margin-top: 4px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--dur-state) var(--ease-out),
              transform var(--dur-state) var(--ease-out);
}
.contact-form .form-status.show {
  opacity: 1;
  transform: none;
}
.contact-form .form-status.success {
  color: #15803d;
}
.contact-form .form-status.error {
  color: #b91c1c;
}
[data-theme="dark"] .contact-form .form-status.success {
  color: #4ade80;
}
[data-theme="dark"] .contact-form .form-status.error {
  color: #f87171;
}

/* ═══ COMMAND PALETTE (⌘K) ═══ */
dialog#cmdk {
  width: min(560px, 92vw);
  max-height: 70vh;
  padding: 0;
  border: 1px solid var(--border, #e4e4e7);
  border-radius: 14px;
  background: var(--bg, #fff);
  color: var(--text, #18181b);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.06);
  margin: 12vh auto auto;
  overflow: hidden;
  font-family: inherit;
}
[data-theme="dark"] dialog#cmdk {
  background: #15151a;
  border-color: #2c2c2e;
  color: #f5f5f5;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
dialog#cmdk::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
dialog#cmdk[open] {
  animation: cmdk-in 220ms var(--ease-out);
}
@keyframes cmdk-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.cmdk-form { display: flex; flex-direction: column; }
#cmdkInput {
  font: inherit;
  font-size: 15px;
  padding: 18px 22px;
  border: none;
  outline: none;
  background: transparent;
  color: inherit;
  border-bottom: 1px solid var(--border, #e4e4e7);
}
[data-theme="dark"] #cmdkInput { border-bottom-color: #2c2c2e; }
#cmdkList {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  max-height: 50vh;
}
#cmdkList li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background var(--dur-feedback) var(--ease-out);
}
#cmdkList li:hover,
#cmdkList li[aria-selected="true"] {
  background: var(--accent-mist);
  color: var(--accent);
}
.cmdk-kind {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.55;
}
.cmdk-foot {
  padding: 10px 16px;
  font-size: 11px;
  color: var(--subtext, #71717a);
  border-top: 1px solid var(--border, #e4e4e7);
  display: flex;
  gap: 12px;
  align-items: center;
}
[data-theme="dark"] .cmdk-foot { border-top-color: #2c2c2e; }
.cmdk-foot kbd {
  font: inherit;
  font-size: 10px;
  padding: 2px 6px;
  border: 1px solid var(--border, #e4e4e7);
  border-radius: 4px;
  background: var(--surface, #f4f4f5);
}
[data-theme="dark"] .cmdk-foot kbd { background: #1c1c1e; border-color: #2c2c2e; }
