/* Konstellar browser app — same system as the website (ADR 0021 rev. 2) and
   the iOS app (ADR 0022). Loads after /shared.css, which supplies the
   Newsreader + Commissioner @font-face rules.

   - Colour: mineral white canvas, near-black ink, one deep wine accent; cool
     mist only for selected/hover; clean white only for fields and controls.
     Dark mode follows prefers-color-scheme with the ADR 0022 dark values.
   - Type: Newsreader for headlines, key statements, result titles and
     reflection questions; Commissioner for everything else. Reading text
     never below 16px.
   - Form: no cards, no pills, no shadows. Space and 1px rules separate
     sections; 8px radius on controls only.
   - Threads: only on the Muster sources ("Woher das kommt"). Filled node =
     computed, open node + dotted line = needs more data. Drawn once; off
     under prefers-reduced-motion. */

:root {
  color-scheme: light dark;
  --canvas: #F7F7F5;
  --surface: #FFFFFF;
  --ink: #1B191A;
  --ink-2: #555354;        /* 7.1:1 on canvas */
  --wine: #8C1D40;         /* 8.3:1 on canvas */
  --wine-deep: #6E1532;    /* pressed/hover */
  --wine-fill: #8C1D40;    /* accent as a large fill (buttons) */
  --wine-fill-deep: #6E1532;
  --on-wine: #FFFFFF;      /* 8.9:1 on the fill */
  --mist: #DCE3E6;         /* selected/hover only */
  --rule: #C9C8C5;
  --control: #858585;      /* field borders, 3.4:1 (WCAG 1.4.11) */
  /* Chart-only functional coding (aspect valence). */
  --aspect-hard: #A23B36;
  --aspect-harm: #3F5F7A;

  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Commissioner", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #121213;
    --surface: #1D1C1D;
    --ink: #EDEDEB;        /* 15.97:1 */
    --ink-2: #ADABAC;      /* 8.2:1 */
    --wine: #E27A96;       /* 6.65:1 */
    --wine-deep: #EC9AB0;
    /* A button filled with the light text wine reads as pink: fills use a
       deeper wine with white text (7.2:1). ADR 0022. */
    --wine-fill: #A3244F;
    --wine-fill-deep: #8C1D40;
    --on-wine: #FFFFFF;
    --mist: #283034;
    --rule: #3A393A;
    --control: #808080;    /* 4.74:1 */
    --aspect-hard: #E08A80;
    --aspect-harm: #8FB0CC;
  }
}

.app-body {
  background: var(--canvas);
  color: var(--ink);
  font: 400 1.125rem/1.6 var(--sans);
  overflow-x: clip;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app-body a { color: var(--wine); }
.app-body a:hover { color: var(--wine-deep); }
.app-body :focus-visible { outline: 2px solid var(--wine); outline-offset: 3px; border-radius: 2px; }
.app-body ::selection { background: var(--mist); }

.app-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 120px;
}

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

.app-noscript { color: var(--ink-2); text-align: center; padding: 48px 0; }

/* ---------- header ---------- */

.app-header {
  position: sticky; top: 0; z-index: 11;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  /* Canvas fill and the bottom rule run edge to edge; border-image outset
     paints outside the column without widening the scroll area. */
  border-bottom: 1px solid var(--rule);
  border-image: linear-gradient(to bottom, var(--canvas) calc(100% - 1px), var(--rule) calc(100% - 1px)) fill 0 / 0 / 0 100vmax;
}

.app-header h1 {
  margin: 0;
  font: 500 1.75rem/1 var(--serif);
  letter-spacing: -0.02em;
  color: var(--ink);
}

.app-date { color: var(--ink-2); font-size: 1rem; font-weight: 500; }

/* ---------- tabs ---------- */

.app-tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px max(16px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom));
  background: var(--canvas);
  border-top: 1px solid var(--rule);
  z-index: 10;
}

.app-tab {
  flex: 0 1 140px;
  min-height: 48px;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--ink-2);
  font: 500 1rem/1.2 var(--sans);
  padding: 8px 12px;
  text-align: center;
  cursor: pointer;
}

.app-tab:hover { color: var(--ink); }
.app-tab[aria-selected="true"] { color: var(--wine); background: var(--mist); }

/* ---------- sections (formerly cards) ---------- */

.k-card {
  padding: 24px 0;
  border-top: 1px solid var(--rule);
}

.app-header + .k-card,
.app-header + div > .k-card:first-child { border-top: 0; }

.k-card h2 {
  margin: 0 0 10px;
  font: 500 1.75rem/1.15 var(--serif);
  letter-spacing: -0.015em;
  color: var(--ink);
}

.k-card h3 {
  margin: 0 0 8px;
  font: 600 1rem/1.4 var(--sans);
  color: var(--ink-2);
}

.k-headline {
  margin: 24px 0 14px;
  font: 500 clamp(2.25rem, 5vw, 3rem)/1.06 var(--serif);
  letter-spacing: -0.02em;
}

.k-summary { margin: 0 0 12px; font-size: 1.1875rem; }

.k-muted { color: var(--ink-2); }

.k-eyebrow {
  margin: 0 0 8px;
  color: var(--wine);
  font: 500 1rem/1.4 var(--sans);
}

.k-eyebrow-muted { color: var(--ink-2); }

.k-chips { margin: 4px 0 8px; color: var(--ink-2); font-size: 1rem; line-height: 1.5; }
.k-chips::before { content: "Beruht auf: "; }
.k-chip + .k-chip::before { content: " · "; }

.k-badge {
  margin-left: 8px;
  font-weight: 500;
  font-size: 1rem;
}

.k-badge.harmonious { color: var(--ink); }
.k-badge.challenging { color: var(--wine); }
.k-badge.intense { color: var(--wine); }

.k-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.k-list { list-style: none; margin: 0; padding: 0; }
.k-list li { padding: 4px 0; }

/* ---------- forms (onboarding) ---------- */

/* Onboarding: big serif question, then the form as one white block. */
.k-onboard { padding-top: clamp(32px, 6vw, 72px); }
.k-onboard h2 {
  margin: 0 0 16px;
  font: 500 clamp(2.5rem, 7vw, 3.75rem)/1.02 var(--serif);
  letter-spacing: -0.025em;
  max-width: 14ch;
}
.k-lede { margin: 0; max-width: 40ch; font-size: 1.1875rem; line-height: 1.55; color: var(--ink); }

.k-form {
  margin-top: 36px;
  padding: 8px 32px 32px;
  background: var(--surface);
  border: 1px solid var(--rule);
}
@media (min-width: 560px) {
  /* Birthday and birth time side by side. */
  .k-form { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; }
  .k-form > * { grid-column: 1 / -1; }
  .k-form > .k-field:nth-of-type(2) { grid-column: 1; }
  .k-form > .k-field:nth-of-type(3) { grid-column: 2; }
}
@media (max-width: 559px) {
  .k-form { padding: 4px 20px 24px; margin-inline: -4px; }
}

.k-field { margin: 24px 0 0; min-width: 0; }
.k-field label { display: block; font-weight: 600; font-size: 1rem; color: var(--ink); margin-bottom: 8px; }

.k-field input[type="text"],
.k-field input[type="date"],
.k-field input[type="time"] {
  display: block;
  width: 100%;
  min-height: 56px;
  background: var(--surface);
  border: 1.5px solid var(--control);
  border-radius: var(--radius);
  color: var(--ink);
  font: 500 1.1875rem/1.3 var(--sans);
  font-variant-numeric: lining-nums tabular-nums;
  padding: 12px 16px;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s ease;
}
.k-field input::-webkit-calendar-picker-indicator { opacity: .6; cursor: pointer; }
.k-field input::-webkit-calendar-picker-indicator:hover { opacity: 1; }
.k-field input::-webkit-datetime-edit { padding: 0; }

.k-field input::placeholder { color: var(--ink-2); }
.k-field input:hover { border-color: var(--ink-2); }
.k-field input:focus { outline: none; border-color: var(--wine); box-shadow: inset 0 0 0 1px var(--wine); }
.k-field input:disabled { background: var(--canvas); border-color: var(--rule); color: var(--ink-2); }

.k-check { display: flex; align-items: center; gap: 12px; min-height: 44px; margin-top: 8px; font-weight: 400; color: var(--ink-2); font-size: 1rem; cursor: pointer; }
.k-field label.k-check { display: flex; font-weight: 400; color: var(--ink); margin-bottom: 0; }

/* Custom checkbox: native input kept for keyboard and screen readers. */
.k-check input, .k-consent input {
  -webkit-appearance: none; appearance: none;
  flex: 0 0 auto; width: 24px; height: 24px; margin: 0;
  background: var(--surface) center / 16px 16px no-repeat;
  border: 1.5px solid var(--control); border-radius: 6px;
  cursor: pointer;
}
.k-check input:hover, .k-consent input:hover { border-color: var(--ink-2); }
.k-check input:checked, .k-consent input:checked {
  background-color: var(--wine-fill); border-color: var(--wine-fill);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.k-check input:focus-visible, .k-consent input:focus-visible { outline: 2px solid var(--wine); outline-offset: 2px; }

.k-consent {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin: 28px 0 0;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  cursor: pointer;
}

.k-btn {
  display: block;
  width: 100%;
  min-height: 60px;
  background: var(--wine-fill);
  color: var(--on-wine);
  border: 1.5px solid var(--wine-fill);
  border-radius: var(--radius);
  font: 600 1.1875rem/1.2 var(--sans);
  padding: 0 24px;
  margin-top: 24px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}

.k-btn:hover { background: var(--wine-fill-deep); border-color: var(--wine-fill-deep); }
/* Disabled: rule fill and secondary text, never a faded wine (reads as blush). */
.k-btn:disabled, .k-btn:disabled:hover { background: var(--rule); border-color: var(--rule); color: var(--ink-2); cursor: default; }

.k-btn-ghost { background: transparent; color: var(--ink); border-color: var(--ink); }
.k-btn-ghost:hover { background: var(--mist); color: var(--wine-deep); border-color: var(--wine); }

.k-citylist {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  background: var(--surface);
  border: 1.5px solid var(--control);
  border-radius: var(--radius);
  overflow: hidden;
}
.k-citylist li { min-height: 48px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--rule); }
.k-citylist li:last-child { border-bottom: none; }
.k-citylist li:hover, .k-citylist li[aria-selected="true"] { background: var(--mist); }
.k-citylist .country { color: var(--ink-2); margin-left: 8px; }

/* ---------- radix ---------- */

.k-wheel { display: block; margin: 0 auto; max-width: 100%; height: auto; font-family: var(--sans); }

.k-table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.k-table td { padding: 8px 4px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.k-table td:first-child { color: var(--ink-2); }
.k-table tr:last-child td { border-bottom: none; }
.k-glyph { margin-right: 8px; color: var(--ink); }

/* ---------- Muster ---------- */

.pattern-hero { padding: clamp(32px, 6vw, 64px) 0 8px; }

.pattern-headline {
  margin: 0 0 18px;
  color: var(--ink);
  font: 500 clamp(2.125rem, 7vw, 3.75rem)/1.04 var(--serif);
  letter-spacing: -0.025em;
  hyphens: auto;
  overflow-wrap: break-word;
}

.pattern-summary {
  margin: 0;
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1.5;
}

/* "Woher das kommt": each statement hangs off the source it was computed
   from. The thread runs down the left edge, like the website at 390px. */
.pattern-chain-wrap { position: relative; margin-top: 36px; }
.pattern-who { position: relative; z-index: 1; display: flex; align-items: center; gap: 16px; margin: 0; font-size: 1rem; line-height: 1.5; color: var(--ink-2); }
.pattern-who strong { color: var(--ink); font-weight: 600; }

.chain { position: relative; z-index: 1; list-style: none; margin: 32px 0 0; padding: 0; }
.link { display: grid; grid-template-columns: minmax(0, 1fr); row-gap: 14px; align-items: start; padding-bottom: 44px; }
.link:last-child { padding-bottom: 12px; }
.src { display: flex; align-items: center; gap: 18px; margin: 0; font-weight: 500; font-size: 1rem; line-height: 1.5; color: var(--ink-2); min-height: 24px; }
.out { position: relative; padding-left: 28px; }
.out > .node { position: absolute; left: 0; top: 7px; transition: opacity .6s ease 1.3s; }
.chain.is-arriving .out > .node { opacity: 0; transition: none; }
.out .label { margin: 0; font-weight: 500; font-size: 1rem; line-height: 1.5; color: var(--wine); }
.out .title { margin: 4px 0 0; font: 500 clamp(1.875rem, 4vw, 2.375rem)/1.08 var(--serif); letter-spacing: -0.015em; color: var(--ink); }
.out .body { margin: 12px 0 0; font-size: 1.125rem; line-height: 1.6; }
.out .prompt { margin: 16px 0 0; font: italic 400 1.3125rem/1.35 var(--serif); color: var(--ink); }
.link.is-open .node { background: var(--canvas); }
.link.is-open .label { color: var(--ink-2); }
.link.is-open .body { margin-top: 4px; color: var(--ink-2); }

.node {
  position: relative; z-index: 1; flex: none;
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--wine); border: 1.5px solid var(--wine);
}
.node-open { background: var(--canvas); }
.links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 0; }
.links path { fill: none; stroke: var(--wine); stroke-width: 1.5; stroke-linecap: round; opacity: .85; }
.links path.is-dotted { stroke-width: 2; stroke-dasharray: 0 7; opacity: .7; }
.links path.is-drawing { transition: stroke-dashoffset 1.6s cubic-bezier(.45,.05,.25,1), opacity 1.2s ease; }

.pattern-section { margin-top: 40px; padding-top: 32px; border-top: 2px solid var(--ink); }

.pattern-card h3 {
  margin: 4px 0 14px;
  color: var(--ink);
  font: 500 clamp(1.75rem, 4vw, 2.25rem)/1.1 var(--serif);
  letter-spacing: -0.01em;
}

.pattern-card > p:not(.k-eyebrow, .pattern-question, .pattern-source-line) { margin: 0; font-size: 1.125rem; line-height: 1.6; }

.pattern-card .pattern-question { margin: 16px 0 0; font: italic 400 1.3125rem/1.35 var(--serif); color: var(--ink); }

.pattern-source-line { margin: 14px 0 0; color: var(--ink-2); font-size: 1rem; }

/* The one question to carry into the week, on a white block. */
.pattern-prompt { margin: 36px 0 32px; padding: 28px 32px 32px; background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--wine); }
.pattern-prompt blockquote {
  margin: 8px 0 0;
  color: var(--ink);
  font: italic 400 clamp(1.5rem, 3.4vw, 1.875rem)/1.3 var(--serif);
}
@media (max-width: 559px) { .pattern-prompt { padding: 22px 20px 24px; } }

.pattern-deeper {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 22px 0;
  background: none;
  border: 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.pattern-deeper:hover strong { color: var(--wine); }
.pattern-deeper strong { display: block; font: 500 1.5rem/1.3 var(--serif); }
.pattern-deeper small { display: block; margin-top: 4px; color: var(--ink-2); font-size: 1rem; line-height: 1.5; }
.pattern-deeper em { margin-left: 6px; color: var(--wine); font: 500 1rem/1 var(--sans); font-style: normal; }
.pattern-deeper > span:last-child {
  display: grid; place-items: center; width: 44px; height: 44px;
  border: 1.5px solid var(--control); border-radius: 50%;
  color: var(--ink); font-size: 1.375rem; line-height: 1;
}
.pattern-deeper:hover > span:last-child { border-color: var(--wine); color: var(--wine); }

.pattern-chart-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  margin: 8px 0 0;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--wine);
  font: 500 1.0625rem/1.3 var(--sans);
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  cursor: pointer;
}

.pattern-chart-link:hover { color: var(--wine-deep); }

.pattern-disclaimer {
  margin: 20px 0 0;
  color: var(--ink-2);
  font-size: 1rem;
  line-height: 1.5;
}

/* ---------- misc ---------- */

.k-install { font-size: 1rem; color: var(--ink-2); }
.k-install strong { color: var(--ink); font-weight: 600; }

.k-footer { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--rule); color: var(--ink-2); font-size: 1rem; line-height: 1.6; }
.k-footer a { color: var(--ink); }
.k-footer a:hover { color: var(--wine); }

.k-tone-row { display: flex; justify-content: flex-end; margin-top: 16px; }
.k-tone { display: inline-flex; border: 1.5px solid var(--control); border-radius: var(--radius); overflow: hidden; }
.k-tone button {
  min-height: 40px;
  background: var(--surface); border: none; color: var(--ink-2);
  font: 500 1rem/1 var(--sans); padding: 0 16px; cursor: pointer;
}
.k-tone button + button { border-left: 1px solid var(--rule); }
.k-tone button[aria-pressed="true"] { background: var(--mist); color: var(--wine); }

.k-day-entry { margin: 10px 0 0; }
.k-day-entry strong { font-weight: 600; }
.k-day-entry .k-badge { margin: 0 8px 0 0; }

/* Desktop: the tabs move up into the header bar, like the website nav. */
@media (min-width: 900px) {
  .app-shell { padding-bottom: 64px; }
  .app-header { min-height: 76px; }
  .app-tabs {
    top: 0; bottom: auto; left: 50%; right: auto; transform: translateX(-50%);
    height: 76px; align-items: center; padding: 0;
    background: transparent; border-top: 0; z-index: 12;
  }
  .app-tab { flex: 0 0 auto; padding: 8px 20px; font-size: 1.0625rem; }
}

@media (prefers-reduced-motion: reduce) {
  .out > .node, .links path.is-drawing { transition: none; }
}
