/*
 * Live Folio (Artbook Edition) — angelmiranda.dev
 * Same visual language as the home page: warm cotton paper, multiply ink plates,
 * Zen Old Mincho + Klee One, Tufte-style active right margin, and restrained motion
 * (< 260 ms, no blocking splash, no dark SaaS cards, no blur/skew gimmicks).
 * 100% CSP-safe (style-src 'self', zero inline styles, zero data: URIs).
 */

@view-transition {
  navigation: auto;
}

:root {
  --folio-progress: 0;
  --folio-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html.folio-enabled {
  scroll-behavior: smooth;
}

/* ---- 1. Quiet 2px ink reading progress line ---- */
.folio-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 500;
  pointer-events: none;
}

.folio-progress-bar {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(var(--folio-progress));
  background: var(--accent);
  opacity: 0.72;
  will-change: transform;
}

/* ---- 2. Paper-native opening (< 260ms, non-blocking) ---- */
html.folio-enabled .page > h1,
html.folio-enabled .page > .meta,
html.folio-enabled .folio-head > h1,
html.folio-enabled .folio-head > .meta {
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  transition: opacity 0.24s var(--folio-ease), transform 0.26s var(--folio-ease);
}

html.folio-open .page > h1,
html.folio-open .page > .meta,
html.folio-open .folio-head > h1,
html.folio-open .folio-head > .meta {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

html.folio-enabled .folio-head > .meta {
  transition-delay: 40ms;
}

.folio-head {
  position: relative;
  padding-bottom: 24px;
  margin-bottom: 34px;
}

.folio-head::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--rule);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.28s var(--folio-ease);
}

html.folio-open .folio-head::after,
html:not(.folio-enabled) .folio-head::after {
  transform: scaleX(1);
}

.folio-head h1 {
  margin: 0 0 10px;
}

.folio-head .meta {
  margin: 0;
}

/* ---- 3. Two-lane Artbook / Tufte Spread ---- */
html.folio-enabled article.page.col {
  width: 100%;
  max-width: 1120px;
}

.folio-grid {
  display: grid;
  grid-template-columns: minmax(0, 680px) minmax(240px, 1fr);
  gap: clamp(32px, 5vw, 76px);
  align-items: start;
}

.folio-main {
  min-width: 0;
}

/* Sticky right margin on the paper (no box, no dark card) */
.folio-margin {
  position: sticky;
  top: 28px;
  align-self: start;
  padding-left: 24px;
  border-left: 1px solid var(--rule);
}

.folio-plate {
  margin: 0 0 22px;
}

.folio-plate canvas {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 !important;
  mix-blend-mode: multiply;
  cursor: pointer;
}

.folio-plate-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  font: 13px/1.4 var(--hand);
  color: var(--muted);
}

.folio-repaint {
  font: 500 12px/1 var(--mono);
  color: var(--muted);
  background: none;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
  transition: color 0.14s ease, transform 0.12s ease;
}

.folio-repaint:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.folio-repaint:active {
  transform: scale(0.97);
}

/* Margin chapter index: paper-native, handwritten feel */
.folio-index-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 10px;
  font: 500 11.5px/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.folio-index-pct {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.folio-index {
  list-style: none;
  margin: 0;
  padding: 0;
}

.folio-index li {
  margin: 0;
}

.folio-index a {
  display: block;
  padding: 5px 0 5px 12px;
  margin-left: -25px;
  padding-left: 23px;
  border-left: 2px solid transparent;
  font: 400 14px/1.45 var(--hand);
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.folio-index a:hover {
  color: var(--ink);
}

.folio-index a.is-active {
  color: var(--ink);
  font-weight: 600;
  border-left-color: var(--warm);
}

/* Active margin sidenote (pulls the active section's plain-terms note into the margin) */
.folio-note {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font: 400 14.5px/1.6 var(--hand);
  color: var(--muted);
  transition: opacity 0.2s ease;
}

.folio-note b {
  display: block;
  margin-bottom: 4px;
  font: 600 13px/1.3 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--warm);
}

.folio-note:empty {
  display: none;
}

/* ---- 4. Refined Paper Surfaces (zero SaaS boxes) ---- */

/* Open ledger for .facts (hairline rules + subtle dry-brush wash, no boxes) */
.prose .facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  background: transparent;
  border: 0;
  border-top: 1.5px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  margin: 1.8em 0 2.2em;
}

.prose .facts > div {
  background: transparent;
  padding: 14px 14px 14px 0;
}

.prose .facts > div + div {
  padding-left: 14px;
  border-left: 1px solid var(--rule);
}

.prose .facts b {
  display: inline-block;
  font: 600 clamp(19px, 1.85vw, 23px)/1.18 var(--title);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  background: linear-gradient(176deg, transparent 0 62%, rgba(66, 87, 163, 0.14) 63% 86%, transparent 88%) no-repeat;
  padding: 0 0.08em;
  margin-bottom: 4px;
}

.prose .facts span {
  display: block;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--muted);
}

/* Section headings with hairline draw-in rule */
.prose h2 {
  position: relative;
  padding-top: 20px;
  margin: 2.2em 0 0.45em;
  scroll-margin-top: 24px;
}

.prose h2::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 56px;
  height: 2px;
  background: var(--warm);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.26s var(--folio-ease);
}

.prose h2.is-seen::before,
html:not(.folio-enabled) .prose h2::before {
  transform: scaleX(1);
}

/* Open print tables (Tufte style: crisp rules, subtle row hover, no box shadow) */
.prose .scroll {
  margin: 1.4em 0 1.9em;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.prose .data {
  margin: 0;
  border-top: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
}

.prose .data thead th {
  padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--ink);
  color: var(--ink);
  font: 600 13px/1.35 var(--mono);
  letter-spacing: 0.02em;
}

.prose .data tbody td {
  padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--rule);
  transition: background-color 0.12s ease;
}

.prose .data tbody tr:last-child td {
  border-bottom: 0;
}

.prose .data tbody tr:hover td {
  background: rgba(66, 87, 163, 0.045);
}

.prose .data tr.total td {
  border-top: 1px solid var(--ink);
  background: rgba(239, 234, 243, 0.45);
}

/* Code / diff blocks: stay on warm paper with subtle left ink rule & quiet copy button */
.folio-snip {
  position: relative;
  margin: 1.5em 0 1.9em;
}

.folio-snip pre.snip {
  margin: 0;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--rule);
  border-left: 2.5px solid var(--accent);
  box-shadow: none;
  padding: 14px 16px;
}

.folio-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  font: 500 11.5px/1 var(--mono);
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 4px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.14s ease, border-color 0.14s ease, transform 0.12s ease;
}

.folio-snip:hover .folio-copy,
.folio-copy:focus-visible {
  opacity: 1;
}

.folio-copy:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.folio-copy:active {
  transform: scale(0.97);
}

/* Quiet scroll settle (< 260ms, no blur, no scale distortion) */
.folio-step {
  opacity: 0;
  transform: translate3d(0, 10px, 0);
  transition: opacity 0.24s var(--folio-ease), transform 0.26s var(--folio-ease);
}

.folio-step.is-seen {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

/* Updates index (.reads): subtle ink bar reveal on hover, no SaaS card box */
.page .reads li {
  transition: padding-left 0.18s var(--folio-ease), border-color 0.18s ease;
}

.page .reads li:hover {
  padding-left: 10px;
  border-top-color: var(--accent);
}

/* ---- 5. Responsive: clean single column on tablet/mobile ---- */
@media (max-width: 1020px) {
  .folio-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }
  .folio-margin {
    position: static;
    order: -1;
    min-width: 0;
    padding-left: 0;
    border-left: 0;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--rule);
  }
  .folio-index-head,
  .folio-index,
  .folio-note {
    display: none;
  }
  .folio-margin.no-plate {
    display: none;
  }
  .folio-copy {
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .prose .facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .prose .facts > div:nth-child(3) {
    padding-left: 0;
    border-left: 0;
    border-top: 1px solid var(--rule);
  }
  .prose .facts > div:nth-child(4) {
    border-top: 1px solid var(--rule);
  }
}

/* ---- 6. Accessibility: prefers-reduced-motion ---- */
@media (prefers-reduced-motion: reduce) {
  html.folio-enabled { scroll-behavior: auto; }
  html.folio-enabled .page > h1,
  html.folio-enabled .page > .meta,
  html.folio-enabled .folio-head > h1,
  html.folio-enabled .folio-head > .meta,
  .folio-step {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .folio-head::after,
  .prose h2::before {
    transform: scaleX(1) !important;
    transition: none !important;
  }
  .folio-repaint:active,
  .folio-copy:active {
    transform: none !important;
  }
}
