/**
 * S. Parthasarathy Author Platform v2 — Design Tokens
 * Theme: "Heritage Teak and Parchment" (Old, premium, library feel)
 *   teak & walnut wood · parchment pages · brass details · oxblood CTAs
 *
 * Contrast compliance (Section 11):
 *   --ink on --parchment ≈ 12.9:1
 *   --muted on --parchment ≈ 5.5:1
 *   --brass-text on --parchment ≈ 5.0:1
 *   --cta (oxblood) with parchment text ≈ 8.0:1
 */

:root {
  color-scheme: light;

  /* 1. Core Heritage Teak and Parchment Palette (Strict Spec) */
  --parchment: #F1E6CF;        /* Primary page background */
  --paper: #F8F0DD;            /* Cards, reader pages, surfaces */
  --aged: #E7D6B6;             /* Alternate section background */
  --ink: #2A1A10;              /* Primary text (high contrast ~13:1, body 92%) */
  --muted: #6B5645;            /* Secondary text (~5.5:1) */
  --walnut: #3F2A1D;           /* Header, footer, reader frame */
  --teak: #5E3D27;             /* Rich wood band */
  --leather: #7A4A2B;          /* Hover borders, accent lines */
  --brass: #A9792B;            /* Decorative details & hairlines only */
  --brass-text: #7A5416;       /* Accessible text & labels on parchment (>= 4.5:1) */
  --cta: #6E2B25;              /* Oxblood primary action buttons (~8:1) */
  --cta-hover: #56211C;        /* Deep oxblood hover */
  --cta-text: #F8F0DD;         /* Parchment text on oxblood buttons */

  /* 2. Semantic Mappings & Backward Compatibility */
  --bg: var(--parchment);
  --surface: #FAF7F0;          /* Warm parchment surface (strict: no #fff cards) */
  --card-hairline: 1px solid rgba(169, 121, 43, 0.25);
  --sand: var(--aged);
  --accent: var(--brass-text);
  --accent-hover: #634313;
  --navy: var(--walnut);
  --navy-2: var(--teak);
  --btn-bg: var(--cta);
  --btn-bg-hover: var(--cta-hover);
  --on-accent: var(--cta-text);
  --portrait-bg: #DFCEAC;

  /* Semantic State Colors */
  --success: #265C39;
  --success-bg: #EAF3EC;
  --danger: #7A221C;
  --danger-bg: #FAECEB;
  --warning: #855519;
  --warning-bg: #FAF3E6;

  /* Paper Cards */
  --card-paper: var(--paper);
  --card-ink: var(--ink);
  --card-muted: var(--muted);
  --card-accent: var(--brass-text);

  /* Lines & Borders */
  --line: rgba(63, 42, 29, 0.15);
  --line-strong: rgba(63, 42, 29, 0.32);
  --line-double: 3px double rgba(122, 74, 43, 0.38);

  /* Subtle Woodgrain & Paper Textures */
  --grad-walnut: linear-gradient(180deg, #382417 0%, #2B1B11 100%);
  --grad-teak: linear-gradient(180deg, #5E3D27 0%, #462B1A 100%);
  --wood-grain: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.02) 0px, rgba(255, 255, 255, 0.02) 1px, transparent 1px, transparent 4px);

  /* Radius Scale (Unified 6 / 10 / 16) */
  --radius-none: 0;
  --radius-sm: 6px;
  --radius-ui: 10px;
  --radius-control: 10px;
  --radius-md: 10px;
  --radius-panel: 10px;
  --radius-lg: 16px;
  --radius-xl: 16px;
  --radius-pill: 9999px;
  --radius-paper: 4px;
  --radius: var(--radius-md);

  /* Unified Control Tokens (Task 0.2: equal height within form rows) */
  --control-h: 48px;
  --control-h-lg: 56px;

  /* Shadows Scale (warm walnut-tinted) */
  --shadow-xs: 0 1px 2px rgba(43, 29, 20, 0.05);
  --shadow-sm: 0 1px 3px rgba(43, 29, 20, 0.08), 0 2px 6px -2px rgba(43, 29, 20, 0.06);
  --shadow-md: 0 4px 14px -3px rgba(43, 29, 20, 0.12), 0 2px 6px -2px rgba(43, 29, 20, 0.08);
  --shadow-paper: 0 2px 4px rgba(43, 29, 20, 0.06), 0 12px 24px -14px rgba(43, 29, 20, 0.28);
  --shadow-lg: 0 12px 28px -6px rgba(43, 29, 20, 0.18), 0 4px 12px -2px rgba(43, 29, 20, 0.1);
  --shadow-modal: 0 24px 48px -12px rgba(43, 29, 20, 0.35);

  /* Spacing Scale (4/8/12/16/24/32/48/64/96) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --space-9: 96px;

  /* Typography (Self-Hosted Cormorant Garamond, Inter & Noto Serif Tamil) */
  --font-serif: "Cormorant Garamond", Georgia, serif;
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-text: var(--font-ui);
  --font-sans: var(--font-ui);
  --font-body: var(--font-ui);
  --font-tamil: "Noto Serif Tamil", serif;

  /* Strict Fluid Type Scale (Task 1) */
  --type-display: clamp(3rem, 1.6rem + 5.6vw, 5.5rem);
  --type-display-lh: 1.02;
  --type-display-ls: -0.02em;
  --type-display-weight: 500;

  --type-h1: clamp(2.25rem, 1.6rem + 2.6vw, 3.5rem);
  --type-h1-lh: 1.1;
  --type-h1-ls: -0.015em;
  --type-h1-weight: 500;

  --type-h2: clamp(1.875rem, 1.4rem + 1.8vw, 2.75rem);
  --type-h2-lh: 1.15;
  --type-h2-ls: -0.01em;
  --type-h2-weight: 500;

  --type-h3: clamp(1.375rem, 1.2rem + 0.7vw, 1.75rem);
  --type-h3-lh: 1.25;
  --type-h3-weight: 600;

  --type-h4: 1.0625rem;
  --type-h4-lh: 1.35;
  --type-h4-weight: 600;

  --type-eyebrow: 0.75rem;
  --type-eyebrow-ls: 0.18em;
  --type-eyebrow-weight: 600;

  --type-lead: clamp(1.0625rem, 1rem + 0.3vw, 1.25rem);
  --type-lead-lh: 1.6;
  --type-lead-max: 56ch;

  --type-body: 1rem;
  --type-body-desktop: 1.0625rem;
  --type-body-lh: 1.7;
  --type-body-max: 65ch;
  --type-small: 0.875rem;
  --type-small-lh: 1.5;

  --type-quote: clamp(1.25rem, 1rem + 1vw, 1.75rem);
  --type-quote-lh: 1.6;

  /* Backward Compatibility Type Aliases */
  --text-hero: var(--type-display);
  --text-h1: var(--type-h1);
  --text-h2: var(--type-h2);
  --text-h3: var(--type-h3);
  --text-body: var(--type-body);
  --text-sm: var(--type-small);
  --line-height-body: var(--type-body-lh);

  /* Fluid Spacing & Section Layout */
  --space-xs: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
  --space-s: clamp(1rem, 0.8rem + 1vw, 1.5rem);
  --space-m: clamp(1.5rem, 1.2rem + 1.5vw, 2.5rem);
  --space-l: clamp(2.5rem, 2rem + 3vw, 5rem);

  /* Layout Containers & Symmetric Gutters (Task 6) */
  --gutter: clamp(20px, 5.5vw, 32px);
  --container-max: 1200px;
  --container-pad: var(--gutter);
  --section-pad-y: clamp(56px, 8vw, 112px);
  --measure-prose: 65ch;
  --measure-lead: 56ch;
  --measure-poem: 42ch;

  /* Motion & Duration Tokens (Task 7) */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 150ms;
  --dur: 220ms;
  --transition-fast: 150ms ease;
  --transition-normal: 220ms var(--ease);
  --focus-ring: 2px solid var(--brass);
  --focus-outline: 2px solid var(--brass);
  --focus-offset: 2px;

  /* Z-index Scale */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-nav: 1040;
  --z-drawer: 1050;
  --z-modal: 1060;
  --z-toast: 1070;
}

/* Wood Band (Header / Footer / Hero Wood Accents) */
.band-dusk,
.band-wood {
  --bg: var(--walnut);
  --surface: #4B3323;
  --ink: #F8F0DD;
  --muted: #D1BFA5;
  --accent: #E5C383;
  --accent-hover: #F2D59D;
  --btn-bg: var(--cta);
  --btn-bg-hover: var(--cta-hover);
  --on-accent: #F8F0DD;
  --line: rgba(248, 240, 221, 0.16);
  --line-strong: rgba(248, 240, 221, 0.32);

  background: var(--grad-walnut);
  color: var(--ink);
  position: relative;
}
.band-dusk::after,
.band-wood::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--wood-grain);
  pointer-events: none;
  opacity: 0.6;
}
.band-dusk :is(h1, h2, h3, h4),
.band-wood :is(h1, h2, h3, h4) { 
  color: #F8F0DD;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

/* Scroll Offset for Sticky Header (Task 3) */
html {
  scroll-padding-top: calc(var(--site-header-height, 68px) + 16px);
  scroll-behavior: smooth;
}

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