/* Kiroski Mythworks — Extraordinary Micro-Interactions & Editorial Craft Layer
 * Modern Web Guidance Compliant: natural-interactions, scroll-progress-indicator,
 * WCAG 1.4.11 focus-visible, prefers-reduced-motion, GPU-compositor transforms only.
 */

/* 0. Unified Sticky Kiroski Mythworks Home Navigation Shell */
.kiroski-home-shell {
  position: sticky;
  top: 0;
  z-index: 900;
  background: color-mix(in srgb, var(--surface, #131823) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border, #2a3447);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.kiroski-shell-inner {
  max-width: 1020px;
  margin: 0 auto;
  padding: 0.55rem 1.15rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1.25rem;
}

.brand-home-link {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--text);
  font-family: Georgia, "Iowan Old Style", serif;
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: -0.01em;
  min-height: 44px;
  padding-inline-end: 0.25rem;
}

.brand-home-link .brand-emblem {
  width: 28px;
  height: 28px;
  display: block;
  flex: none;
  transition: rotate 480ms ease-out;
}

@media (prefers-reduced-motion: no-preference) {
  .brand-home-link:hover .brand-emblem {
    rotate: 180deg;
  }
}

.brand-subtag {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--emerald);
  display: block;
  line-height: 1.1;
}

.shell-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.shell-nav::-webkit-scrollbar {
  display: none;
}

.shell-nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.shell-nav a:hover {
  color: var(--text);
  background: var(--surface-alt);
}

.shell-nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 700;
}

.shell-nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  inset: auto 0.65rem 2px;
  border-block-end: 3px solid var(--accent);
  border-radius: 2px;
}

@media print {
  .kiroski-home-shell {
    display: none !important;
  }
}

/* 1. Unmistakable pointing hand across EVERY clickable element + touch responsiveness */
:where(a[href], button:not(:disabled), [role="tab"], summary, label[for], input[type="checkbox"], input[type="radio"], select) {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
}

/* 2. Book-grade typography & selection polish (what 99% of websites miss) */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 5.5rem;
  text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

h1, h2, h3, .story-title {
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

.story-prose,
.letter-quote {
  hanging-punctuation: first last;
}

.chip,
.stat-chip,
.like-btn,
.provenance-line,
.count-status,
time {
  font-variant-numeric: tabular-nums;
}

::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--text);
}

/* 3. Refined link underline geometry & hover crispness */
a[href] {
  text-underline-offset: 0.22em;
  text-decoration-thickness: 1.5px;
  transition: color 140ms ease-out, border-color 140ms ease-out, box-shadow 150ms ease-out, text-decoration-thickness 140ms ease-out;
}

a[href]:hover {
  text-decoration-thickness: 2.5px;
}

/* 4. Distinct tactile hover, press (scale 0.97), and keyboard focus-visible states */
:where(button, .pill-link, .nav-pill, .nav-btn, .back-link, .filter-btn, .board-btn, .forum-cta-link, .sec-btn, .comment-submit-btn, .cta-primary, .cta-secondary) {
  transition: box-shadow 150ms ease-out, scale 140ms ease-out, border-color 140ms ease-out, background-color 140ms ease-out, color 140ms ease-out;
}

:where(button:not(:disabled), .pill-link, .nav-pill, .nav-btn, .back-link, .filter-btn, .board-btn, .forum-cta-link, .sec-btn, .comment-submit-btn, .cta-primary, .cta-secondary):hover {
  box-shadow: 0 3px 12px rgb(0 0 0 / 0.22);
}

@media (prefers-reduced-motion: no-preference) {
  :where(button:not(:disabled), .pill-link, .nav-pill, .nav-btn, .back-link, .filter-btn, .board-btn, .forum-cta-link, .sec-btn, .comment-submit-btn, .cta-primary, .cta-secondary):active {
    scale: 0.97;
  }
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 3px;
}

/* 5. Prevent mobile horizontal swipe on story tabs from triggering browser back-nav */
.tablist-bar {
  overscroll-behavior-x: contain;
}

/* 6. Accessible Skip-to-Content link (visible only on keyboard Tab) */
.skip-link {
  position: fixed;
  top: -100px;
  left: 1rem;
  z-index: 1000;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  background: var(--accent);
  color: #0b0e14;
  font-family: system-ui, -apple-system, sans-serif;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus-visible {
  top: 0.75rem;
}

/* 7. Zero-JS GPU-compositor Scroll-Driven Reading Progress Bar (modern-web-guidance: scroll-progress-indicator) */
.reading-progress-bar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--emerald));
  transform-origin: 0 50%;
  transform: scaleX(0);
  z-index: 999;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: scroll()) {
    @keyframes kiroski-grow-progress {
      from { transform: scaleX(0); }
      to { transform: scaleX(1); }
    }

    .reading-progress-bar {
      animation: kiroski-grow-progress auto linear;
      animation-timeline: scroll(root);
    }
  }
}

/* 8. Cosmic Yin-Yang Thinking Pointer & Indeterminate <progress> Spinner (modern-web-guidance: spinner) */
html[data-ui-busy="true"],
html[data-ui-busy="true"] * {
  cursor: url("/assets/img/yinyang-cursor.svg") 16 16, wait !important;
}

.yinyang-cursor-follower {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2000;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.32rem 0.7rem 0.32rem 0.38rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1.5px solid var(--accent);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.32);
  pointer-events: none;
  will-change: transform;
}

.yinyang-cursor-follower[hidden] {
  display: none;
}

.yinyang-busy-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

/* Native indeterminate <progress> styled as the spinning Kiroski Cosmic Yin-Yang (93 BPM cadence = 1.29s / 2 beats) */
progress.yinyang-spinner:indeterminate::-webkit-progress-bar,
progress.yinyang-spinner:indeterminate::-webkit-progress-value,
progress.yinyang-spinner:indeterminate::-moz-progress-bar,
progress.yinyang-spinner:indeterminate::slider-fill {
  display: none;
  background: none;
}

progress.yinyang-spinner:indeterminate {
  --spinner-duration: 1.29s;
  --_used-spinner-duration: var(--spinner-duration);
  appearance: none;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background-color: transparent;
  background-image: url("/assets/img/yinyang-cursor.svg");
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  flex: none;
  animation: kiroski-yinyang-spin var(--_used-spinner-duration) linear infinite;
}

@keyframes kiroski-yinyang-spin {
  to {
    rotate: 1turn;
  }
}

@media (prefers-reduced-motion: reduce) {
  progress.yinyang-spinner:indeterminate {
    /* Slow down significantly rather than stopping completely so users still see activity */
    --_used-spinner-duration: 6s;
  }
}

@media (forced-colors: active) {
  progress.yinyang-spinner:indeterminate {
    forced-color-adjust: none;
    border: 2px solid CanvasText;
    background-image: conic-gradient(CanvasText 0 50%, Canvas 50% 100%);
  }
}

/* 9. Clean hardcover print styling if a reader prints a story */
@media print {
  .reading-progress-bar,
  .top-nav,
  .tablist-bar,
  .font-controls,
  .story-nav,
  .community-section,
  .follow-card,
  .skip-link {
    display: none !important;
  }
  body {
    background: #ffffff;
    color: #000000;
  }
  .story-card {
    border: 0;
    padding: 0;
  }
}
