/* ============================================================
   me — styles.css
   Two views: AGENT (raw markdown) · HUMAN (rendered, themeable).
   Light only by design — newspaper/soft/etc. supply their own paper.
   ============================================================ */

/* ---------- 1. Tokens --------------------------------------- */
:root {
  color-scheme: light;

  --bg: #ffffff;
  --fg: #0c0d10;
  --muted: #6b6b72;
  --soft: #f4f4f5;
  --soft-2: #ececee;
  --border: #e4e4e7;
  --accent: #0c0d10;
  --code-bg: #f2f2f4;
  --link: #0c0d10;
  --success: #1f7a3a;
  --warn: #b94a4a;
  --tip-bg: #161922;
  --tip-fg: #f5f5f6;

  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --font-serif: ui-serif, "Iowan Old Style", "Charter", "Georgia", serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --measure: 38rem;
  --radius-sm: 6px;
}

/* ---------- 2. Reset ---------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
img, svg { display: block; max-width: 100%; }
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
select { font: inherit; color: inherit; }

/* ---------- 3. Base ----------------------------------------- */
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: env(safe-area-inset-bottom);
}

a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent);
}
a:hover {
  text-decoration-color: var(--link);
  text-decoration-thickness: 1.5px;
}
a:focus-visible,
button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- 4. Skip link ------------------------------------ */
.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--bg);
  color: var(--fg);
  padding: 0.5rem 1rem;
  z-index: 100;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.skip:focus { left: 0.75rem; top: 0.75rem; }

/* ---------- 5. Toolbar (bar + controls) --------------------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-5);
  padding: var(--space-3) 0;
  margin-bottom: var(--space-5);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
@supports not (backdrop-filter: blur(10px)) {
  .bar { background: var(--bg); }
}

.bar__cluster {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
[data-view="agent"] .bar__cluster--theme { display: none; }

.bar__label {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
}

/* Segmented control — the AGENT/HUMAN tabs */
.bar__seg {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
}
.bar__seg button {
  position: relative;
  padding: 0.6rem 0.95rem;
  min-height: 44px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  color: var(--muted);
  border-radius: 0;
  transition: color 120ms ease;
}
.bar__seg button:hover { color: var(--fg); }
.bar__seg button[aria-selected="true"] { color: var(--fg); }
.bar__seg button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0.95rem;
  right: 0.95rem;
  bottom: 4px;
  height: 2px;
  background: var(--fg);
  border-radius: 1px;
}

/* Info button + tooltip */
.info {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.info__btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  color: var(--muted);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 120ms ease, background 120ms ease;
}
.info__svg { width: 18px; height: 18px; display: block; }
.info__btn:hover,
.info__btn:focus-visible {
  color: var(--fg);
  background: var(--soft);
}
.info__tip {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translate(-50%, -4px);
  z-index: 30;
  width: max-content;
  max-width: min(22rem, calc(100vw - 2rem));
  background: var(--tip-bg);
  color: var(--tip-fg);
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 12.75px;
  line-height: 1.55;
  letter-spacing: normal;
  text-transform: none;
  font-style: normal;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.info__tip strong {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.info__hint {
  display: block;
  margin-top: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px solid color-mix(in srgb, var(--tip-fg) 18%, transparent);
  font-size: 11.5px;
  opacity: 0.85;
}
.info__hint kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 0 0.35em;
  margin: 0 0.05em;
  border: 1px solid color-mix(in srgb, var(--tip-fg) 30%, transparent);
  border-radius: 3px;
  vertical-align: 1px;
}
.info__tip::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 8px;
  height: 8px;
  background: var(--tip-bg);
}
.info:hover .info__tip,
.info:focus-within .info__tip,
.info.is-open .info__tip {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

/* HUMAN-only theme picker */
#human-theme {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--soft);
  color: var(--fg);
  padding: 0.55rem 1.9rem 0.55rem 0.7rem;
  min-height: 40px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M3 4.5l3 3 3-3' stroke='gray' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 12px;
  transition: background-color 120ms ease;
}
#human-theme:hover { background-color: var(--soft-2); }

.bar__actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

.icon {
  position: relative;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--muted);
  transition: color 120ms ease, background 120ms ease;
}
.icon:hover { color: var(--fg); background: var(--soft); }
.icon__svg { width: 18px; height: 18px; }

.icon__check { display: none; }
[data-copy-state="copied"] .icon__copy { display: none; }
[data-copy-state="copied"] .icon__check { display: block; color: var(--success); }
[data-copy-state="failed"] .icon__copy { color: var(--warn); }

.content {
  flex: 1 1 auto;
  width: 100%;
}

.foot {
  margin-top: var(--space-7);
  padding: var(--space-4) 0 var(--space-5);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  color: var(--muted);
  line-height: 1.7;
}
.foot p { margin: 0; max-width: 56rem; }
.foot a { color: var(--muted); }
.foot a:hover { color: var(--fg); }

/* ---------- 6. Layout containers + view visibility ---------- */
[data-view="agent"] [data-view-panel="human"] { display: none; }
[data-view="human"] [data-view-panel="agent"] { display: none; }

.noscript {
  max-width: var(--measure);
  margin: var(--space-5) auto;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--soft);
  font-family: var(--font-sans);
  color: var(--muted);
  font-size: 14px;
}

/* ---------- 7. AGENT view — plain raw markdown -------------- */
.agent {
  width: 100%;
  max-width: 60rem;
  margin: 0 auto;
}
.agent__source {
  margin: 0;
  padding: var(--space-4) 0 var(--space-6);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--fg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}
.agent__source code {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  padding: 0;
}
@media (min-width: 720px) {
  .agent__source { font-size: 14.5px; }
}

/* ---------- 8. HUMAN view — Editorial (default) ------------- */
.human {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--space-5) 0 var(--space-7);
  font-family: var(--font-serif);
  font-size: clamp(1rem, 0.5vw + 0.92rem, 1.0625rem);
  line-height: 1.7;
  color: var(--fg);
}
.human > div { font-feature-settings: "kern", "liga"; }

.human h1, .human h2, .human h3 {
  font-family: var(--font-serif);
  color: var(--fg);
  text-wrap: balance;
}
.human h1 {
  font-size: clamp(2.2rem, 1rem + 4vw, 3.1rem);
  font-weight: 700;
  line-height: 1.06;
  letter-spacing: -0.015em;
  margin: 0 0 var(--space-2);
}
.human h1 + p {
  color: var(--muted);
  font-size: 1.05em;
  margin: 0 0 var(--space-6);
  font-style: italic;
}
.human h2 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: var(--space-5);
  margin: var(--space-7) 0 var(--space-4);
}
.human h3 {
  font-size: 1.18rem;
  font-style: italic;
  font-weight: 600;
  margin: var(--space-5) 0 var(--space-2);
  letter-spacing: -0.005em;
}
.human p { margin: 0 0 var(--space-4); }
.human ul, .human ol {
  padding-left: 1.25rem;
  margin: 0 0 var(--space-4);
}
.human li { margin-bottom: var(--space-2); }
.human li::marker { color: var(--muted); }
.human strong { font-weight: 700; }
.human em { font-style: italic; }
.human code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.88em;
}
.human a {
  color: var(--link);
  text-decoration-color: color-mix(in srgb, var(--link) 30%, transparent);
}

/* HR is hidden by default — H2 top border serves as the section divider.
   Themes without a border on H2 (soft, minimal) bring it back below. */
.human hr { display: none; }

/* ---------- 9. HUMAN themes -------------------------------- */

/* --- Brutalist --- */
[data-human-theme="brutalist"] { --measure: 44rem; }
[data-human-theme="brutalist"] .human,
[data-human-theme="brutalist"] .human h1,
[data-human-theme="brutalist"] .human h2,
[data-human-theme="brutalist"] .human h3 {
  font-family: var(--font-sans);
}
[data-human-theme="brutalist"] .human h1 {
  font-size: clamp(2.6rem, 1rem + 8vw, 4.4rem);
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 0.96;
  margin-bottom: var(--space-3);
}
[data-human-theme="brutalist"] .human h1 + p {
  font-style: normal;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.85em;
  color: var(--fg);
  margin-bottom: var(--space-6);
}
[data-human-theme="brutalist"] .human h2 {
  border-top: 4px solid var(--fg);
  padding-top: var(--space-3);
  font-size: 0.85rem;
  color: var(--fg);
  margin-top: var(--space-7);
  letter-spacing: 0.18em;
}
[data-human-theme="brutalist"] .human h3 {
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.96rem;
  font-weight: 800;
}
[data-human-theme="brutalist"] .human a { font-weight: 600; }

/* --- Newspaper --- */
[data-human-theme="newspaper"] {
  --bg: #fffdf6;
  --fg: #161616;
  --muted: #6b665a;
  --border: #c7c2b1;
  --code-bg: #f3ecd9;
  --link: #161616;
  --measure: 36rem;
}
[data-human-theme="newspaper"] .human {
  font-family: ui-serif, "Iowan Old Style", "Times New Roman", "Georgia", serif;
  text-align: justify;
  hyphens: auto;
}
[data-human-theme="newspaper"] .human h1 {
  text-align: center;
  font-weight: 900;
  font-size: clamp(2.3rem, 1rem + 6vw, 3.6rem);
  font-family: ui-serif, "Iowan Old Style", "Times New Roman", serif;
  border-top: 3px double var(--fg);
  border-bottom: 3px double var(--fg);
  padding: var(--space-3) 0;
  margin: var(--space-3) 0 var(--space-2);
  letter-spacing: -0.01em;
  line-height: 1.05;
}
[data-human-theme="newspaper"] .human h1 + p {
  text-align: center;
  font-style: italic;
  font-variant: small-caps;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-6);
  color: var(--fg);
}
[data-human-theme="newspaper"] .human h2 {
  text-align: left;
  border-top: 1px solid var(--fg);
  font-variant: small-caps;
  letter-spacing: 0.06em;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: none;
  color: var(--fg);
}
[data-human-theme="newspaper"] .human h3 {
  font-style: normal;
  font-variant: small-caps;
  letter-spacing: 0.04em;
  font-weight: 700;
}

/* --- Soft --- */
[data-human-theme="soft"] {
  --bg: #fbf6ec;
  --fg: #2a2520;
  --muted: #8e8474;
  --border: #d8cebb;
  --code-bg: #f2ead8;
  --link: #4a3c2c;
  --measure: 36rem;
}
[data-human-theme="soft"] .human {
  font-family: "Baskerville", "Iowan Old Style", "Hoefler Text", ui-serif, serif;
  line-height: 1.85;
}
[data-human-theme="soft"] .human h1 {
  font-weight: 400;
  font-style: italic;
  font-size: clamp(2.4rem, 1rem + 5vw, 3.4rem);
  letter-spacing: -0.005em;
  margin-bottom: var(--space-4);
}
[data-human-theme="soft"] .human h1 + p {
  font-style: italic;
  color: var(--muted);
}
[data-human-theme="soft"] .human h2 {
  border-top: none;
  text-transform: none;
  font-variant: small-caps;
  font-style: italic;
  letter-spacing: 0.06em;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--muted);
  padding-top: var(--space-5);
  margin-top: var(--space-6);
}
[data-human-theme="soft"] .human h3 {
  font-style: italic;
  font-weight: 500;
}
[data-human-theme="soft"] .human ul {
  list-style: none;
  padding-left: 1.5rem;
}
[data-human-theme="soft"] .human li {
  position: relative;
}
[data-human-theme="soft"] .human li::before {
  content: "○";
  position: absolute;
  left: -1.5rem;
  top: 0;
  color: var(--muted);
  font-size: 0.85em;
  line-height: 1.85;
}
[data-human-theme="soft"] .human hr {
  display: block;
  border: 0;
  border-top: 1px dotted var(--border);
  margin: var(--space-6) 0;
}

/* --- Minimal --- */
[data-human-theme="minimal"] .human,
[data-human-theme="minimal"] .human h1,
[data-human-theme="minimal"] .human h2,
[data-human-theme="minimal"] .human h3 {
  font-family: var(--font-sans);
}
[data-human-theme="minimal"] .human {
  font-size: clamp(0.95rem, 0.4vw + 0.88rem, 1.02rem);
  line-height: 1.65;
}
[data-human-theme="minimal"] .human h1 {
  font-weight: 700;
  font-size: clamp(1.95rem, 1rem + 3vw, 2.55rem);
  letter-spacing: -0.02em;
}
[data-human-theme="minimal"] .human h1 + p {
  font-style: normal;
}
[data-human-theme="minimal"] .human h2 {
  border-top: none;
  padding-top: 0;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: var(--space-6);
}
[data-human-theme="minimal"] .human h3 {
  font-style: normal;
  font-weight: 600;
  font-size: 1.08rem;
}
[data-human-theme="minimal"] .human hr {
  display: block;
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-5) 0;
}

/* ---------- 10. Mobile ------------------------------------- */
@media (max-width: 640px) {
  .bar {
    gap: var(--space-2) var(--space-3);
    padding: var(--space-2) 0;
  }
  .bar__label { font-size: 12px; }
  .bar__seg button { padding: 0.55rem 0.7rem; font-size: 11px; }
  .bar__seg button[aria-selected="true"]::after { left: 0.7rem; right: 0.7rem; }

  /* Theme cluster wraps to its own row in HUMAN view */
  [data-view="human"] .bar__cluster--theme {
    order: 99;
    flex: 1 1 100%;
    margin-top: var(--space-1);
  }
  [data-view="human"] #human-theme { flex: 1 1 auto; }

  /* Tooltip — banner just below the bar.
     .bar's backdrop-filter creates a containing block for fixed positioning,
     so left:0/right:0 spans the bar's padded width (= viewport minus body padding). */
  .info__tip {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 4.5rem);
    left: 0;
    right: 0;
    bottom: auto;
    transform: translateY(-4px);
    width: auto;
    max-width: none;
  }
  .info__tip::before { display: none; }
  .info:hover .info__tip,
  .info:focus-within .info__tip,
  .info.is-open .info__tip { transform: translateY(0); }

  .agent__source { padding: var(--space-3) 0 var(--space-5); font-size: 13px; }
  .human { padding: var(--space-4) 0 var(--space-6); }
  .human h2 { padding-top: var(--space-4); margin-top: var(--space-5); }
}

/* ---------- 11. Print -------------------------------------- */
@media print {
  /* Override tokens for ink — borders need to be darker than the on-screen #e4e4e7. */
  :root {
    --bg: #ffffff;
    --fg: #111111;
    --muted: #555555;
    --border: #999999;
    --accent: #111111;
    --code-bg: #f2f2f2;
    --link: #111111;
  }

  .bar, .foot, .skip { display: none !important; }
  [data-view-panel="agent"] { display: none !important; }
  [data-view-panel="human"] { display: block !important; }

  body { font-size: 10.5pt; line-height: 1.45; padding: 0; }
  .content { padding: 0; }
  .human {
    max-width: none;
    padding: 0;
    margin: 0;
    font-size: 10.5pt;
    font-family: var(--font-serif);
    line-height: 1.45;
  }
  .human h1 { font-size: 22pt; margin-top: 0; }
  .human h1 + p { margin-bottom: 14pt; }
  .human h2 {
    font-size: 9.5pt;
    margin-top: 14pt;
    padding-top: 6pt;
    border-top: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.12em;
  }
  .human h3 { font-size: 11pt; }
  .human h1, .human h2, .human h3 { break-after: avoid; page-break-after: avoid; }
  .human ul, .human ol, .human p { orphans: 3; widows: 3; }
  .human a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #555;
    font-style: italic;
  }
  @page { margin: 1.5cm; }
}
