/* ==========================================================================
   Tri-Optikon — SWARMATIC
   Eine Fläche: links die Episode, rechts die fünf Triaden. Der Text bleibt
   sichtbar, weil eingeordnet wird, was dasteht — nicht was erinnert wird.
   Farbwerte sind Entwurf: gegen die echten Marken-Token tauschen.
   ========================================================================== */

:root {
  --paper:        #F4F2EC;
  --paper-deep:   #EAE6DC;
  --card:         #FBFAF6;
  --ink:          #16232C;
  --ink-soft:     #4C5A63;
  --ink-faint:    #8C979D;
  --forest:       #21493B;
  --petrol:       #1B5560;
  --amber:        #B8761A;
  --line:         #D6D1C5;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --measure: 62ch;
  --pad: clamp(1.25rem, 5vw, 4rem);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1rem, 0.6vw + 0.9rem, 1.125rem);
  line-height: 1.6;
}

/* --- Sprungmarke / Screenreader ------------------------------------------ */

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--paper);
  padding: 0.6rem 1rem; z-index: 60;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

.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;
}

/* --- Kopf ---------------------------------------------------------------- */

.masthead {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem var(--pad);
  background: linear-gradient(var(--paper) 68%, transparent);
  pointer-events: none;
}
.masthead a { pointer-events: auto; }

.wordmark {
  font-family: var(--sans);
  font-size: 0.9rem; font-weight: 600; letter-spacing: 0.02em;
  color: var(--ink); text-decoration: none;
}

.masthead-note {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-faint);
}

/* --- Typografie ---------------------------------------------------------- */

h1, h2 {
  font-weight: 400;
  line-height: 1.14;
  letter-spacing: -0.015em;
  margin: 0 0 1.1rem;
  text-wrap: balance;
}

h1 { font-size: clamp(2.1rem, 5.2vw, 3.5rem); }
h2 { font-size: clamp(1.55rem, 3.2vw, 2.15rem); }

.lede {
  margin: 0 0 1rem;
  color: var(--ink-soft);
  font-size: 1.04em;
  max-width: 54ch;
}

.fine {
  margin: 0 0 1.5rem;
  font-family: var(--sans);
  font-size: 0.85rem; line-height: 1.55;
  color: var(--ink-faint);
  max-width: 52ch;
}

a { color: var(--petrol); text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* --- Bildschirme --------------------------------------------------------- */

.screen { padding: 5.5rem var(--pad) 5rem; }
.screen[hidden] { display: none; }

.screen--open,
.screen--contact,
.screen--done {
  min-height: 100svh;
  display: flex; align-items: center; justify-content: center;
}

.column { width: 100%; max-width: var(--measure); }

/* --- Auftakt ------------------------------------------------------------- */

.open-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.92fr);
  gap: clamp(2rem, 5vw, 5rem);
  align-items: center;
  width: 100%; max-width: 78rem;
}

.open-text { max-width: 34ch; }
.open-demo { min-width: 0; }

@media (max-width: 860px) {
  .open-grid { grid-template-columns: 1fr; }
  .open-demo { order: -1; }
  .open-text { max-width: none; }
}

/* --- Knöpfe -------------------------------------------------------------- */

.btn {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.92rem; font-weight: 500; line-height: 1;
  padding: 0.85rem 1.5rem;
  border: 1px solid transparent; border-radius: 2px;
  cursor: pointer; text-decoration: none;
  transition: background-color 120ms ease, color 120ms ease, opacity 120ms ease;
}

.btn--primary { background: var(--forest); color: var(--paper); }
.btn--primary:hover { background: var(--ink); }

.btn--quiet {
  background: transparent; color: var(--ink-soft);
  border-color: var(--line);
}
.btn--quiet:hover { color: var(--ink); border-color: var(--ink-faint); }

.btn--small { padding: 0.6rem 1.05rem; font-size: 0.85rem; }

.btn:disabled { opacity: 0.3; cursor: default; }
.btn--primary:disabled:hover { background: var(--forest); }

.btn:focus-visible,
textarea:focus-visible,
input:focus-visible,
summary:focus-visible,
.triad-plot:focus-visible {
  outline: 2px solid var(--petrol);
  outline-offset: 3px;
}

.actions { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: center; }

/* --- Arbeitsfläche ------------------------------------------------------- */

.work {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4.5rem);
  width: 100%; max-width: 82rem; margin: 0 auto;
  align-items: start;
}

.work-story { position: sticky; top: 5.5rem; }

.story-inner {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: clamp(1.2rem, 2.4vw, 2rem);
}

textarea {
  width: 100%;
  font-family: var(--serif);
  font-size: 1rem; line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line); border-radius: 2px;
  padding: 1rem 1.1rem;
  resize: vertical;
}
textarea::placeholder { color: var(--ink-faint); }

.story-note {
  margin: 0.7rem 0 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.work-triads { min-width: 0; }

@media (max-width: 900px) {
  .work { grid-template-columns: 1fr; }
  .work-story { position: static; }
  textarea { min-height: 11rem; }
}

/* --- Triade -------------------------------------------------------------- */

.triad {
  padding-bottom: clamp(3rem, 7vw, 5.5rem);
}
.triad + .triad {
  border-top: 1px solid var(--line);
  padding-top: clamp(2.5rem, 6vw, 4rem);
}

.triad-head { margin-bottom: 1.5rem; }

.triad-question {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.35rem, 2.6vw, 1.85rem);
  line-height: 1.18; letter-spacing: -0.012em;
  margin: 0 0 0.4rem;
  text-wrap: balance;
}

.triad-sub {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-faint);
}

.triad-frame {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem 1.2rem;
  align-items: start;
}

.corner {
  font-family: var(--sans);
  font-size: 0.85rem; line-height: 1.45;
  color: var(--ink-soft);
  margin: 0; max-width: 28ch;
}
.corner--a { grid-column: 1 / -1; justify-self: center; text-align: center; }
.corner--b { justify-self: start; }
.corner--c { justify-self: end; text-align: right; }

.plot-cell { grid-column: 1 / -1; }

.triad-plot {
  display: block; width: 100%; height: auto;
  touch-action: none; cursor: crosshair;
  transition: opacity 160ms ease;
}

.tri-edge {
  fill: rgba(27, 85, 96, 0.045);
  stroke: var(--petrol); stroke-width: 1.25;
}
.tri-median { stroke: var(--petrol); stroke-width: 0.75; opacity: 0.16; }
.tri-vertex { fill: var(--petrol); opacity: 0.5; }
.tri-marker-halo { fill: var(--amber); opacity: 0.14; }
.tri-marker { fill: var(--amber); stroke: var(--card); stroke-width: 2.5; }

/* Geschlossen: der Punkt bekommt einen Ring und die Fläche wird still. */
.tri-marker-ring {
  fill: none;
  stroke: var(--amber);
  stroke-width: 1;
  opacity: 0.45;
}

.triad-plot.is-locked { cursor: default; }
.triad-plot.is-locked .tri-edge { fill: rgba(27, 85, 96, 0.02); opacity: 0.55; }
.triad-plot.is-locked .tri-median,
.triad-plot.is-locked .tri-vertex { opacity: 0.08; }

.tri-hint {
  fill: var(--ink-faint);
  font-family: var(--sans);
  font-size: 13px;
  text-anchor: middle;
}

/* Geschlossene Triade: die Ecken treten zurück, damit der Blick
   auf die offene Frage weiter unten fällt. */
.triad.is-locked .corner { color: var(--ink-faint); }
.triad.is-locked .triad-sub { opacity: 0; }

.triad-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-top: 0.9rem; min-height: 2.2rem;
}

.triad-state {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-faint);
}
.triad.is-locked .triad-state { color: var(--amber); }

/* --- Zähler unten -------------------------------------------------------- */

.tally {
  position: fixed;
  left: 50%; bottom: 1.1rem; transform: translateX(-50%);
  z-index: 30;
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.55rem 0.7rem 0.55rem 1.1rem;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 2px;
  box-shadow: 0 2px 14px rgba(22, 35, 44, 0.07);
}
.tally[hidden] { display: none; }

.tally-pips { display: flex; gap: 0.45rem; }

.pip {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--line);
  transition: background-color 160ms ease;
}
.pip.is-set { background: var(--amber); }

.tally-text {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

@media (max-width: 560px) {
  .tally { left: var(--pad); right: var(--pad); transform: none; justify-content: space-between; }
  .tally-text { display: none; }
}

/* --- Formular ------------------------------------------------------------ */

.field { margin-bottom: 1.3rem; }

.field label {
  display: block;
  font-family: var(--sans);
  font-size: 0.85rem; color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.field input[type="text"],
.field input[type="email"] {
  width: 100%; max-width: 26rem;
  font-family: var(--serif); font-size: 1rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line); border-radius: 2px;
  padding: 0.75rem 0.9rem;
}

.field--check {
  display: grid; grid-template-columns: auto 1fr;
  gap: 0.7rem; align-items: start; max-width: 46rem;
  margin-bottom: 1.8rem;
}
.field--check label { margin: 0; line-height: 1.5; }
.field--check input { margin-top: 0.2rem; width: 1.05rem; height: 1.05rem; }

.field-error {
  font-family: var(--sans); font-size: 0.8rem;
  color: var(--amber); margin: 0.4rem 0 0;
}

/* --- Nachlauf ------------------------------------------------------------ */

.payload {
  margin-top: 2.5rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}
.payload summary {
  font-family: var(--sans); font-size: 0.85rem;
  color: var(--ink-soft); cursor: pointer;
}
.payload pre {
  font-size: 0.72rem; line-height: 1.5;
  background: var(--paper-deep); border-radius: 2px;
  padding: 0.9rem; max-height: 15rem; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}

/* --- Ohne JavaScript ----------------------------------------------------- */

.noscript {
  max-width: var(--measure); margin: 0 auto;
  padding: 7rem var(--pad) 4rem;
}

/* --- Bewegung ------------------------------------------------------------ */

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