/* =======================================================================
   Habil — Design System (base.css)
   Shared foundation for all website templates.
   Injected CSS variables (colors, fonts) are set in <head> by the template.
   ======================================================================= */

/* -----------------------------------------------------------------------
   Reset & defaults
   ----------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* Native smooth scroll (only for anchors; driven by JS with offset). */
  scroll-padding-top: var(--header-h);
}

body {
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--color-ink);
  background: var(--color-bg);
  overflow-x: hidden;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

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

::selection {
  background: var(--color-primary);
  color: #fff;
}

/* -----------------------------------------------------------------------
   Design tokens (default values — overridden by template inline)
   ----------------------------------------------------------------------- */
:root {
  /* Colors (set by template in <head>) */
  --color-primary: #0A2540;
  --color-secondary: #D4A24C;
  --color-accent: #00D4A3;

  /* Neutrals */
  --color-ink: #0A1628;
  --color-ink-2: #1F2937;
  --color-muted: #6B7280;
  --color-muted-2: #9CA3AF;
  --color-line: #E5E7EB;
  --color-line-soft: #F3F4F6;
  --color-bg: #FFFFFF;
  --color-bg-alt: #FAFAF9;
  --color-bg-dark: #0A1628;
  --color-bg-darker: #050B15;

  /* Derived from primary */
  --color-primary-tint-5: color-mix(in srgb, var(--color-primary) 5%, white);
  --color-primary-tint-10: color-mix(in srgb, var(--color-primary) 10%, white);
  --color-primary-tint-20: color-mix(in srgb, var(--color-primary) 20%, white);
  --color-primary-soft: color-mix(in srgb, var(--color-primary) 8%, transparent);

  /* Typography — fonts injected by template */
  --font-heading: 'Instrument Serif', 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;

  /* Modular scale — ratio 1.25 (major third) */
  --fs-xs: 0.75rem;       /* 12 */
  --fs-sm: 0.875rem;      /* 14 */
  --fs-base: 1rem;        /* 16 */
  --fs-lg: 1.125rem;      /* 18 */
  --fs-xl: 1.375rem;      /* 22 */
  --fs-2xl: 1.75rem;      /* 28 */
  --fs-3xl: 2.25rem;      /* 36 */
  --fs-4xl: 3rem;         /* 48 */
  --fs-5xl: 4rem;         /* 64 */
  --fs-6xl: 5.25rem;      /* 84 */
  --fs-7xl: 7rem;         /* 112 */

  /* Line heights */
  --lh-tight: 1.05;
  --lh-snug: 1.2;
  --lh-normal: 1.5;
  --lh-relaxed: 1.7;

  /* Letter spacing */
  --tracking-tight: -0.025em;
  --tracking-normal: 0;
  --tracking-wide: 0.04em;
  --tracking-wider: 0.08em;

  /* Spacing scale (base 4px) */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.25rem;
  --s-6: 1.5rem;
  --s-8: 2rem;
  --s-10: 2.5rem;
  --s-12: 3rem;
  --s-16: 4rem;
  --s-20: 5rem;
  --s-24: 6rem;
  --s-32: 8rem;
  --s-40: 10rem;
  --s-48: 12rem;

  /* Layout */
  --container-max: 1440px;
  --container-md: 1200px;
  --container-narrow: 960px;
  --container-text: 680px;
  --gutter: clamp(1.25rem, 4vw, 2.5rem);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 32px;
  --radius-pill: 999px;

  /* Shadows (subtle, layered) */
  --shadow-xs: 0 1px 2px rgba(10, 22, 40, 0.04);
  --shadow-sm: 0 2px 8px rgba(10, 22, 40, 0.05);
  --shadow-md: 0 8px 24px rgba(10, 22, 40, 0.08);
  --shadow-lg: 0 20px 48px rgba(10, 22, 40, 0.12);
  --shadow-xl: 0 40px 80px rgba(10, 22, 40, 0.18);

  /* Easing & duration */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.83, 0, 0.17, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 0.2s;
  --t-base: 0.4s;
  --t-slow: 0.7s;
  --t-slower: 1.1s;

  /* Z-index scale */
  --z-below: -1;
  --z-base: 0;
  --z-sticky: 10;
  --z-fixed: 20;
  --z-overlay: 30;
  --z-modal: 40;
  --z-toast: 50;

  /* Header height (used for offsets) */
  --header-h: 80px;
}

/* -----------------------------------------------------------------------
   Typography
   ----------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5 {
  font-family: var(--font-heading);
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--color-ink);
  text-wrap: balance;
}

h1, .h1 { font-size: clamp(2.5rem, 7vw, var(--fs-6xl)); }
h2, .h2 { font-size: clamp(2rem, 5vw, var(--fs-4xl)); }
h3, .h3 { font-size: clamp(1.5rem, 3.2vw, var(--fs-3xl)); }
h4, .h4 { font-size: clamp(1.25rem, 2.4vw, var(--fs-2xl)); line-height: var(--lh-snug); }
h5, .h5 { font-size: var(--fs-xl); line-height: var(--lh-snug); }

p {
  text-wrap: pretty;
  max-width: var(--container-text);
}

.lead {
  font-size: clamp(var(--fs-lg), 1.6vw, var(--fs-xl));
  color: var(--color-muted);
  line-height: var(--lh-relaxed);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--color-primary);
}

.eyebrow::before {
  content: '';
  display: inline-block;
  width: 24px;
  height: 1px;
  background: currentColor;
  opacity: 0.5;
}

/* -----------------------------------------------------------------------
   Layout primitives
   ----------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container-md { max-width: var(--container-md); }
.container-narrow { max-width: var(--container-narrow); }
.container-text { max-width: var(--container-text); }

.section {
  padding-block: clamp(var(--s-16), 10vw, var(--s-32));
}

.section-lg {
  padding-block: clamp(var(--s-20), 12vw, var(--s-40));
}

.section-dark {
  background: var(--color-bg-dark);
  color: rgba(255, 255, 255, 0.95);
}

.section-dark h1,
.section-dark h2,
.section-dark h3,
.section-dark h4,
.section-dark h5 {
  color: #fff;
}

.section-dark .lead,
.section-dark p {
  color: rgba(255, 255, 255, 0.7);
}

.section-alt {
  background: var(--color-bg-alt);
}

/* -----------------------------------------------------------------------
   Buttons
   ----------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 0.875rem 1.5rem;
  font-size: var(--fs-base);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.01em;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  transition:
    background-color var(--t-fast) var(--ease-out),
    color var(--t-fast) var(--ease-out),
    border-color var(--t-fast) var(--ease-out),
    transform var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.btn--primary {
  background: var(--color-ink);
  color: #fff;
}

.btn--primary:hover {
  background: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn--secondary {
  background: var(--color-primary);
  color: #fff;
}

.btn--secondary:hover {
  background: color-mix(in srgb, var(--color-primary) 88%, black);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn--ghost {
  background: transparent;
  color: var(--color-ink);
  border-color: var(--color-line);
}

.btn--ghost:hover {
  background: var(--color-ink);
  color: #fff;
  border-color: var(--color-ink);
}

.btn--light {
  background: #fff;
  color: var(--color-ink);
}

.btn--light:hover {
  background: var(--color-bg-alt);
  transform: translateY(-1px);
}

.btn--link {
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-ink);
  border-bottom: 1px solid currentColor;
  padding-bottom: 2px;
}

.btn--link:hover {
  color: var(--color-primary);
}

.btn--lg {
  padding: 1.125rem 2rem;
  font-size: var(--fs-lg);
}

.btn__arrow {
  display: inline-block;
  transition: transform var(--t-fast) var(--ease-out);
}

.btn:hover .btn__arrow {
  transform: translateX(3px);
}

/* -----------------------------------------------------------------------
   Links
   ----------------------------------------------------------------------- */
.link-underline {
  position: relative;
  display: inline-block;
}

.link-underline::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 100%;
  height: 1px;
  background: currentColor;
  transform-origin: right center;
  transform: scaleX(1);
  transition: transform var(--t-base) var(--ease-out);
}

.link-underline:hover::after {
  transform-origin: left center;
  transform: scaleX(0);
  animation: link-underline-redraw var(--t-base) var(--ease-out) forwards;
}

@keyframes link-underline-redraw {
  0% { transform-origin: right center; transform: scaleX(0); }
  50% { transform-origin: right center; transform: scaleX(1); transform: scaleX(0); }
  50.01% { transform-origin: left center; transform: scaleX(0); }
  100% { transform-origin: left center; transform: scaleX(1); }
}

/* -----------------------------------------------------------------------
   Form elements
   ----------------------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.form-label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--color-ink-2);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: var(--fs-base);
  font-family: var(--font-body);
  color: var(--color-ink);
  background: #fff;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  transition:
    border-color var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 15%, transparent);
}

.form-textarea {
  min-height: 140px;
  resize: vertical;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-muted-2);
}

/* -----------------------------------------------------------------------
   Scroll reveals (used with IntersectionObserver/GSAP)
   ----------------------------------------------------------------------- */
.reveal {
  opacity: 0;
  transform: translateY(32px);
  transition:
    opacity var(--t-slower) var(--ease-out),
    transform var(--t-slower) var(--ease-out);
}

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

.reveal-scale {
  opacity: 0;
  transform: scale(0.96);
  transition:
    opacity var(--t-slow) var(--ease-out),
    transform var(--t-slow) var(--ease-out);
}

.reveal-scale.is-visible {
  opacity: 1;
  transform: scale(1);
}

/* Stagger children when a group is revealed */
.stagger.is-visible > * {
  animation: stagger-in var(--t-slower) var(--ease-out) backwards;
}
.stagger.is-visible > *:nth-child(1) { animation-delay: 0.05s; }
.stagger.is-visible > *:nth-child(2) { animation-delay: 0.1s; }
.stagger.is-visible > *:nth-child(3) { animation-delay: 0.15s; }
.stagger.is-visible > *:nth-child(4) { animation-delay: 0.2s; }
.stagger.is-visible > *:nth-child(5) { animation-delay: 0.25s; }
.stagger.is-visible > *:nth-child(6) { animation-delay: 0.3s; }
.stagger.is-visible > *:nth-child(n+7) { animation-delay: 0.35s; }

@keyframes stagger-in {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

/* -----------------------------------------------------------------------
   Respect prefers-reduced-motion
   ----------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .reveal, .reveal-scale {
    opacity: 1 !important;
    transform: none !important;
  }
}

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

.text-center { text-align: center; }
.text-balance { text-wrap: balance; }
.text-muted { color: var(--color-muted); }

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--s-2); }
.gap-4 { gap: var(--s-4); }
.gap-6 { gap: var(--s-6); }
.gap-8 { gap: var(--s-8); }

.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 768px) {
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: 1fr;
  }
  .grid-cols-2 {
    grid-template-columns: 1fr;
  }
}

.aspect-square { aspect-ratio: 1 / 1; }
.aspect-video { aspect-ratio: 16 / 9; }
.aspect-portrait { aspect-ratio: 4 / 5; }

.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-pill { border-radius: var(--radius-pill); }

/* Hide on mobile */
@media (max-width: 767px) {
  .hide-mobile { display: none !important; }
}
@media (min-width: 768px) {
  .show-mobile { display: none !important; }
}
