/* Hearth v4 design tokens — canonical palette, type, spacing, motion.
 *
 * Status: Phase-1 of the v4 redesign. Currently scoped to the auth
 * surfaces (/auth/landing, /auth/signup form). The SPA shell
 * still uses the legacy app.css tokens. Phase 2 will migrate the
 * shell; phase 3 the components.
 *
 * Anti-FUD note: color is semantic before decorative. Green is
 * "handled / resting state," not just decoration. Amber is the
 * strongest routine tone — "glance," not "alarm." Alert (rust) is
 * spent almost never.
 */

:root {
  /* ---- Surfaces ---- */
  --v4-cream: #f3efe4;
  --v4-paper: #fbf9f3;
  --v4-paper-card: #fdfcf8;

  /* ---- Ink ---- */
  --v4-ink: #2b3950;
  --v4-ink-2: #46566b;
  --v4-ink-3: #7c8794;
  --v4-ink-4: #a7afb9;

  /* ---- Navy (dark surfaces, toast, hero badges) ---- */
  --v4-navy: #2b3950;
  --v4-navy-2: #222e41;
  --v4-navy-ink: #e9e4d6;
  --v4-navy-ink-2: #aeb6c2;

  /* ---- Cornflower blue: action, forward motion. Never fear. ---- */
  --v4-blue: #3461e6;
  --v4-blue-2: #5b82f0;
  --v4-blue-deep: #2747ad;
  --v4-blue-tint: #e6ecfb;

  /* ---- Lines ---- */
  --v4-line: rgba(43, 57, 80, 0.12);
  --v4-line-2: rgba(43, 57, 80, 0.20);

  /* ---- Semantic verdict tones ---- */
  --v4-ok: #5b9277;
  --v4-ok-tint: #e4efe9;
  --v4-warn: #bd9038;
  --v4-warn-tint: #f6efdc;
  --v4-alert: #bd6a52;
  --v4-alert-tint: #f2e0da;

  /* ---- Shadows ---- */
  --v4-shadow: 0 1px 2px rgba(43, 57, 80, 0.05),
               0 22px 44px -30px rgba(43, 57, 80, 0.40);
  --v4-shadow-sm: 0 1px 2px rgba(43, 57, 80, 0.06);

  /* ---- Type families ----
   * Loaded via Google Fonts <link> on each page that needs them.
   * Inter = the chrome (UI you operate) AND Hestia's narrative voice
   *   (moved off serif for readability, 2026-07-13; see --hestia-* in
   *   v4-shell.css).
   * Instrument Serif = display type only (wordmark, section headings,
   *   KPI numbers) via --v4-serif below.
   * JetBrains Mono = machine truth (data, IDs, IPs, timestamps).
   */
  --v4-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --v4-serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --v4-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* ---- Type sizes ----
   * A small NAMED scale, replacing the ad-hoc per-component px that had drifted
   * to ~14 near-identical sizes. Six roles, each a job: mono-caps section
   * eyebrows, mono tags/badges, small meta/notes, field labels, body/controls,
   * and serif display headings. New components size off these, not raw px.
   * (Introduced for the automation-builder cleanup; adopt app-wide over time.)
   */
  --v4-fs-eyebrow: 9.5px;  /* mono-caps section labels */
  --v4-fs-badge: 10px;     /* mono tags: tier / count / provider */
  --v4-fs-meta: 11px;      /* small meta, notes, descriptions */
  --v4-fs-label: 12.5px;   /* field labels, secondary body */
  --v4-fs-body: 14px;      /* body, controls, primary rows */
  --v4-fs-title: 22px;     /* serif section / modal heading */
  --v4-ls-caps: 0.12em;    /* one letter-spacing for all mono-caps eyebrows */

  /* ---- Radii ---- */
  --v4-r1: 6px;
  --v4-r2: 9px;
  --v4-r3: 13px;
  --v4-r4: 18px;

  /* ---- Motion ---- */
  --v4-ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* MR-0 criticals: define tokens referenced without a fallback elsewhere in
     the cascade. Aliases to existing tokens; retired by the post-beta CSS
     token consolidation. */
  --fg: var(--text);
  --surface: var(--panel);
  --text-muted: var(--muted);
}

/* ---- Body baseline for v4-scoped pages ---- */
.v4 {
  font-family: var(--v4-sans);
  background: var(--v4-cream);
  color: var(--v4-ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
  margin: 0;
  min-height: 100vh;
}

.v4 ::selection {
  background: rgba(52, 97, 230, 0.18);
}

.v4 a {
  color: inherit;
  text-decoration: none;
}

/* Subtle radial wash on the background — same gradient as the
   reference. Keep z-index negative so content sits on top. */
.v4 .v4-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 88% -8%, rgba(52, 97, 230, 0.07), transparent 60%),
    radial-gradient(700px 500px at -6% 108%, rgba(91, 146, 119, 0.06), transparent 55%);
  pointer-events: none;
}

/* ---- The orb — Hestia's presence ----
 * Cornflower sphere with interior highlight. Pulses while reading;
 * rests otherwise. Never wears a face.
 */
.v4 .orb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--v4-blue-2), var(--v4-blue-deep));
  position: relative;
  flex: 0 0 auto;
}

.v4 .orb.pulse::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid rgba(52, 97, 230, 0.4);
  animation: v4-orb-pulse 2.8s infinite;
}

@keyframes v4-orb-pulse {
  0%   { transform: scale(0.9); opacity: 0.7; }
  70%  { transform: scale(1.5); opacity: 0; }
  100% { opacity: 0; }
}

/* Larger orb variant for hero/brand treatment. */
.v4 .orb-lg {
  width: 36px;
  height: 36px;
}

.v4 .orb-xl {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--v4-blue-2), var(--v4-blue-deep));
  opacity: 0.12;
  filter: blur(8px);
}

/* ---- Wordmark + brand row ---- */
.v4 .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.v4 .brand svg,
.v4 .brand img {
  /* The auth pages render the brand mark as <img src=hedgehog.svg>
     for easy swap with the canonical source; older surfaces may
     still inline an SVG. Both get the same sizing here. */
  width: 44px;
  height: auto;
}
/* Theme-aware swap — both <img> tags ship in the markup, CSS hides
   the wrong one. Default: light visible, dark hidden. */
/* !important needed because the auth-page templates put inline
   ``style="display:..."`` on both <img> tags for FOUC protection.
   Inline styles beat unimportant CSS; the dark-mode rules below
   need !important to flip both variants once the theme attribute
   resolves dark. */
.v4 .brand-mark-light { display: block !important; }
.v4 .brand-mark-dark { display: none !important; }
html[data-theme="dark"] .v4 .brand-mark-light { display: none !important; }
html[data-theme="dark"] .v4 .brand-mark-dark { display: block !important; }
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .v4 .brand-mark-light { display: none !important; }
  html[data-theme="system"] .v4 .brand-mark-dark { display: block !important; }
}

.v4 .brand .wm {
  font-family: var(--v4-serif);
  font-size: 24px;
  color: var(--v4-ink);
  letter-spacing: -0.005em;
}

.v4 .tagline {
  font-family: var(--v4-mono);
  font-size: 9px;
  letter-spacing: 0.13em;
  color: var(--v4-ink-4);
  text-transform: uppercase;
}

/* ---- Eyebrow / section labels ---- */
.v4 .eyebrow {
  font-family: var(--v4-mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  color: var(--v4-blue-deep);
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* ---- Headings ---- */
.v4 h1 {
  font-family: var(--v4-serif);
  font-weight: 400;
  font-size: 52px;
  line-height: 1.02;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
  color: var(--v4-ink);
}

.v4 h2 {
  font-family: var(--v4-serif);
  font-weight: 400;
  font-size: 31px;
  line-height: 1.1;
  margin: 0 0 8px;
  color: var(--v4-ink);
}

.v4 h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--v4-ink);
}

.v4 h3::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--v4-blue);
  flex: 0 0 auto;
}

.v4 .sub {
  font-size: 14.5px;
  color: var(--v4-ink-2);
  max-width: 710px;
  margin: 0 0 24px;
}

.v4 .sub b {
  color: var(--v4-ink);
  font-weight: 600;
}

/* ---- Card ---- */
.v4 .card {
  border: 1px solid var(--v4-line);
  border-radius: var(--v4-r4);
  background: var(--v4-paper-card);
  box-shadow: var(--v4-shadow-sm);
  padding: 22px;
}

/* Hero-style card used by the auth surfaces. */
.v4 .hero-card {
  border: 1px solid var(--v4-line-2);
  border-radius: 22px;
  background: linear-gradient(165deg, var(--v4-paper-card), rgba(230, 236, 251, 0.4));
  box-shadow: var(--v4-shadow);
  padding: 42px 44px;
  position: relative;
  overflow: hidden;
}

.v4 .hero-card .orb-xl {
  position: absolute;
  right: -40px;
  top: -40px;
}

/* ---- Form fields ---- */
.v4 .field {
  margin-bottom: 14px;
}

.v4 .field label {
  display: block;
  font-family: var(--v4-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--v4-ink-3);
  margin-bottom: 6px;
}

.v4 .field input {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--v4-sans);
  font-size: 14px;
  color: var(--v4-ink);
  background: var(--v4-paper);
  border: 1px solid var(--v4-line-2);
  border-radius: var(--v4-r2);
  box-sizing: border-box;
  transition: border-color 140ms var(--v4-ease), box-shadow 140ms var(--v4-ease);
}

.v4 .field input:focus {
  outline: none;
  border-color: var(--v4-blue);
  box-shadow: 0 0 0 3px rgba(52, 97, 230, 0.12);
}

.v4 .field .hint {
  font-family: var(--v4-mono);
  font-size: 10px;
  color: var(--v4-ink-3);
  margin-top: 5px;
  line-height: 1.4;
}

/* ---- Buttons ---- */
.v4 .btn {
  display: inline-block;
  width: 100%;
  padding: 11px 18px;
  font-family: var(--v4-sans);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  border-radius: var(--v4-r2);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  transition: background 140ms var(--v4-ease), border-color 140ms var(--v4-ease);
}

.v4 .btn-primary {
  background: var(--v4-blue);
  color: #fff;
  border-color: var(--v4-blue);
}

.v4 .btn-primary:hover {
  background: var(--v4-blue-deep);
  border-color: var(--v4-blue-deep);
}

.v4 .btn-primary:disabled {
  opacity: 0.55;
  cursor: progress;
}

.v4 .btn-secondary {
  background: var(--v4-paper-card);
  color: var(--v4-blue-deep);
  border-color: var(--v4-blue);
}

.v4 .btn-secondary:hover {
  background: var(--v4-blue-tint);
}

.v4 .btn-ghost {
  background: transparent;
  color: var(--v4-ink-2);
  border-color: var(--v4-line-2);
}

.v4 .btn-ghost:hover {
  background: rgba(43, 57, 80, 0.04);
  border-color: var(--v4-line);
}

/* ---- Flash / toast (in-page) ---- */
.v4 .flash {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--v4-r2);
  font-size: 13px;
  line-height: 1.45;
}

.v4 .flash.success {
  background: var(--v4-ok-tint);
  border: 1px solid rgba(91, 146, 119, 0.35);
  color: var(--v4-ok);
}

.v4 .flash.error {
  background: var(--v4-alert-tint);
  border: 1px solid rgba(189, 106, 82, 0.35);
  color: var(--v4-alert);
}

.v4 .flash.warn {
  background: var(--v4-warn-tint);
  border: 1px solid rgba(189, 144, 56, 0.35);
  color: var(--v4-warn);
}

/* ---- Pill row (used for "no FUD / autonomy you supervise" etc.) ---- */
.v4 .pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.v4 .pill {
  font-family: var(--v4-mono);
  font-size: 10px;
  color: var(--v4-ink-2);
  border: 1px solid var(--v4-line-2);
  background: var(--v4-paper-card);
  padding: 6px 11px;
  border-radius: 999px;
}

/* ---- Auth surface layout ---- */
.v4 .auth-page {
  max-width: 920px;
  margin: 0 auto;
  padding: 56px 32px 80px;
}

.v4 .auth-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 22px;
  margin-top: 28px;
}

.v4 .auth-card {
  border: 1px solid var(--v4-line);
  border-radius: var(--v4-r4);
  background: var(--v4-paper-card);
  box-shadow: var(--v4-shadow-sm);
  padding: 26px 28px;
}

.v4 .auth-card h2 {
  font-size: 22px;
  margin-bottom: 6px;
}

.v4 .auth-card .desc {
  color: var(--v4-ink-2);
  font-size: 13px;
  margin: 0 0 22px;
  line-height: 1.5;
}

/* ---- "Drillable" underline — for the bear page and other places
 *    that surface a phrase the reader can click into for the
 *    underlying evidence. Always pair with a popover or link.       */
.v4 .drill {
  border-bottom: 1.5px dotted var(--v4-ink-4);
  cursor: help;
}

.v4 .drill:hover {
  border-color: var(--v4-blue);
  color: var(--v4-blue-deep);
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .v4 .orb.pulse::after { animation: none; }
  .v4 * { transition-duration: 0.01ms !important; }
}

/* ---- Mobile ---- */
@media (max-width: 720px) {
  .v4 h1 { font-size: 38px; }
  .v4 .hero-card { padding: 28px 24px; }
  .v4 .auth-page { padding: 32px 18px 60px; }
  .v4 .auth-cards { grid-template-columns: 1fr; }
}
