/* ========================================================================
   THE BOOK FLOW — BASE DESIGN SYSTEM
   Single source of truth for palette, typography, layout, and utilities.
   All page-specific files build on top of these tokens.
   ======================================================================== */

:root {
  color-scheme: light;

  /* ── Stitch Core Palette (Light Editorial) ── */
  --tf-bg:            #d9d8cf;      /* Warm editorial grey                 */
  --tf-bg-mid:        #ecebe3;      /* Surface Container Low               */
  --tf-bg-soft:       #f5f3ea;      /* Page glow                           */
  --tf-bg-deep:       #b9bab3;      /* Page depth                          */
  --tf-bg-card:       #fcfcfc;      /* Pure white for cards                */
  --tf-border:        rgba(27, 28, 21, 0.08); /* Subtle dividers           */
  --tf-border-mid:    rgba(27, 28, 21, 0.15); /* Slightly stronger border  */

  /* ── Text hierarchy ── */
  --tf-text:          #1b1c15;      /* Charcoal - primary readable text    */
  --tf-text-soft:     #424844;      /* secondary / muted text              */
  --tf-text-dim:      #727973;      /* placeholders and hint text          */

  /* ── Accent system ── */
  --tf-accent:        #173124;      /* Library Green                       */
  --tf-accent-dark:   #2d4739;      /* Primary Container                   */
  --tf-accent-glow:   rgba(23, 49, 36, 0.08); /* subtle tinted background  */

  /* ── Semantic colors ── */
  --tf-success:       #2e5339;
  --tf-error:         #ba1a1a;
  --tf-warning:       #93000a;
  --tf-info:          #332a18;

  /* ── Radii (sharp architectural aesthetic) ── */
  --tf-r-sm:   2px;  /* 0.125rem as per Stitch */
  --tf-r-md:   4px;  /* 0.25rem */
  --tf-r-lg:   6px;  /* 0.375rem */
  --tf-r-pill: 0px;  /* Experimental: sharp corners forpill labels */

  /* ── Shadows (Diffused/Ambient) ── */
  --tf-shadow-sm:  0 4px 12px rgba(27, 28, 21, 0.04);
  --tf-shadow-md:  0 12px 24px rgba(27, 28, 21, 0.06);
  --tf-shadow-lg:  0 20px 48px rgba(27, 28, 21, 0.08);

  /* ── Motion ── */
  --tf-ease:       cubic-bezier(0.22, 0.61, 0.36, 1);
  --tf-ease-spring:cubic-bezier(0.2, 0.8, 0.2, 1);
  --tf-t-fast:     140ms;
  --tf-t:          220ms;
  --tf-t-slow:     380ms;

  /* ── Layout ── */
  --navbar-h: 66px;
  --tf-max-w: 1240px;
  --tf-container-w: min(var(--tf-max-w), 96%);
  --tf-container-pad: 20px;
  --tf-public-max-w: var(--tf-max-w);
  --tf-public-w: min(var(--tf-public-max-w), calc(100vw - 40px));
  --tf-public-pad-y: clamp(20px, 4vw, 40px);

  /* ── Legacy Aliases ── */
  --tf-cream:         color-mix(in srgb, #fbfaee 85%, black 15%);
  --tf-cream-mid:     color-mix(in srgb, #f5f4e8 85%, black 15%);
  --tf-ink:           #1b1c15;
  --tf-ink-soft:      #424844;
  --tf-amber:         #173124;
}

/* ── Reduce motion ── */
@media (prefers-reduced-motion: reduce) {
  :root {
    --tf-t-fast: 1ms;
    --tf-t:      1ms;
    --tf-t-slow: 1ms;
  }
}

/* ========================================================================
   RESET
   ======================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}

html, body {
  min-height: 100%;
}

body {
  padding-top: var(--navbar-h);
  font-family: "Manrope", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.65; /* slightly taller for editorial feel */
  background-color: var(--tf-bg);
  color: var(--tf-text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

.tf-background {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 10%, rgba(245, 243, 234, 0.92) 0, rgba(245, 243, 234, 0.45) 28%, transparent 52%),
    radial-gradient(circle at 84% 18%, rgba(196, 202, 193, 0.72) 0, rgba(196, 202, 193, 0.28) 24%, transparent 50%),
    linear-gradient(135deg, var(--tf-bg-soft) 0%, var(--tf-bg-mid) 36%, var(--tf-bg) 68%, var(--tf-bg-deep) 100%);
}

/* ── Global heading scale ── */
h1, h2, h3, h4, h5, h6 {
  font-family: "Newsreader", serif;
  color: var(--tf-text);
  line-height: 1.05;
  font-weight: 500; /* Editorial serifs look better at med weights */
}

h1 {
  font-size: clamp(32px, 5vw, 64px);
  letter-spacing: -0.02em;
  margin-bottom: 0.5em;
}

h2 {
  font-size: clamp(24px, 3.5vw, 42px);
  letter-spacing: -0.015em;
  margin-bottom: 0.4em;
}

h3 {
  font-size: clamp(20px, 2.5vw, 28px);
  margin-bottom: 0.3em;
}

h4 {
  font-weight: 600;
  font-size: clamp(16px, 1.8vw, 20px);
  margin-bottom: 0.25em;
}

p { margin: 0 0 1.25em; }

/* ── Links ── */
a {
  color: inherit;
  text-decoration: none;
}
a:hover, a:focus { text-decoration: none; }

/* ── Media ── */
img, svg {
  display: block;
  max-width: 100%;
}

/* ── Form elements ── */
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: none;
  background: none;
}
ul, ol { list-style: none; }

/* ── Focus rings ── */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--tf-accent);
  outline-offset: 2px;
}
/* ── Archival Stamp: tactile press snap for all primary CTAs ──
   Simulates the physical impact of a library stamp. The transform is
   !important so it wins over any hover translateY already in flight. */
.tf-btn--primary:active,
.sch-btn--publish:active,
.nm-work-btn--primary:active,
.pw-checkout-btn--solid:active,
.premium-btn--primary:active,
.ds-btn-upgrade:active,
.nb-btn--primary:active {
  transform: scale(0.96) !important;
  transition-duration: 80ms !important;
  box-shadow: none !important;
}

/* ========================================================================
   LAYOUT SHELL
   ======================================================================== */
.tf-layout {
  min-height: 100vh;
  height: auto;
  display: flex;
  flex-direction: column;
  max-width: 100vw;
  overflow-x: clip;
}

.tf-main {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  max-width: 100vw;
  overflow-x: clip;
}

.tf-main__inner {
  flex: 1 0 auto;
}

.tf-main {
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 180ms var(--tf-ease),
    transform 180ms var(--tf-ease);
}

.tf-main.is-page-leaving {
  opacity: 0;
  transform: translateY(8px);
}

.tf-main.is-page-entering {
  opacity: 0;
  transform: translateY(8px);
}

body.is-navigating .nb-nav {
  cursor: progress;
}

@media (prefers-reduced-motion: reduce) {
  .tf-main {
    transition-duration: 1ms;
    transform: none;
  }

  .tf-main.is-page-leaving,
  .tf-main.is-page-entering {
    transform: none;
  }
}

/* ========================================================================
   PREMIUM PILL LABEL
   ======================================================================== */
.premium-pill {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: var(--tf-r-sm);
  background: var(--tf-accent-dark);
  color: #ffffff;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  font-family: "Manrope", sans-serif;
  margin-bottom: 12px;
  border: none;
}

/* ========================================================================
   FLASH MESSAGES
   ======================================================================== */
.tf-flash-modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 42px);
  animation: tf-flash-modal-in 180ms ease-out both;
}

.tf-flash-modal.is-dismissing {
  animation: tf-flash-modal-out 180ms ease-in both;
}

.tf-flash-backdrop {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: rgba(27, 28, 21, 0.26);
  cursor: default;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.tf-flash-dialog {
  position: relative;
  z-index: 1;
  width: min(460px, calc(100vw - 36px));
  padding: 18px;
  border: 1px solid rgba(27, 28, 21, 0.14);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 250, 0.96), rgba(246, 246, 238, 0.92)),
    var(--tf-bg-card);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 28px 80px rgba(27, 28, 21, 0.24);
}

.tf-flash-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.tf-flash-dialog__header p {
  margin: 0;
  color: var(--tf-text);
  font-family: "Manrope", sans-serif;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  line-height: 1;
  text-transform: uppercase;
}

.tf-flash-close {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--tf-text);
  background: transparent;
  border: 1px solid var(--tf-border-mid);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  transition: background 180ms var(--tf-ease), border-color 180ms var(--tf-ease), color 180ms var(--tf-ease);
}

.tf-flash-close:hover,
.tf-flash-close:focus-visible {
  color: #ffffff;
  background: var(--tf-accent);
  border-color: var(--tf-accent);
  outline: none;
}

.tf-flash-stack {
  width: min(760px, calc(100% - 32px));
  margin: clamp(16px, 2.4vw, 24px) auto 0;
  display: grid;
  gap: 10px;
}

.tf-flash-modal .tf-flash-stack {
  width: 100%;
  margin: 0;
}

.tf-flash {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--tf-r-sm);
  border: 1px solid var(--tf-border-mid);
  background:
    linear-gradient(180deg, rgba(255, 255, 250, 0.86), rgba(246, 246, 238, 0.78)),
    var(--tf-bg-card);
  color: var(--tf-text);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 16px 34px rgba(27, 28, 21, 0.07);
  font-family: "Manrope", sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.45;
}

.tf-flash-modal .tf-flash {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  padding: 6px 4px 8px;
  font-size: 0.92rem;
}

.tf-flash::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 0.48em;
  border-radius: 50%;
  background: var(--tf-accent);
  box-shadow: 0 0 0 4px rgba(23, 49, 36, 0.08);
}

.tf-flash--success {
  border-color: rgba(46, 83, 57, 0.2);
  background:
    linear-gradient(180deg, rgba(255, 255, 250, 0.88), rgba(243, 247, 240, 0.8)),
    rgba(46, 83, 57, 0.04);
  color: #2e5339;
}

.tf-flash--warning,
.tf-flash--error {
  border-color: rgba(147, 75, 25, 0.24);
  background:
    linear-gradient(180deg, rgba(255, 255, 250, 0.9), rgba(249, 243, 232, 0.84)),
    rgba(147, 75, 25, 0.05);
  color: #6f3517;
}

.tf-flash--warning::before,
.tf-flash--error::before {
  background: #b9822b;
  box-shadow: 0 0 0 4px rgba(185, 130, 43, 0.11);
}

.tf-flash--info {
  border-color: rgba(51, 42, 24, 0.2);
  background:
    linear-gradient(180deg, rgba(255, 255, 250, 0.88), rgba(246, 246, 238, 0.8)),
    rgba(51, 42, 24, 0.04);
  color: #332a18;
}

@media (max-width: 640px) {
  :root {
    --tf-public-w: calc(100vw - 28px);
  }

  .tf-flash-stack {
    width: calc(100% - 28px);
    margin-top: 14px;
  }

  .tf-flash-dialog {
    padding: 16px;
  }

  .tf-flash {
    padding: 13px 14px;
    font-size: 0.78rem;
  }

  .tf-flash-modal .tf-flash {
    padding: 4px 2px 8px;
    font-size: 0.86rem;
  }
}

@keyframes tf-flash-modal-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes tf-flash-modal-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* ========================================================================
   CAROUSEL UTILITIES (For JS Drag / Autoplay Integration)
   ======================================================================== */
.is-programmatic {
  scroll-snap-type: none !important;
  scroll-behavior: auto !important;
}

.is-dragging a,
.is-dragging img {
  pointer-events: none !important;
}

.is-dragging,
.is-dragging .lp-track,
.is-dragging .nm-track,
.is-dragging .bs-track {
  cursor: grabbing !important;
  user-select: none !important;
}

/* ========================================================================
   REACTIONS (like / dislike)
   ======================================================================== */
.tf-reactions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tf-btn--reaction {
  position: relative;
  overflow: visible;
}

/* Like */
.tf-reaction-form[data-kind="like"] .tf-btn--reaction {
  background: rgba(46, 83, 57, 0.06);
  border: 1px solid rgba(46, 83, 57, 0.15);
  color: #2e5339;
}
.tf-reaction-form[data-kind="like"] .tf-btn--reaction:hover {
  background: rgba(46, 83, 57, 0.12);
  border-color: rgba(46, 83, 57, 0.25);
}
.tf-reaction-form.is-active[data-kind="like"] .tf-btn--reaction {
  background: #173124;
  border-color: #173124;
  color: #fff;
  box-shadow: 0 4px 12px rgba(23, 49, 36, 0.15);
}

/* Dislike */
.tf-reaction-form[data-kind="dislike"] .tf-btn--reaction {
  background: rgba(186, 26, 26, 0.06);
  border: 1px solid rgba(186, 26, 26, 0.15);
  color: #ba1a1a;
}
.tf-reaction-form[data-kind="dislike"] .tf-btn--reaction:hover {
  background: rgba(186, 26, 26, 0.12);
  border-color: rgba(186, 26, 26, 0.25);
}
.tf-reaction-form.is-active[data-kind="dislike"] .tf-btn--reaction {
  background: #ba1a1a;
  border-color: #ba1a1a;
  color: #fff;
  box-shadow: 0 4px 12px rgba(186, 26, 26, 0.15);
}

/* Burst particle animation cleaned up; replaced with subtle CSS transitions below */

/* ── Curated Reactions (Premium Editorial Style) ── */
.tf-reactions-curated {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.tf-reaction-form { margin: 0; }

.reaction-btn {
  background: var(--tf-bg-mid);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--tf-text-soft);
  transition: all var(--tf-t) var(--tf-ease);
  padding: 0.6rem 1.1rem;
  border-radius: var(--tf-r-sm);
  position: relative;
  overflow: hidden;
}

.reaction-btn:hover {
  background: #ffffff;
  border-color: var(--tf-border-mid);
  color: var(--tf-text);
  transform: translateY(-2px);
  box-shadow: var(--tf-shadow-sm);
}

.reaction-btn:active {
  transform: scale(0.96);
}

.tf-reaction-form.is-active[data-kind="like"] .reaction-btn {
  background: var(--tf-accent);
  border-color: var(--tf-accent);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(23, 49, 36, 0.2);
}

.tf-reaction-form.is-active[data-kind="dislike"] .reaction-btn {
  background: #ba1a1a;
  border-color: #ba1a1a;
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(186, 26, 26, 0.2);
}

.tf-reaction-form.is-active .reaction-btn .reaction-count {
  color: #ffffff;
  opacity: 0.9;
}

.reaction-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.reaction-icon svg {
  width: 17px;
  height: 17px;
  stroke-width: 1.8;
  display: block;
  transition: transform var(--tf-t) var(--tf-ease-spring);
}

.reaction-label {
  font-family: "Manrope", sans-serif;
  font-weight: 800;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.reaction-count {
  font-family: "Newsreader", serif;
  font-weight: 700;
  font-size: 1rem; /* Slightly smaller for better balance */
  color: var(--tf-text);
  margin-left: 1px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

/* ===== Carousel Controls — Global ===== */
.carousel-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--tf-border);
  background: #ffffff;
  color: var(--tf-text-soft);
  cursor: pointer;
  transition: all 0.3s var(--tf-ease);
  padding: 0;
  box-shadow: 0 2px 8px rgba(27, 28, 21, 0.05);
  margin: 0;
}

.carousel-toggle:hover {
  border-color: var(--tf-accent);
  color: var(--tf-text);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(27, 28, 21, 0.08);
}

.carousel-toggle svg {
  width: 16px;
  height: 16px;
  display: block;
}

.carousel-toggle__text {
  display: none !important;
}
