/* =============================================================================
 * Design system — derived from unicorn.pro
 * =============================================================================
 * Brand cyan = sole accent. Everything else is neutral grayscale.
 * Inter (Google Fonts) ≈ Inter Display.
 * Heading scale is display-heavy with tight negative letter-spacing.
 * Components: pill buttons, soft-gray cards, generous whitespace.
 * ========================================================================== */

:root {
  /* ─── Color tokens ─── */
  --color-brand: #1ab8e4;
  --color-brand-hover: #15a3cc;
  --color-brand-press: #117f9f;

  --color-ink: #1e1e1e; /* primary heading + body */
  --color-ink-soft: #444444; /* secondary body */
  --color-ink-muted: rgba(9, 9, 9, 0.4); /* labels, captions */

  --color-surface: #ffffff;
  --color-surface-alt: #f5f4f3; /* warm off-white card */
  --color-surface-neutral: #eaeaea; /* pill bg */
  --color-divider: #e3e1de;

  --color-error: #c0392b;
  --color-error-bg: #fdecea;

  --color-code-bg: #0f1115; /* dark code surface for transcript / json */
  --color-code-ink: #e6e8ec;

  /* ─── Typography tokens ─── */
  --font-display:
    'Inter', 'Inter Display', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --font-size-body: 15px;
  --font-size-small: 13px;
  --font-size-label: 12px;

  --font-size-h1: clamp(56px, 8vw, 96px);
  --font-size-h2: clamp(36px, 5vw, 56px);
  --font-size-h3: clamp(20px, 2.5vw, 24px);

  --leading-display: 0.95;
  --leading-body: 1.55;
  --tracking-display: -0.04em;
  --tracking-h2: -0.035em;
  --tracking-h3: -0.02em;

  /* ─── Spacing scale ─── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --space-9: 96px;

  /* ─── Radius & shadow ─── */
  --radius-card: 24px;
  --radius-pill: 999px;
  --radius-input: 12px;

  --shadow-sm: 0 1px 2px rgba(9, 9, 9, 0.04);
  --shadow-card: 0 1px 0 var(--color-divider);
  --shadow-pill-inset: inset 0 0 4px rgba(0, 0, 0, 0.05);
  --shadow-focus: 0 0 0 3px rgba(26, 184, 228, 0.25);

  /* ─── Layout ─── */
  --container-max: 1200px;
  --container-pad-x: clamp(20px, 4vw, 40px);
}

/* ─── Reset / base ────────────────────────────────────────────────────────── */

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

html,
body {
  margin: 0;
  padding: 0;
}

html {
  background: var(--color-surface);
  color: var(--color-ink);
  font-family: var(--font-display);
  font-size: var(--font-size-body);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(
      ellipse 80% 60% at 50% -10%,
      rgba(26, 184, 228, 0.06) 0%,
      transparent 60%
    ),
    var(--color-surface);
}

/* ─── Layout container ────────────────────────────────────────────────────── */

.page {
  /* why: flex column + min-height 100vh + margin-top:auto on the footer
     gives a sticky-footer that pins to the viewport bottom on short pages
     and flows naturally below content on long pages. */
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-7) var(--container-pad-x);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Brand / header ──────────────────────────────────────────────────────── */

.brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  font-size: var(--font-size-label);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-ink-muted);
}

.brand::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--color-brand);
  border-radius: 50%;
  align-self: center;
}

/* ─── Display heading ─────────────────────────────────────────────────────── */

.hero {
  margin-bottom: var(--space-7);
}

.hero h1 {
  margin: 0 0 var(--space-3) 0;
  font-family: var(--font-display);
  font-size: var(--font-size-h1);
  font-weight: 600;
  line-height: var(--leading-display);
  letter-spacing: var(--tracking-display);
  color: var(--color-ink);
}

.hero h1 .accent {
  color: var(--color-brand);
}

.hero p {
  margin: 0;
  max-width: 60ch;
  color: var(--color-ink-soft);
  font-size: var(--font-size-body);
  line-height: var(--leading-body);
}

/* ─── Footer breathing room ──────────────────────────────────────────────────
   On tall pages flex's margin-top:auto collapses to 0, so the footer border
   would touch the last card. This guarantees a minimum gap above the footer
   regardless of content height. The selector targets whichever element is the
   sibling immediately before the footer (form card on idle, result card on
   success). */
.page > *:nth-last-child(2) {
  margin-bottom: var(--space-7);
}

/* ─── Card surface (form + results) ───────────────────────────────────────── */

.card {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-card);
  padding: var(--space-7);
}

.card + .card {
  margin-top: var(--space-5);
}

/* ─── Form ────────────────────────────────────────────────────────────────── */

form.analyze-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-3);
  align-items: end;
}

.analyze-form .field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.analyze-form label {
  font-size: var(--font-size-label);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-ink-muted);
}

.analyze-form input[type='url'] {
  font: inherit;
  font-size: var(--font-size-body);
  padding: 14px 18px;
  background: var(--color-surface);
  color: var(--color-ink);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-input);
  width: 100%;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease;
}

.analyze-form input[type='url']::placeholder {
  color: var(--color-ink-muted);
}

.analyze-form input[type='url']:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: var(--shadow-focus);
}

.analyze-form input[type='url']:disabled {
  background: var(--color-surface-neutral);
  cursor: not-allowed;
  opacity: 0.7;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  font: inherit;
  font-weight: 500;
  font-size: var(--font-size-body);
  padding: 14px 28px;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition:
    background 120ms ease,
    transform 60ms ease,
    box-shadow 120ms ease;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

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

.btn-primary {
  background: var(--color-brand);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-brand-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-brand-press);
  transform: translateY(1px);
}

/* ─── Status region — persistent aria-live wrapper ───────────────────────── */
/* why: empty block takes no visible space; min-height:0 prevents a layout gap
   when no status message is rendered. The wrapper must remain in the DOM
   (not conditionally mounted) so the browser registers it as a live region
   before the first announcement fires. */
.status-region:empty {
  display: none;
}

/* ─── Status row (loading / error) ────────────────────────────────────────── */

.status {
  min-height: 1.5em;
  margin-top: var(--space-4);
  font-size: var(--font-size-small);
  color: var(--color-ink-muted);
}

.status.is-loading {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.status.is-loading::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-brand);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.4);
  }
}

.status.is-error {
  color: var(--color-error);
  background: var(--color-error-bg);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-input);
  font-weight: 500;
}

/* ─── Section heading inside results card ─────────────────────────────────── */

.section-heading {
  margin: 0 0 var(--space-4) 0;
  font-size: var(--font-size-h3);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: var(--tracking-h3);
  color: var(--color-ink);
}

/* why: the original adjacent-sibling selector (.section-heading + .section-heading-wrap)
   never matched — .section-heading is a child of a wrapper div, not a sibling of
   .section-heading-wrap. Apply margin-top directly on the wrapper instead. */
.section-heading-wrap {
  margin-top: var(--space-6);
}

/* ─── Person table ────────────────────────────────────────────────────────── */

.person-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-body);
}

.person-table th,
.person-table td {
  text-align: left;
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  vertical-align: top;
}

.person-table tr:last-child th,
.person-table tr:last-child td {
  border-bottom: none;
}

.person-table th {
  width: 35%;
  font-weight: 500;
  font-size: var(--font-size-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-ink-muted);
  white-space: nowrap;
}

.person-table td {
  color: var(--color-ink);
}

.person-table td.is-null {
  color: var(--color-ink-muted);
  font-style: italic;
}

/* ─── Transcript / code blocks ────────────────────────────────────────────── */

.transcript,
.raw-json {
  font-family: var(--font-mono);
  font-size: var(--font-size-small);
  line-height: 1.6;
  background: var(--color-code-bg);
  color: var(--color-code-ink);
  padding: var(--space-5);
  border-radius: var(--radius-input);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.transcript.is-empty {
  background: transparent;
  color: var(--color-ink-muted);
  font-family: var(--font-display);
  font-style: italic;
  padding: var(--space-3) 0;
}

/* ─── Empty person state ──────────────────────────────────────────────────── */

.empty-person {
  margin: 0;
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px dashed var(--color-divider);
  border-radius: var(--radius-input);
  color: var(--color-ink-muted);
  font-style: italic;
  text-align: center;
}

/* ─── Raw JSON details ────────────────────────────────────────────────────── */

details.raw-details {
  margin-top: var(--space-5);
}

details.raw-details summary {
  cursor: pointer;
  list-style: none;
  font-size: var(--font-size-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  color: var(--color-ink-muted);
  padding: var(--space-2) 0;
  user-select: none;
}

details.raw-details summary::marker,
details.raw-details summary::-webkit-details-marker {
  display: none;
}

details.raw-details summary::before {
  content: '+ ';
  font-weight: 600;
  color: var(--color-brand);
}

details.raw-details[open] summary::before {
  content: '− ';
}

details.raw-details .raw-json {
  margin-top: var(--space-2);
}

/* ─── Footer ──────────────────────────────────────────────────────────────── */

.footnote {
  /* why: margin-top:auto eats the remaining flex space in .page, pinning the
     footer to the viewport bottom when content is short. padding-top keeps the
     visual gap above the border on tall pages where auto resolves to 0. */
  margin-top: auto;
  padding-top: var(--space-7);
  border-top: 1px solid var(--color-divider);
  font-size: var(--font-size-label);
  color: var(--color-ink-muted);
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .card {
    padding: var(--space-5);
  }
  form.analyze-form {
    grid-template-columns: 1fr;
  }
  .btn-primary {
    width: 100%;
    justify-content: center;
  }
  .person-table th {
    width: 45%;
  }
}
