/* ==========================================================================
   Our approach (/implementation/). Built on tokens.css + base.css.
   The ash tree is most explicit here: the branch explorer draws MELIA as the
   trunk and each area of work as a branch.
   ========================================================================== */

/* ---- Intro ----------------------------------------------------------------- */
.ap-hero { padding-block: clamp(var(--space-7), 2rem + 4vw, var(--space-9)) clamp(var(--space-6), 1.5rem + 3vw, var(--space-8)); }
.ap-hero__grid { display: grid; gap: var(--space-6); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .ap-hero__grid { grid-template-columns: 6fr 5fr; gap: var(--space-8); align-items: end; } }
.ap-hero h1 { font-size: var(--text-4xl); font-weight: 350; line-height: 1.02; letter-spacing: -0.03em; max-width: 11ch; }
.ap-hero__note { margin-top: var(--space-5); padding-top: var(--space-4); border-top: var(--rule); font-size: var(--text-sm); color: var(--color-text-soft); max-width: 52ch; }

/* ---- Explorer -------------------------------------------------------------- */
.ap-tree { padding-block: var(--space-6) var(--space-section); }
.ap-tree__head { display: grid; gap: var(--space-5); margin-bottom: var(--space-7); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .ap-tree__head { grid-template-columns: 3fr 9fr; } }
.ap-tree__head h2 { max-width: 20ch; }
.ap-tree__head .lede { margin-top: var(--space-4); }

.explorer { display: grid; gap: var(--space-6); grid-template-columns: minmax(0, 1fr); border-top: var(--rule-strong); padding-top: var(--space-6); }
@media (min-width: 1000px) {
  .explorer { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--space-6) var(--space-8); align-items: start; }
  .explorer__stage { grid-column: 1; grid-row: 2; }
  .anatomy { grid-column: 1; grid-row: 3; }
  .explorer__panels { grid-column: 2; grid-row: 2 / span 2; }
}

.explorer__stage { position: relative; max-width: 640px; width: 100%; justify-self: center; }
.explorer__svg { width: 100%; height: auto; overflow: visible; }
/* The tree is drawn in filled shapes: tapering wood, compound leaves.
   At rest it is quiet (sage wood and foliage); the chosen branch comes
   alive in charcoal wood and green leaves, with a few turned to brass. */
.ex-ground { stroke: var(--branch-trunk); stroke-width: 1.2; }
.ex-root { fill: var(--branch-root); }
.ex-limb { fill: var(--wood-idle); transition: fill var(--dur-med), opacity var(--dur-med); }
.ex-limb:not([data-branch]) { fill: var(--branch-trunk); }  /* the trunk */
.ex-leaf { fill: var(--leaf-idle); transition: fill var(--dur-med), opacity var(--dur-med); }
.ex-branches path { fill: none; stroke: none; pointer-events: none; }  /* geometry only */
.ex-trunk-mark circle { fill: var(--color-primary); stroke: var(--color-bg); stroke-width: 2; }
.ex-trunk-mark path { fill: var(--ivory-50); }

.ex-limb.is-hover { fill: var(--ink-600); }
.ex-leaf.is-hover { fill: var(--sage-400); }
.ex-limb.is-active { fill: var(--branch-trunk); }
.ex-leaf.is-active { fill: var(--leaf-a); }
.ex-leaf--b.is-active { fill: var(--leaf-b); }
.ex-leaf--c.is-active { fill: var(--leaf-c); }
.ex-leaf--o.is-active { fill: var(--branch-leaf); }
/* the chosen branch leafs out again each time it is chosen */
.ex-leaf.is-growing { animation: ash-fade 600ms var(--ease-out) both; }
/* Filtered out: still there, still selectable, quieter. */
.ex-limb.is-dim:not(.is-active), .ex-leaf.is-dim:not(.is-active) { opacity: .35; }
.branch-tab.is-dim:not([aria-selected="true"]) { color: var(--color-text-soft); border-style: dashed; background: transparent; }

/* First growth (with JS): roots spread, wood rises, leaves come out. */
.js .explorer__svg .ex-roots { animation: ash-roots 1s var(--ease-out) both; }
.js .explorer__svg .ex-wood { animation: ash-rise 1.5s var(--ease-in-out) 250ms both; }
.js .explorer__svg .ex-leaves { animation: ash-fade 900ms var(--ease-out) 1300ms both; }
@keyframes ash-roots { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes ash-rise { from { clip-path: inset(100% 0 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes ash-fade { from { opacity: 0; } }

/* Sprouts: a twig and a compound leaf for each example in the panel,
   numbered to match the list. */
.ex-sprout path { fill: none; stroke: var(--branch-trunk); stroke-width: 1.3; stroke-linecap: round;
  stroke-dasharray: 1; stroke-dashoffset: 1; animation: ex-grow 600ms var(--ease-out) both; animation-delay: calc(350ms + var(--k) * 140ms); }
.ex-sprout use { fill: var(--leaf-a); animation: ash-fade 500ms var(--ease-out) both; animation-delay: calc(700ms + var(--k) * 140ms);
  transition: fill var(--dur-fast); }
.ex-sprout text { font: 500 11px var(--font-mono); text-anchor: middle; dominant-baseline: central; fill: var(--brass-700);
  paint-order: stroke; stroke: var(--color-bg); stroke-width: 4px; stroke-linejoin: round;
  animation: ash-fade 400ms var(--ease-out) both; animation-delay: calc(850ms + var(--k) * 140ms); }
.ex-sprout.is-lit use { fill: var(--branch-leaf); }
.ex-sprout.is-lit path { stroke-width: 2; }
.ex-sprout.is-lit text { fill: var(--color-text); }
@keyframes ex-grow { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .ex-sprout path, .ex-sprout use, .ex-sprout text, .ex-leaf.is-growing, .js .explorer__svg g { animation: none !important; stroke-dashoffset: 0; }
}

/* Filter chips */
.explorer__filter { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
html:not(.js) .explorer__filter { display: none; }
.explorer__filter-label { margin-right: var(--space-2); font: 500 11px var(--font-mono); letter-spacing: var(--tracking-mono); text-transform: uppercase; color: var(--color-accent); }
.filter-chip {
  min-height: 40px; padding: .4rem .9rem; border-radius: var(--radius-pill);
  font: 500 var(--text-xs)/1.2 var(--font-sans); color: var(--color-text-soft);
  background: transparent; border: 1px solid var(--color-line); cursor: pointer;
  transition: color var(--dur-fast), border-color var(--dur-fast), background var(--dur-fast);
}
.filter-chip:hover { color: var(--color-text); border-color: var(--color-text); }
.filter-chip[aria-pressed="true"] { color: var(--color-text); border-color: var(--color-text); background: var(--color-surface); box-shadow: inset 0 -2px 0 var(--color-primary); }
@media (max-width: 559px) { .explorer__filter-label { flex-basis: 100%; } }

/* How to read the tree */
.anatomy { list-style: none; margin: var(--space-7) 0 0; padding: var(--space-3) 0 0; border-top: var(--rule);
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3) var(--space-5); }
@media (min-width: 1000px) { .anatomy { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.anatomy__item { display: grid; grid-template-columns: 22px 1fr; column-gap: var(--space-2); align-items: baseline;
  font-size: var(--text-xs); line-height: 1.4; color: var(--color-text-soft); }
.anatomy__item b { font: italic 400 var(--text-sm) var(--font-serif); color: var(--color-text); display: block; grid-column: 2; }
.anatomy__item { grid-template-rows: auto auto; }
.anatomy__glyph { grid-row: 1 / span 2; align-self: center; width: 18px; height: 18px; position: relative; }
.anatomy__item--roots .anatomy__glyph { border-bottom: 1.3px solid var(--branch-root); border-left: 1.3px solid var(--branch-root); border-radius: 0 0 0 12px; width: 12px; height: 12px; margin-left: 4px; }
.anatomy__item--trunk .anatomy__glyph::before { content: ""; position: absolute; left: 7px; top: 0; bottom: 0; width: 4px; background: var(--branch-trunk); }
.anatomy__item--branches .anatomy__glyph { border-top: 1.6px solid var(--branch-trunk); border-left: 1.6px solid var(--branch-trunk); border-radius: 14px 0 0 0; width: 14px; height: 14px; margin-left: 3px; }
.anatomy__item--leaves .anatomy__glyph::before { content: ""; position: absolute; left: 6px; top: 2px; width: 7px; height: 14px; border-radius: 100% 0; transform: rotate(35deg); background: var(--branch-leaf); }

/* wider, invisible twins of the limbs take the pointer */
.ex-hits path { fill: none; stroke: transparent; stroke-width: 26; stroke-linecap: round; pointer-events: none; }
.is-interactive .ex-hits path { pointer-events: stroke; cursor: pointer; }

/* Branch tabs: set at the tip of each drawn branch on wide screens. */
.explorer__tabs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr)); gap: var(--space-2); margin-top: var(--space-5); }
html:not(.js) .explorer__tabs { display: none; }
.branch-tab {
  display: inline-flex; align-items: center; gap: .5em;
  min-height: 44px; padding: .5rem .85rem;
  font: 500 var(--text-sm)/1.2 var(--font-sans); color: var(--color-text); text-align: left;
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-pill);
  cursor: pointer; transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
}
.branch-tab::before {
  content: ""; flex: none; width: 9px; height: 9px; border-radius: 50%;
  background: var(--color-bg); border: 1.5px solid var(--sage-400);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.branch-tab__num { font: 400 11px var(--font-mono); color: var(--color-accent); }
.branch-tab:hover, .branch-tab.is-hover { border-color: var(--forest-700); }
.branch-tab[aria-selected="true"] { background: var(--forest-700); border-color: var(--forest-700); color: var(--ivory-50); box-shadow: 0 10px 24px -14px rgba(18, 38, 28, .6); }
.branch-tab[aria-selected="true"] .branch-tab__num { color: var(--sage-200); }
.branch-tab[aria-selected="true"]::before { background: var(--color-leaf); border-color: var(--color-leaf); }

@media (min-width: 760px) {
  .explorer__tabs { display: block; margin: 0; }
  /* Each label sits centred above the tip of its branch. */
  .branch-tab {
    position: absolute; left: calc(var(--x) * 1%); top: calc(var(--y) * 1%);
    width: max-content; max-width: 9.75rem; white-space: normal; justify-content: center; text-align: center;
    padding: .45rem .8rem; transform: translate(-50%, calc(-100% - 30px));
  }
  .branch-tab::before { display: none; }
  html:not(.js) .explorer__tabs { display: none; }
}
.explorer__trunk {
  position: absolute; left: 50%; top: 100%; transform: translateX(-50%);
  margin: 0; width: max-content; text-align: center;
  font: 400 11px var(--font-mono); letter-spacing: .04em; color: var(--color-text-soft);
}
.explorer__trunk b { display: block; font: 500 12px var(--font-mono); letter-spacing: .24em; color: var(--color-text); }
@media (max-width: 759px) { .explorer__trunk { display: none; } }

/* Panels */
.explorer__panels { display: grid; gap: var(--space-5); }
.branch-panel {
  padding: clamp(1.25rem, 1rem + 1.5vw, 2.25rem);
  background: var(--color-surface); border: var(--rule); border-top: var(--rule-accent); border-radius: var(--radius-plate);
  box-shadow: var(--shadow-plate);
}
.is-interactive .branch-panel { animation: panel-in 420ms var(--ease-out) both; }
@keyframes panel-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .is-interactive .branch-panel { animation: none; } }
.branch-panel:focus-visible { outline-offset: 4px; }
.branch-panel__kicker { margin: 0 0 var(--space-3); font: 500 12px var(--font-mono); letter-spacing: var(--tracking-mono); text-transform: uppercase; color: var(--color-accent); }
.branch-panel__title { font-size: var(--text-2xl); line-height: 1.1; margin-bottom: var(--space-4); }
.branch-panel__lede { color: var(--color-text-soft); }
.branch-panel__cols { display: grid; gap: var(--space-5); margin-top: var(--space-5); padding-top: var(--space-4); border-top: var(--rule); }
.branch-panel h4 { margin: 0 0 var(--space-3); font: 500 12px var(--font-mono); letter-spacing: var(--tracking-mono); text-transform: uppercase; color: var(--color-text); }
.branch-panel ul, .branch-panel ol { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.branch-panel li { position: relative; padding-left: 1.4rem; font-size: var(--text-sm); line-height: 1.5; }
.branch-panel li::before { content: ""; position: absolute; left: 0; top: .55em; width: .75rem; border-top: 1.5px solid var(--forest-700); }
.branch-panel__roots { margin: var(--space-4) 0 0; padding-left: var(--space-4); border-left: var(--branch-w-root) solid var(--branch-root); font-size: var(--text-sm); line-height: 1.55; color: var(--color-text); }
.branch-panel__roots span { display: block; margin-bottom: 2px; font: 500 11px var(--font-mono); letter-spacing: var(--tracking-mono); text-transform: uppercase; color: var(--color-accent); }
/* Examples are numbered to match the leaves that sprout on the drawing. */
.branch-panel__build { counter-reset: sprout; }
.branch-panel__build li { counter-increment: sprout; padding-left: 1.9rem; cursor: default; }
.branch-panel__build li::before {
  content: counter(sprout); width: 1.25rem; height: 1.25rem; top: .1em; border: 1.5px solid var(--branch-leaf); border-radius: 50%;
  display: grid; place-items: center; font: 500 10px/1 var(--font-mono); color: var(--brass-700);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.branch-panel__build li:hover::before { background: var(--branch-leaf); color: var(--ivory-50); }
.branch-panel__measures li::before { width: 7px; height: 7px; border: 0; border-radius: 50%; background: var(--color-leaf); top: .5em; left: 2px; }
.branch-panel__for { margin: var(--space-5) 0 0; font-size: var(--text-xs); color: var(--color-text-soft); }
.branch-panel__for span { font: 500 11px var(--font-mono); letter-spacing: var(--tracking-mono); text-transform: uppercase; color: var(--color-accent); margin-right: .5em; }
.explorer__disclaimer { margin: 0; font-size: var(--text-xs); line-height: 1.55; color: var(--color-text-soft); max-width: 52ch; }

/* ---- Method ---------------------------------------------------------------- */
.method { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; border-top: var(--rule-strong); counter-reset: m; }
@media (min-width: 760px) { .method { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .method { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.method__step { padding: var(--space-5) var(--space-5) var(--space-6) 0; border-bottom: var(--rule); counter-increment: m; }
.method__step .grow__glyph { margin-bottom: var(--space-4); }
@media (min-width: 1100px) { .method__step { border-bottom: 0; } .method__step + .method__step { padding-left: var(--space-5); border-left: var(--rule); } }
.method__part { margin: 0 0 var(--space-4); font: 500 12px var(--font-mono); letter-spacing: var(--tracking-mono); text-transform: uppercase; color: var(--color-accent); }
.method__part::before { content: "0" counter(m) " · "; }
.method__step h3 { font-size: var(--text-xl); margin-bottom: var(--space-3); }
.method__step > p:not(.method__part):not(.method__out) { font-size: var(--text-sm); color: var(--color-text-soft); line-height: 1.6; }
.method__out { margin-top: var(--space-4); padding: var(--space-3) var(--space-4); background: var(--color-surface); border-left: 2px solid var(--color-leaf); font-size: var(--text-xs); line-height: 1.55; color: var(--color-text); }
.method__out span { display: block; margin-bottom: 2px; font: 500 11px var(--font-mono); letter-spacing: var(--tracking-mono); text-transform: uppercase; color: var(--brass-700); }

/* ---- Principles ------------------------------------------------------------ */
.ap-principles__grid { display: grid; gap: var(--space-7); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .ap-principles__grid { grid-template-columns: 4fr 8fr; gap: var(--space-8); } }
.ap-principles .section-marker { margin-bottom: var(--space-6); max-width: 16rem; }
.ap-principles h2 { max-width: 12ch; }
.contrast { margin: 0; display: grid; gap: 0; border-top: var(--rule-strong); }
@media (min-width: 700px) { .contrast { grid-template-columns: 1fr 1fr; column-gap: var(--space-6); } }
.contrast > div { padding-block: var(--space-5); border-bottom: var(--rule); }
.contrast dt { font: 400 var(--text-xl)/1.2 var(--font-serif); margin-bottom: var(--space-2); }
.contrast dd { margin: 0; font-size: var(--text-sm); line-height: 1.6; color: var(--color-text-soft); }

/* ---- CTA ------------------------------------------------------------------- */
.ap-cta__grid { display: grid; gap: var(--space-6); grid-template-columns: minmax(0, 1fr); align-items: end; }
@media (min-width: 900px) { .ap-cta__grid { grid-template-columns: 7fr 5fr; } .ap-cta .actions { justify-content: flex-end; } }
.ap-cta .section-marker { max-width: 14rem; margin-bottom: var(--space-5); }
.ap-cta h2 { max-width: 16ch; margin-bottom: var(--space-4); }
