/*
 * AiPreso theme: tokens + shared components.
 * The CSS custom properties below are the SINGLE source of truth for colour.
 * theme.json's palette points at them (var(--aip-*)), so the Site Editor, patterns
 * and this file all follow whichever mode is active.
 *
 * Mode resolution:
 *   1. :root                              dark (deep aubergine), the default
 *   2. @media (prefers-color-scheme: light) light, unless the visitor chose dark
 *   3. :root[data-theme="light"]          explicit light choice (set by assets/js/theme-toggle.js)
 *   4. :root[data-theme="dark"]           explicit dark choice, wins over the media query
 */

:root {
  color-scheme: dark;

  --aip-canvas: #190A24;
  --aip-canvas-2: #110618;
  --aip-surface-1: #241333;
  --aip-surface-2: #2E1A40;
  --aip-surface-3: #3A2450;
  --aip-text-1: #F4EEFB;
  --aip-text-2: #D6C9E6;
  --aip-text-3: #C2B6D6;
  --aip-border: rgba(236, 222, 255, 0.12);
  --aip-border-strong: rgba(236, 222, 255, 0.22);
  --aip-hairline: rgba(236, 222, 255, 0.09);
  --aip-shadow-sm: 0 2px 10px rgba(8, 0, 16, 0.45);

  /* Brand fills are mode-independent. Never use them as small text. */
  --aip-brand-orange: #FF4500;
  --aip-brand-purple: #4D006D;
  /* Brighter purple for borders and dots: #4D006D vanishes on aubergine. */
  --aip-brand-purple-bright: #7B1FA2;
  --aip-brand-blue: #00B4FC;

  /* Mode-tuned accent-as-text (>= AA on canvas and surfaces). */
  --aip-accent-orange: #FF7849;
  --aip-accent-purple: #CB86E2;
  --aip-accent-blue: #5CC8FF;

  /* Dark ink on the orange fill: white on #FF4500 is only 3.44:1, this is 5.61:1. */
  --aip-on-orange: #1A0A00;
  --aip-orange-hover: #FF5A1A;
  --aip-focus: #F4EEFB;

  /* Mode-swapped visibility (CSS-only wordmark and toggle glyph swap). */
  --aip-show-wordmark-dark: block;
  --aip-show-wordmark-light: none;
  --aip-show-icon-sun: block;
  --aip-show-icon-moon: none;

  --aip-gradient-signature: var(--wp--preset--gradient--signature);
  --aip-font-display: var(--wp--preset--font-family--display, Saira, system-ui, sans-serif);
  --aip-font-body: var(--wp--preset--font-family--body, 'IBM Plex Sans', system-ui, sans-serif);
  --aip-font-mono: var(--wp--preset--font-family--mono, 'IBM Plex Mono', ui-monospace, monospace);
  --aip-header-offset: 80px;
}

/* Light (crema paper). Declared twice because CSS cannot share one block between a
   media query and an attribute selector; keep both copies identical. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --aip-canvas: #F4ECE1;
    --aip-canvas-2: #EFE5D6;
    --aip-surface-1: #FFFFFF;
    --aip-surface-2: #FDFAF5;
    --aip-surface-3: #F3EADC;
    --aip-text-1: #241A12;
    --aip-text-2: #574A3E;
    /* README had #8B7B6C (3.48:1, fails AA); darkened to pass. */
    --aip-text-3: #6B5C4E;
    --aip-border: rgba(61, 42, 28, 0.14);
    --aip-border-strong: rgba(61, 42, 28, 0.26);
    --aip-hairline: rgba(61, 42, 28, 0.10);
    --aip-shadow-sm: 0 2px 8px rgba(74, 50, 28, 0.10);
    --aip-accent-orange: #BC3409;
    --aip-accent-purple: #7B1FA2;
    --aip-accent-blue: #0A6E96;
    --aip-focus: #241A12;
    --aip-show-wordmark-dark: none;
    --aip-show-wordmark-light: block;
    --aip-show-icon-sun: none;
    --aip-show-icon-moon: block;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --aip-canvas: #F4ECE1;
  --aip-canvas-2: #EFE5D6;
  --aip-surface-1: #FFFFFF;
  --aip-surface-2: #FDFAF5;
  --aip-surface-3: #F3EADC;
  --aip-text-1: #241A12;
  --aip-text-2: #574A3E;
  --aip-text-3: #6B5C4E;
  --aip-border: rgba(61, 42, 28, 0.14);
  --aip-border-strong: rgba(61, 42, 28, 0.26);
  --aip-hairline: rgba(61, 42, 28, 0.10);
  --aip-shadow-sm: 0 2px 8px rgba(74, 50, 28, 0.10);
  --aip-accent-orange: #BC3409;
  --aip-accent-purple: #7B1FA2;
  --aip-accent-blue: #0A6E96;
  --aip-focus: #241A12;
  --aip-show-wordmark-dark: none;
  --aip-show-wordmark-light: block;
  --aip-show-icon-sun: none;
  --aip-show-icon-moon: block;
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-padding-top: var(--aip-header-offset);
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  background: var(--aip-canvas);
  color: var(--aip-text-1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

p, h1, h2, h3 {
  text-wrap: pretty;
}

/* Body links are underlined so they do not rely on colour alone; nav, buttons and
   headings opt out. */
.entry-content a:not(.wp-block-button__link),
.wp-block-post-content a:not(.wp-block-button__link),
.wp-block-post-excerpt a {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

/* Template parts sit flush; sections own their own vertical rhythm. */
.wp-site-blocks > * + * {
  margin-block-start: 0;
}

/* ---------- Focus ---------- */

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--aip-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* On the orange/purple gradient a single ring loses contrast, so use a dark
   band under a white ring. */
.aip-hero :focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px #1A0A00;
}

/* ---------- Skip link ---------- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100000;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--aip-canvas);
  color: var(--aip-text-1);
  border: 2px solid var(--aip-focus);
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
  clip: auto;
  width: auto;
  height: auto;
}

/* ---------- Header / footer ---------- */

/* Stickiness goes on the template-part wrapper, not on the group inside it:
   a sticky element only sticks within its parent, and the wrapper's parent
   (.wp-site-blocks) is the tall one. */
.wp-site-blocks > header.wp-block-template-part {
  position: sticky;
  top: 0;
  z-index: 50;
}

.admin-bar .wp-site-blocks > header.wp-block-template-part {
  top: var(--wp-admin--admin-bar--height, 32px);
}

.aip-header {
  background: var(--aip-canvas);
  border-bottom: 1px solid var(--aip-hairline);
}

.aip-header__inner {
  gap: 1rem 1.5rem;
}

.aip-header .wp-block-navigation {
  flex: 1 1 auto;
}

.aip-header .wp-block-navigation-item__content {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
}

.aip-header .wp-block-navigation .current-menu-item > .wp-block-navigation-item__content,
.aip-header .wp-block-navigation [aria-current="page"] {
  color: var(--aip-accent-orange);
}

.aip-header__actions {
  gap: 0.625rem;
}

.aip-login {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.aip-login a {
  color: var(--aip-text-1);
  padding: 0.5rem 0.75rem;
  display: inline-block;
}

.aip-header .wp-block-buttons,
.aip-header .wp-block-button {
  margin: 0;
}

.aip-footer {
  background: var(--aip-canvas-2);
  border-top: 1px solid var(--aip-hairline);
}

.aip-footer__inner {
  gap: 1.5rem;
}

.aip-footer .wp-block-navigation-item__content {
  padding: 0.375rem 0.625rem;
  font-size: 0.875rem;
}

.aip-mono-tagline {
  font-family: var(--aip-font-mono);
  font-size: 0.75rem;
  color: var(--aip-text-3);
  margin: 0;
}

/* Wordmarks: white-ink PNG for dark mode, black-ink PNG for light mode.
   Class names say which MODE the image is shown in. */
.aip-wordmark-dark,
.aip-wordmark-light {
  margin: 0;
}

.aip-wordmark-dark {
  display: var(--aip-show-wordmark-dark);
}

.aip-wordmark-light {
  display: var(--aip-show-wordmark-light);
}

.aip-wordmark-dark img,
.aip-wordmark-light img {
  height: 26px;
  width: auto;
  display: block;
}

.aip-footer .aip-wordmark-dark img,
.aip-footer .aip-wordmark-light img {
  height: 24px;
}

/* Theme toggle (markup lives in parts/header.html). */
.aip-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--aip-surface-2);
  color: var(--aip-text-1);
  border: 1px solid var(--aip-border-strong);
  cursor: pointer;
}

.aip-theme-toggle:hover {
  background: var(--aip-surface-3);
}

.aip-theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.aip-theme-toggle .aip-icon-sun {
  display: var(--aip-show-icon-sun);
}

.aip-theme-toggle .aip-icon-moon {
  display: var(--aip-show-icon-moon);
}

@media (max-width: 600px) {
  .aip-header__inner {
    gap: 0.5rem 1rem;
  }
}

/* ---------- Buttons ---------- */

.wp-block-button__link,
.wp-element-button {
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.wp-block-button__link:hover {
  background-color: var(--aip-orange-hover);
  color: var(--aip-on-orange);
  text-decoration: none;
}

/* Outline / ghost: core "outline" style, or the aip-btn-ghost class. */
.is-style-outline .wp-block-button__link,
.aip-btn-ghost .wp-block-button__link {
  background: transparent;
  color: var(--aip-text-1);
  border: 1px solid var(--aip-border-strong);
}

.is-style-outline .wp-block-button__link:hover,
.aip-btn-ghost .wp-block-button__link:hover {
  background: var(--aip-surface-2);
  color: var(--aip-text-1);
}

.aip-btn-sm .wp-block-button__link {
  font-size: 0.875rem;
  padding: 0.625rem 1.125rem;
}

/* For use on the gradient hero only. */
.aip-btn-white .wp-block-button__link {
  background: #fff;
  color: #4D006D;
  font-weight: 700;
}

.aip-btn-white .wp-block-button__link:hover {
  background: #F4EEFB;
  color: #4D006D;
}

/* A translucent dark fill keeps white text >= AA over the orange part of the
   gradient (plain white-on-orange is 3.44:1). */
.aip-btn-ghost-white .wp-block-button__link {
  background: rgba(26, 10, 0, 0.55);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.aip-btn-ghost-white .wp-block-button__link:hover {
  background: rgba(26, 10, 0, 0.7);
  color: #fff;
}

/* ---------- Shared utilities ---------- */

.aip-container {
  max-width: 1240px;
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

/* Mono label. 0.75rem in an accent text colour, never raw brand orange. */
.aip-eyebrow {
  font-family: var(--aip-font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--aip-accent-orange);
  margin: 0 0 1rem;
}

.aip-eyebrow--purple { color: var(--aip-accent-purple); }
.aip-eyebrow--blue { color: var(--aip-accent-blue); }
.aip-eyebrow--muted { color: var(--aip-text-3); }
/* On the gradient hero: dark ink reads on orange, white reads on purple. White is
   used because the eyebrow is large-tracked and short; keep it to one line. */
.aip-eyebrow--on-hero { color: #fff; }

.aip-card {
  background: var(--aip-surface-2);
  border: 1px solid var(--aip-border);
  border-radius: 14px;
  padding: 1.5rem;
}

.aip-card--orange { border-top: 3px solid var(--aip-brand-orange); }
.aip-card--purple { border-top: 3px solid var(--aip-brand-purple-bright); }
.aip-card--blue { border-top: 3px solid var(--aip-brand-blue); }

.aip-pill {
  display: inline-block;
  font-family: var(--aip-font-mono);
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--aip-text-2);
  border: 1px solid var(--aip-border-strong);
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  margin: 0;
}

.aip-pill--hot {
  background: var(--aip-brand-orange);
  border-color: var(--aip-brand-orange);
  color: var(--aip-on-orange);
}

/* Icon tile (ritual steps). Icons are white PNGs, shown on the orange fill. */
.aip-tile {
  width: 62px;
  height: 62px;
  border-radius: 14px;
  background: var(--aip-brand-orange);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(255, 69, 0, 0.3);
}

.aip-tile img {
  width: 38px;
  height: 38px;
}

.aip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 1.5rem;
}

.aip-grid > * {
  margin: 0;
}

/* Signature gradient hero. Use once per page. */
.aip-hero {
  position: relative;
  overflow: hidden;
  background: var(--aip-gradient-signature);
  color: #fff;
}

/* Wire-cup sketch overlay: one instance, 0.3 opacity (design files vary .2 to .34). */
.aip-hero::before {
  content: "";
  position: absolute;
  left: -60px;
  bottom: -120px;
  width: 520px;
  height: 520px;
  background: url("../images/cup-wire-lines.svg") no-repeat left bottom / contain;
  opacity: 0.3;
  pointer-events: none;
}

.aip-hero > * {
  position: relative;
}

.aip-hero h1,
.aip-hero h2,
.aip-hero h3 {
  color: #fff;
}

.aip-hero a:not(.wp-block-button__link) {
  color: #fff;
  text-decoration: underline;
}

/* ---------- Quick answer ---------- */

.aip-quick-answer,
.is-style-aip-quick-answer {
  background: var(--aip-surface-2);
  border: 1px solid var(--aip-border);
  border-left: 4px solid var(--aip-brand-orange);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
}

.aip-quick-answer > :first-child,
.is-style-aip-quick-answer > :first-child {
  margin-top: 0;
}

.aip-quick-answer > :last-child,
.is-style-aip-quick-answer > :last-child {
  margin-bottom: 0;
}

/* ---------- FAQ (also the hook inc/seo.php reads for FAQPage JSON-LD) ---------- */

.aip-faq {
  display: grid;
  gap: 0.75rem;
}

.aip-faq > * {
  margin: 0;
}

.aip-faq .wp-block-details summary,
.wp-block-details.is-style-aip-faq-item summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--aip-text-1);
  list-style-position: outside;
}

.aip-faq .wp-block-details[open] summary {
  margin-bottom: 0.75rem;
}

.aip-faq .wp-block-details p {
  color: var(--aip-text-2);
}

/* ---------- Block styles ---------- */

.wp-block-quote.is-style-aip-pull-quote {
  border-left-width: 4px;
  font-family: var(--aip-font-display);
  font-size: var(--wp--preset--font-size--lead, 1.5rem);
  font-weight: 600;
  line-height: 1.3;
  padding-left: 1.5rem;
}

.wp-block-details.is-style-aip-faq-item {
  background: var(--aip-surface-1);
}

/* ---------- Blog lists ---------- */

.aip-post-card {
  border-top: 1px solid var(--aip-hairline);
  padding-block: 1.5rem;
}

.aip-post-card > * {
  margin-block: 0.5rem;
}

.wp-block-query-pagination {
  margin-top: 2rem;
  gap: 1rem;
}

/* ---------- 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;
  }
}
