/* ==========================================================================
   HARMONIC — styles.css
   Palette, type, grid and component styling per DESIGN.md.
   All animation/transition rules live inside
   @media (prefers-reduced-motion: no-preference) so the default experience
   is fully static.
   ========================================================================== */

/* Global hidden-attribute guard: some author rules below match elements that
   also carry [hidden] at the same specificity as the UA stylesheet's
   [hidden]{display:none}; without !important here, cascade order (author
   after UA) lets those author rules win and the element stays visible. */
[hidden] { display: none !important; }

:root {
  --paper: #F5F3EC;
  --paper-dim: #ECE7D6;
  --ink: #131210;
  --green: #0F7A4D;
  --green-dark: #0B5C39;
  --rust: #D14B1F;
  --rust-text: #B93F19; /* darkened for AA text contrast on paper; --rust itself is for borders/fills at 3:1 */
  --indigo: #4E4AE8; /* reserved for basis-wave strokes only */
  --line: #CFC8B2;
  --line-strong: #A79E82;
  --muted: #5B564A;
  --on-accent: #F5F3EC; /* text color for the green CTA surface, AA-checked at 4.84:1 */

  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 48px;
  --space-6: 64px;
  --space-7: 96px;

  --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --pad-left: clamp(24px, 16.6vw, 320px);
  --pad-right: var(--space-4);
  --radius: 0;
}

/* HARMONIC uses one fixed warm-paper palette per DESIGN.md; no dark-mode
   variant is specified in the brief, so none is implemented here. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden; /* hard guard: no horizontal scroll at any width */
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 800; }
p { margin: 0; }
ul, dl { margin: 0; }
button { font: inherit; }

a { color: var(--ink); }
a:not(:hover) { text-decoration-color: var(--line-strong); }

.mono { font-family: var(--font-mono); }
.serif { font-family: var(--font-serif); }
.muted { color: var(--muted); }

.num {
  color: var(--rust-text);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  margin-right: var(--space-2);
  vertical-align: middle;
}

.small-cap {
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.6875rem;
  color: var(--muted);
}

/* Focus visibility — unconditional, not motion */
:focus-visible {
  outline: 3px solid var(--rust);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------------
   Shared section padding / grid-left-margin / bleed
   ------------------------------------------------------------------------ */

.ticker, .hero, section.section, footer.footer {
  padding-left: var(--pad-left);
  padding-right: var(--pad-right);
}

.bleed {
  margin-right: calc(-1 * var(--pad-right));
}

section.section {
  border-top: 1px solid var(--line);
  padding-top: var(--space-6);
  padding-bottom: var(--space-6);
}

/* ------------------------------------------------------------------------
   Banners (engine/examples-missing, csv/model errors)
   ------------------------------------------------------------------------ */

.banner, .error {
  border: 0;
  border-left: 4px solid var(--rust);
  background: color-mix(in srgb, var(--rust) 8%, var(--paper));
  padding: var(--space-2) var(--space-3);
  margin: var(--space-2) 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
}

.banner {
  margin: 0;
  border-radius: var(--radius);
}

/* ------------------------------------------------------------------------
   Ticker
   ------------------------------------------------------------------------ */

.ticker {
  background: var(--ink);
  color: var(--paper);
  padding-top: 10px;
  padding-bottom: 10px;
  overflow: hidden;
  white-space: nowrap;
}

.ticker-track {
  display: inline-flex;
  gap: 3em;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ticker-track span { display: inline-flex; gap: 3em; }

@media (prefers-reduced-motion: no-preference) {
  .ticker-track {
    animation: ticker-scroll 26s linear infinite;
  }
  @keyframes ticker-scroll {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
  }
}

/* ------------------------------------------------------------------------
   Hero
   ------------------------------------------------------------------------ */

.hero {
  display: grid;
  grid-template-columns: minmax(280px, 620px) 1fr;
  gap: var(--space-5);
  align-items: end;
  padding-top: var(--space-6);
  padding-bottom: var(--space-6);
}

.hero-text h1 {
  font-size: clamp(2.75rem, 8.5vw, 7rem);
  line-height: 0.92;
  letter-spacing: -0.02em;
  margin: var(--space-2) 0;
}

.hero-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.6875rem;
  color: var(--muted);
}

.hero-claim {
  font-size: clamp(1.125rem, 2.1vw, 1.5rem);
  line-height: 1.4;
  font-style: italic;
  max-width: 34ch;
  margin-top: var(--space-2);
}

.hero-privacy {
  margin-top: var(--space-3);
  font-size: 0.8125rem;
  color: var(--green-dark);
  letter-spacing: 0.02em;
}

.hero-instrument {
  min-width: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hero-instrument svg {
  width: 100%;
  height: auto;
  display: block;
}

.hero-instrument .placeholder {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  border: 1px dashed var(--line);
  padding: var(--space-4);
}

/* ------------------------------------------------------------------------
   Section leads
   ------------------------------------------------------------------------ */

section.section h2 {
  font-size: clamp(1.5rem, 3.4vw, 2.375rem);
  display: flex;
  align-items: baseline;
  margin-bottom: var(--space-3);
}

.lead {
  font-size: clamp(1.0625rem, 1.6vw, 1.25rem);
  max-width: 62ch;
  line-height: 1.55;
  margin-bottom: var(--space-4);
  font-style: italic;
}

/* ------------------------------------------------------------------------
   01 DATA
   ------------------------------------------------------------------------ */

.dropzone {
  border: 2px dashed var(--line-strong);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  cursor: pointer;
  max-width: 720px;
}

.dropzone p { margin-bottom: var(--space-2); }
.dropzone p:last-of-type { margin-bottom: 0; }

.dropzone:hover, .dropzone:focus-visible {
  border-color: var(--rust);
}

.example-cards {
  list-style: none;
  padding: 0;
  margin-top: var(--space-3);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-3);
  max-width: 980px;
}

.example-card {
  border: 1px solid var(--line);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.example-card:hover { border-color: var(--ink); }
.example-card.is-active { border-color: var(--green); border-width: 2px; padding: calc(var(--space-3) - 1px); }

.example-card h4 { font-size: 1rem; }
.example-card p { font-size: 0.875rem; color: var(--muted); }
.example-card .meta { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); }

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

.btn {
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  font-size: 0.9375rem;
  padding: 13px 26px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-block;
}

.btn-primary {
  background: var(--green);
  border-color: var(--ink);
  color: var(--on-accent);
}

.btn-secondary { background: transparent; }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn:not(:disabled):hover.btn-primary { background: var(--green-dark); }
.btn:not(:disabled):hover.btn-secondary { background: var(--ink); color: var(--paper); }

@media (prefers-reduced-motion: no-preference) {
  .btn { transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease; }
  .example-card { transition: border-color 120ms ease; }
}

/* ------------------------------------------------------------------------
   02 MODEL
   ------------------------------------------------------------------------ */

.picker-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  max-width: 900px;
}

.picker { border: 0; padding: 0; margin: 0; }
.picker legend { padding: 0 0 var(--space-1) 0; }

.bordered-list {
  list-style: none;
  border: 1px solid var(--line);
  max-height: 260px;
  overflow-y: auto;
}

.bordered-list li { border-bottom: 1px solid var(--line); }
.bordered-list li:last-child { border-bottom: none; }

.bordered-list label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.bordered-list label:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }

.bordered-list input[type="radio"],
.bordered-list input[type="checkbox"] {
  accent-color: var(--green);
  width: 15px;
  height: 15px;
  flex: none;
}

.fit-row {
  margin-top: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.fit-readout { font-size: 0.8125rem; color: var(--muted); min-height: 1.2em; }

/* ------------------------------------------------------------------------
   03 CURVES / 04 FIT — SVG plot chrome
   ------------------------------------------------------------------------ */

.curves-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: var(--space-5) var(--space-4);
}

.curve-panel { min-width: 0; }

.curve-panel h3 {
  font-size: 0.9375rem;
  font-weight: 800;
  margin-bottom: var(--space-1);
}

.curve-panel .panel-meta {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--muted);
  margin-bottom: var(--space-2);
}

.plot-svg { width: 100%; height: auto; display: block; }
.plot-svg text { font-family: var(--font-mono); }
.hover-readout { font-family: var(--font-mono); font-size: 0.75rem; fill: var(--ink); }

@media (prefers-reduced-motion: no-preference) {
  .curve-anim { animation: fade-up 520ms ease-out both; }
  @keyframes fade-up {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--space-3);
  max-width: 980px;
  margin-bottom: var(--space-5);
}

.stats-grid > div {
  border-top: 2px solid var(--ink);
  padding-top: var(--space-1);
}

.stats-grid dt {
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.6875rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

.stats-grid dd {
  margin: 4px 0 0 0;
  font-family: var(--font-mono);
  font-size: 1.375rem;
  font-weight: 700;
}

.residual-block { max-width: 760px; }

/* ------------------------------------------------------------------------
   05 METHOD
   ------------------------------------------------------------------------ */

.method-body { max-width: 68ch; }
.method-body p { margin-bottom: var(--space-3); }
.method-body h3 { font-size: 1rem; margin: var(--space-4) 0 var(--space-2); }
.caveat {
  border-left: 3px solid var(--rust);
  padding-left: var(--space-2);
}

/* ------------------------------------------------------------------------
   06 EXPORT
   ------------------------------------------------------------------------ */

#export-hint { margin-top: var(--space-2); font-size: 0.8125rem; }

/* ------------------------------------------------------------------------
   Footer
   ------------------------------------------------------------------------ */

.footer {
  border-top: 1px solid var(--line);
  padding-top: var(--space-5);
  padding-bottom: var(--space-6);
  font-size: 0.8125rem;
  color: var(--muted);
}

.footer .footer-title {
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.6875rem;
  color: var(--muted);
  margin-bottom: var(--space-2);
}

.footer ul { list-style: none; padding: 0; margin: var(--space-1) 0 var(--space-4); }
.footer li { margin-bottom: 4px; }

/* ------------------------------------------------------------------------
   Drag-over overlay (whole-page CSV drop)
   ------------------------------------------------------------------------ */

.dragover-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 92%, transparent);
  color: var(--paper);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.5rem, 5vw, 3rem);
  font-weight: 800;
  z-index: 9999;
  pointer-events: none;
  border: 8px dashed var(--rust);
  box-sizing: border-box;
}

.dragover-overlay.is-active {
  display: flex;
}

/* ------------------------------------------------------------------------
   Mobile — single column, 375px baseline
   ------------------------------------------------------------------------ */

@media (max-width: 640px) {
  :root {
    --pad-left: var(--space-3);
    --pad-right: var(--space-3);
  }

  .hero {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .bleed { margin-right: 0; }

  .picker-row { grid-template-columns: 1fr; }

  .curves-grid { grid-template-columns: 1fr; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
