/* ===== Design tokens — light =====
   Dual convention:
   - --color-X (hex):       for plain CSS and arbitrary Tailwind classes without opacity
   - --color-X-rgb (R G B): for Tailwind aliases 'avelia-X' used with opacity modifier slash-N
   Do NOT mix: bg-[color:var(--x)]/40 does not work — use bg-avelia-x/40 instead.
===== */
:root {
  --color-bg: #F5F7F6;
  --color-surface: #FFFFFF;
  --color-surface-alt: #FAFBFA;
  --color-text: #1A4940;
  --color-text-muted: #4F6660;
  --color-text-heading: #12382F;
  --color-primary: #2E7D6D;
  --color-primary-hover: #246357;
  --color-mint: #DFF5EE;
  --color-accent: #7DC6E6;
  --color-salmon: #F7B6A8;
  --color-border: #E1ECE8;
  --color-focus: #7DC6E6;
  --color-danger: #E53E3E;

  --color-bg-rgb: 245 247 246;
  --color-surface-rgb: 255 255 255;
  --color-surface-alt-rgb: 250 251 250;
  --color-border-rgb: 225 236 232;
  --color-primary-rgb: 46 125 109;
  --color-mint-rgb: 223 245 238;
  --color-salmon-rgb: 247 182 168;
  --color-text-muted-rgb: 79 102 96;

  --shadow-soft: 0 1px 3px rgba(46, 125, 109, 0.06), 0 1px 2px rgba(46, 125, 109, 0.04);
  --shadow-elevated: 0 8px 24px rgba(46, 125, 109, 0.10), 0 2px 6px rgba(46, 125, 109, 0.06);
  --easing-soft: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ===== Design tokens — dark ===== */
html.dark,
:root.dark {
  --color-bg: #0F1A18;
  --color-surface: #162523;
  --color-surface-alt: #1D302C;
  --color-text: #DFF5EE;
  --color-text-muted: #94B0A8;
  --color-text-heading: #DFF5EE;
  --color-primary: #5BA999;
  --color-primary-hover: #7AC2B0;
  --color-mint: #1D302C;
  --color-accent: #9DD4EC;
  --color-salmon: #F9C5B8;
  --color-border: #243A35;
  --color-danger: #FF6B6B;

  --color-bg-rgb: 15 26 24;
  --color-surface-rgb: 22 37 35;
  --color-surface-alt-rgb: 29 48 44;
  --color-border-rgb: 36 58 53;
  --color-primary-rgb: 91 169 153;
  --color-mint-rgb: 29 48 44;
  --color-salmon-rgb: 249 197 184;
  --color-text-muted-rgb: 148 176 168;

  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* ===== Base ===== */
html {
  scroll-behavior: smooth;
}

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

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  color: var(--color-text-heading);
  font-family: 'Fraunces', Georgia, serif;
  font-optical-sizing: auto;
}

::selection {
  background: var(--color-mint);
  color: var(--color-text-heading);
}

/* Remove default focus ring only when not keyboard-focused */
:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ===== Skip link ===== */
.skip-link {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 9999;
  padding: 0.625rem 1rem;
  background: var(--color-primary);
  color: #FFFFFF;
  font-weight: 600;
  border-radius: 6px;
  box-shadow: var(--shadow-elevated);
  transform: translateY(-150%);
  transition: transform 200ms var(--easing-soft);
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
}

/* ===== Breathing widget ===== */
@keyframes breathe-grow {
  from {
    transform: scale(0.65);
  }
  to {
    transform: scale(1);
  }
}

@keyframes breathe-shrink {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(0.65);
  }
}

.breathing-circle {
  width: 220px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--color-mint) 0%, rgba(46, 125, 109, 0.35) 70%, rgba(46, 125, 109, 0.55) 100%);
  transform-origin: center;
  will-change: transform;
  transition: transform 400ms var(--easing-soft);
}

.breathing-circle.is-inhale {
  animation: breathe-grow 4s var(--easing-soft) forwards;
}

.breathing-circle.is-exhale {
  animation: breathe-shrink 4s var(--easing-soft) forwards;
}

.breathing-circle.is-hold {
  /* Hold current scale, no animation applied */
}

.breathing-circle.is-idle {
  transform: scale(0.65);
}

@media (prefers-reduced-motion: reduce) {
  .breathing-circle,
  .breathing-circle.is-inhale,
  .breathing-circle.is-exhale,
  .breathing-circle.is-hold,
  .breathing-circle.is-idle {
    animation: none;
    transition: none;
    transform: scale(0.85);
  }

  .breathing-circle.is-static-mode {
    animation: none;
    transform: scale(0.85);
  }
}

/* ===== Scroll reveal — progressive enhancement =====
   .reveal es visible por default (sin JS, sin animación).
   main.js agrega .is-revealing cuando arranca (oculta + prepara animación).
   IntersectionObserver agrega .is-visible al entrar en viewport (reveals con fade-up).
   Si JS falla por cualquier motivo, .is-revealing nunca se aplica → contenido queda visible. */
.reveal.is-revealing {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 700ms var(--easing-soft), transform 700ms var(--easing-soft);
}

.reveal.is-revealing.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .reveal.is-revealing {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ===== Editorial details ===== */
.editorial-rule {
  position: relative;
  height: 1px;
  background: currentColor;
  opacity: 0.15;
  border: 0;
}

.editorial-rule::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
  opacity: 1;
}

.text-balance {
  text-wrap: balance;
}

.text-pretty {
  text-wrap: pretty;
}

/* ===== Numerics ===== */
.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* ===== Paper grain overlay ===== */
body {
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
  opacity: 0.025;
  mix-blend-mode: multiply;
}

html.dark body::before {
  opacity: 0.05;
  mix-blend-mode: screen;
}

body > * {
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  body::before {
    /* keep grain — it's static, not motion */
  }
}

/* ===== Card hover lift (U2) ===== */
@media (hover: hover) {
  .reveal.rounded-3xl:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevated);
    transition: transform 240ms var(--easing-soft), box-shadow 240ms var(--easing-soft);
  }
}

@media (prefers-reduced-motion: reduce) {
  .reveal.rounded-3xl:hover {
    transform: none;
    transition: none;
  }
}

/* ===== Drop cap en #story (U3) ===== */
#story .font-serif > p:first-of-type::first-letter {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 3.6em;
  line-height: 0.9;
  float: left;
  padding: 0.05em 0.14em 0 0;
  color: var(--color-primary);
  font-weight: 500;
  font-feature-settings: "dlig", "ss01";
}
