/* =============================================================================
   NATURHAUS WECHSELLAND — Technik-Seite: interaktive Bauteile & Bauphysik
   Loaded only on technik.html. Builds on brand.css tokens.
   Components:
     1. .tech-fig  — interactive freigestellte drawing (raster + SVG hotspots),
                     popover shows the component's layer build-up
     2. .roles     — material-roles triad (Stroh · Lehm · Holz · Kalk)
   ========================================================================== */

/* ---------- 1 · Interactive figure -------------------------------------- */
.tech-fig {
  position: relative;
  display: block;
  width: 100%;
  margin: 0;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  overflow: visible;            /* let popover/label spill out */
  --hl: var(--terracotta);
}
.tech-fig__frame {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
}
.tech-fig--portrait { max-width: 340px; margin-inline: auto; }
.tech-fig--wide     { max-width: 560px; margin-inline: auto; }

.tech-fig__img { width: 100%; height: auto; display: block; }

.tech-fig__svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible;
}

/* a hotspot = focusable group holding an invisible hit-shape + a visible pin */
.tech-hotspot { cursor: pointer; outline: none; }
.tech-hotspot__hit {
  fill: rgba(175, 110, 78, 0);     /* transparent terracotta */
  stroke: transparent;
  stroke-width: 3;
  pointer-events: all;             /* whole region hoverable, paint irrelevant */
  transition: fill var(--dur) var(--ease), stroke var(--dur) var(--ease);
  vector-effect: non-scaling-stroke;
}
.tech-hotspot:hover  .tech-hotspot__hit,
.tech-hotspot:focus-visible .tech-hotspot__hit,
.tech-hotspot.is-active .tech-hotspot__hit {
  fill: rgba(175, 110, 78, 0);
  stroke: transparent;
}
/* dim the others while one part is open, to focus attention */
.tech-fig.is-open .tech-hotspot:not(.is-active) .tech-hotspot__hit { fill: rgba(68,62,59,0.04); }

/* pin marker (discoverability + guaranteed tap target) */
.tech-pin__ring {
  fill: var(--paper);
  stroke: var(--terracotta);
  stroke-width: 2;
  transition: transform var(--dur) var(--ease);
  transform-box: fill-box;
  transform-origin: center;
}
.tech-pin__plus { stroke: var(--terracotta-700); stroke-width: 2.2; stroke-linecap: round; }
.tech-pin__pulse {
  fill: none; stroke: var(--terracotta); stroke-width: 2; opacity: 0;
  transform-box: fill-box; transform-origin: center;
}
.tech-hotspot:hover .tech-pin__ring,
.tech-hotspot:focus-visible .tech-pin__ring { transform: scale(1.18); }
.tech-hotspot.is-active .tech-pin__ring { fill: var(--terracotta); }
.tech-hotspot.is-active .tech-pin__plus { stroke: var(--paper); }
/* idle attract pulse on the pins (motion only) */
@media (prefers-reduced-motion: no-preference) {
  .tech-pin__pulse { animation: pinPulse 3.2s var(--ease) infinite; }
  .tech-hotspot:nth-of-type(2) .tech-pin__pulse { animation-delay: .5s; }
  .tech-hotspot:nth-of-type(3) .tech-pin__pulse { animation-delay: 1s; }
  .tech-hotspot:nth-of-type(4) .tech-pin__pulse { animation-delay: 1.5s; }
  .tech-hotspot:nth-of-type(5) .tech-pin__pulse { animation-delay: 2s; }
  .tech-hotspot:hover .tech-pin__pulse,
  .tech-hotspot.is-active .tech-pin__pulse { animation: none; }
}
@keyframes pinPulse {
  0%   { opacity: .55; transform: scale(1); }
  70%  { opacity: 0;   transform: scale(2.4); }
  100% { opacity: 0;   transform: scale(2.4); }
}

/* pause looping animations while their section is off-screen (set by JS) */
.tech-fig.is-offscreen .tech-pin__pulse { animation-play-state: paused; }

/* hover/focus name label (custom tooltip) */
.tech-label {
  position: absolute; z-index: 6;
  left: 0; top: 0;
  transform: translate(-50%, -130%);
  padding: 6px 12px;
  background: var(--stone); color: var(--paper);
  font-size: var(--fs-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  border-radius: 100px; white-space: nowrap;
  box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none;
  transition: opacity .18s var(--ease);
}
.tech-label.is-shown { opacity: 1; }
.tech-label::after {
  content: ""; position: absolute; left: 50%; bottom: -5px;
  width: 10px; height: 10px; background: var(--stone);
  transform: translateX(-50%) rotate(45deg);
}

/* detail popover */
.tech-pop {
  position: absolute; z-index: 8;
  width: min(300px, 78vw);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s-6);
  max-height: min(76vh, 580px); overflow-y: auto;
  opacity: 0; transform: translateY(8px) scale(.98);
  transform-origin: top center;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
/* the [hidden] attribute (display:none) does the actual hiding; opacity/transform animate */
.tech-pop.is-open { opacity: 1; transform: none; }
.tech-pop__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); }
.tech-pop__num {
  font-family: var(--font-display); font-size: var(--fs-lg);
  color: var(--terracotta-700); line-height: 1; flex: none;
}
.tech-pop__title { font-family: var(--font-display); font-size: var(--fs-lg); color: var(--stone); line-height: 1.1; }
.tech-pop__close {
  flex: none; width: 40px; height: 40px; border-radius: 100px;
  display: grid; place-items: center; color: var(--muted);
  background: var(--clay-100); font-size: 1.1rem; line-height: 1;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tech-pop__close:hover { background: var(--stone); color: var(--paper); }
.tech-pop__tag {
  display: inline-block; margin-top: var(--s-3);
  padding: 3px 10px; border-radius: 100px;
  background: var(--sand-200); color: var(--terracotta-700);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em;
}
.tech-pop__body { margin-top: var(--s-3); color: var(--muted); font-size: var(--fs-sm); line-height: 1.6; }
.tech-pop__feat { margin-top: var(--s-4); list-style: none; padding: 0; display: grid; gap: var(--s-2); }
.tech-pop__feat li {
  position: relative; padding-left: 20px;
  font-size: var(--fs-sm); color: var(--stone); line-height: 1.45;
}
.tech-pop__feat li::before {
  content: ""; position: absolute; left: 0; top: .5em;
  width: 7px; height: 7px; border-right: 2px solid var(--terracotta);
  border-top: 2px solid var(--terracotta); transform: rotate(45deg);
}

/* layer build-up list inside the popover (shows the part's Schichten) */
.tech-pop__layers { margin-top: var(--s-4); }
.tech-pop__layers-h {
  font-family: var(--font-body); font-weight: 700; text-transform: uppercase;
  letter-spacing: var(--tracking-caps); font-size: var(--fs-xs); color: var(--stone);
  margin-bottom: var(--s-2);
}
.tech-pop__layers-h span { color: var(--muted); font-weight: 500; letter-spacing: .03em; }
.tech-pop__layers ol {
  counter-reset: ly; list-style: none; margin: 0; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.tech-pop__layers li {
  counter-increment: ly; position: relative;
  padding: 8px 10px 8px 36px;
  font-size: var(--fs-sm); color: var(--stone); line-height: 1.3;
  border-top: 1px solid var(--line);
}
.tech-pop__layers li:first-child { border-top: 0; }
.tech-pop__layers li:nth-child(odd) { background: var(--cream); }
.tech-pop__layers li::before {
  content: counter(ly); position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; border-radius: 100px;
  background: var(--sand-200); color: var(--terracotta-700);
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
}

/* hint row under the figure */
.tech-hint {
  display: inline-flex; align-items: center; gap: var(--s-2);
  margin-top: var(--s-4);
  font-size: var(--fs-sm); color: var(--muted);
}
.tech-hint svg { width: 18px; height: 18px; color: var(--terracotta); flex: none; }
.tech-hint a { color: var(--terracotta-700); font-weight: 600; }
.tech-hint a:hover { text-decoration: underline; }

/* mobile: popover becomes a bottom sheet */
@media (max-width: 620px) {
  .tech-pop {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; max-width: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
    max-height: 82vh; overflow-y: auto;
    padding-bottom: calc(var(--s-8) + env(safe-area-inset-bottom, 0px));
  }
  .tech-pop.is-open { transform: none; }
  .tech-fig.is-open::after {       /* scrim */
    content: ""; position: fixed; inset: 0; z-index: 7;
    background: rgba(46,42,40,.45); animation: fadeIn .25s var(--ease);
  }
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

/* ---------- 3 · Material roles triad ------------------------------------ */
.roles { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-6); }
@media (max-width: 980px) { .roles { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .roles { grid-template-columns: 1fr; } }

.role {
  position: relative; background: var(--paper);
  border-radius: var(--radius-lg); padding: var(--s-8);
  box-shadow: var(--shadow-sm); overflow: hidden;
  border-top: 4px solid var(--role, var(--terracotta));
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.role:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); }
.role::before {            /* soft tonal wash from the material colour */
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: radial-gradient(120% 80% at 100% 0%, var(--wash, transparent), transparent 60%);
  opacity: .5; pointer-events: none;
}
.role > * { position: relative; z-index: 1; }
.role__icon {
  width: 48px; height: 48px; margin-bottom: var(--s-4);
  display: grid; place-items: center; border-radius: 12px;
  background: var(--wash, var(--clay-100)); color: var(--role-ink, var(--terracotta-700));
}
.role__icon svg { width: 28px; height: 28px; }
.role__job {
  font-family: var(--font-body); font-weight: 700; text-transform: uppercase;
  letter-spacing: var(--tracking-caps); font-size: var(--fs-xs);
  color: var(--role-ink, var(--terracotta-700));
}
.role h3 { font-size: var(--fs-xl); margin: var(--s-1) 0 var(--s-3); }
.role p { color: var(--muted); font-size: var(--fs-sm); line-height: 1.6; }
.role__tag {
  display: inline-block; margin-top: var(--s-4);
  font-size: var(--fs-xs); font-weight: 600; color: var(--muted);
  padding: 3px 10px; border: 1px solid var(--line); border-radius: 100px;
}

/* per-material palette (tokens stay brand-true) */
.role--stroh { --role: var(--sand);       --role-ink: #8a6f3e; --wash: #efe3c8; }
.role--lehm  { --role: var(--terracotta); --role-ink: var(--terracotta-700); --wash: #efd9cc; }
.role--holz  { --role: var(--stone-700);  --role-ink: var(--stone-700); --wash: #e2d6cb; }
.role--kalk  { --role: var(--clay);       --role-ink: #6f6359; --wash: #ece8e3; }

/* ---------- Text wrapping polish (baseline-ui) --------------------------- */
.role p, .tech-pop__body, .tech-hint { text-wrap: pretty; }

/* ---------- 4 · Sticky Sprungnavigation (subnav) ------------------------- */
/* --header-h is measured by technik.js; 93px fallback matches the header.  */
.subnav {
  position: sticky; top: calc(var(--header-h, 93px) - 1px); z-index: 90;
  background: color-mix(in srgb, var(--cream) 92%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-block: 1px solid var(--line);
}
.subnav__track {
  display: flex; gap: var(--s-2);
  padding-block: var(--s-3);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.subnav__track::-webkit-scrollbar { display: none; }
.subnav a {
  flex: none; display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: 40px; padding: var(--s-2) var(--s-4);
  border: 1px solid var(--line); border-radius: 100px;
  background: var(--paper); color: var(--muted);
  font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              background var(--dur) var(--ease);
}
.subnav a:hover { border-color: var(--terracotta); color: var(--terracotta-700); }
.subnav a.is-current { background: var(--stone); border-color: var(--stone); color: var(--paper); }

/* anchored sections land below header + subnav */
.section[id] { scroll-margin-top: calc(var(--header-h, 93px) + 72px); }

/* ---------- 5 · Layer list (numbered build-up, used by Wand & Dach) ------ */
.layer-list { margin-top: var(--s-8); list-style: none; padding: var(--s-8); display: grid; gap: var(--s-6); }
.layer-list li { display: flex; gap: var(--s-4); align-items: baseline; }
.layer-list__num { font-family: var(--font-display); font-size: var(--fs-lg); color: var(--terracotta-700); flex: none; }
.layer-list .subhead { font-size: var(--fs-base); display: block; margin-bottom: var(--s-1); }
.layer-list__d { color: var(--muted); font-size: var(--fs-sm); }

/* ---------- 6 · Dach diagram --------------------------------------------- */
.dach-fig {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--s-6) var(--s-6) var(--s-4);
}
.dach-fig svg { width: 100%; height: auto; display: block; }
.dach-fig .caption-static { margin-top: var(--s-3); }

/* ---------- 7 · Comparison table ----------------------------------------- */
.compare-hint {
  display: none;
  align-items: center; gap: var(--s-2);
  font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s-3);
}
.compare-hint svg { width: 18px; height: 18px; color: var(--terracotta); flex: none; }
@media (max-width: 680px) { .compare-hint { display: flex; } }

.compare {
  position: relative;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--paper); box-shadow: var(--shadow-sm);
}
/* soft edge fade hints there's more table to scroll to (mobile only, decorative) */
.compare::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 28px;
  background: linear-gradient(to right, transparent, var(--paper));
  pointer-events: none;
}
@media (min-width: 681px) { .compare::after { display: none; } }
.compare:focus-visible { outline: 3px solid var(--terracotta); outline-offset: 3px; }
.compare table { width: 100%; border-collapse: collapse; min-width: 620px; font-size: var(--fs-sm); }
.compare th, .compare td {
  padding: var(--s-4) var(--s-6); text-align: left; vertical-align: top;
  border-top: 1px solid var(--line); line-height: 1.55;
}
.compare thead th {
  border-top: 0; font-family: var(--font-body); font-weight: 700;
  text-transform: uppercase; letter-spacing: var(--tracking-caps);
  font-size: var(--fs-xs); color: var(--muted);
}
.compare tbody th { font-weight: 600; color: var(--stone); width: 22%; }
.compare td { color: var(--muted); width: 39%; }
.compare .is-nh { background: color-mix(in srgb, var(--sand-200) 45%, transparent); }
.compare thead .is-nh { color: var(--terracotta-700); }
.compare td.is-nh { color: var(--stone); }
.compare td, .compare tbody th { text-wrap: pretty; }

/* dark variant inside .section--stone */
.section--stone .compare { background: transparent; border-color: rgba(255,255,255,.25); box-shadow: none; }
.section--stone .compare th, .section--stone .compare td { border-color: rgba(255,255,255,.16); }
.section--stone .compare thead th { color: rgba(255,255,255,.68); }
.section--stone .compare tbody th { color: var(--paper); }
.section--stone .compare td { color: rgba(255,255,255,.78); }
.section--stone .compare .is-nh { background: rgba(255,255,255,.07); }
.section--stone .compare thead th.is-nh { color: var(--sand); }
.section--stone .compare td.is-nh { color: #fff; }
.section--stone .caption-static { color: rgba(255,255,255,.6); }
