/* ============================================================
   SAWYER HOUSE TOOLS — shared.css
   ============================================================
   Drop-in replacement. Same class names and structure as before,
   retuned to the Writer/Performer direction so the skin no longer
   has to fight it:

     - Nitti Grotesk for the interface, Nitti Typewriter for the
       page and numeric readouts. No Fraunces, no IBM Plex Mono.
     - The cooler ground (#f3f2f2 / #201e1d) and the single red.
     - Nothing in the chrome below 12.5px; 40px control height.
     - Rules carry real weight: hairlines at 0.4 alpha, 2px on
       structural edges.

   Link it once, AFTER the font kit:

     <link rel="stylesheet" href="wp-fonts-nitti.css">
     <link rel="stylesheet" href="/shared.css">

   Trimmed from the previous version: the Google Fonts dependency,
   the brand-crumb hover expansion, --shadow/--shadow-lg (both were
   already none), and the .section-title::after reset (the trick it
   undid is gone).

   THEME: set on <html>. Default is paper (light).
   data-theme="noir" is dark. Both share identical structure.
   ============================================================ */

/* ---------- Design tokens: shared across themes ---------- */
:root {
  /* Three roles, one family. Display is the condensed cut — the kit
     caps at 700, so condensed carries poster scale. */
  --font-display: 'nitti-grotesk-condensed', 'nitti-grotesk', sans-serif;
  --font-body:    'nitti-grotesk', 'Helvetica Neue', Arial, sans-serif;
  --font-light:   'nitti-grotesk-light', 'nitti-grotesk', sans-serif;
  --font-mono:    'nitti-typewriter-normal', 'Courier New', monospace;

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

  --transition: 0.12s ease;

  /* Structure */
  --radius: 0px;
  --radius-sm: 0px;
  --border-w: 1px;
  --rule-w: 2px;
  --panel-border-style: solid;

  /* Interface scale. Nothing in the chrome goes below --ui-sm. */
  --ui-sm: 1rem;
  --ui:    1rem;
  --ui-lg: 1rem;
  --control-h: 40px;
  --control-h-sm: 36px;

  /* Uppercase tracking eases as size grows — never past 0.08em. */
  --track: 0.07em;
  --track-tight: 0.04em;
}

/* ---------- Paper theme (light, default) ---------- */
:root,
html[data-theme="paper"],
html[data-theme="light"] {
  --bg: #f3f2f2;
  --panel: #f3f2f2;
  --panel-2: #eae9e9;
  --panel-3: #e0dfdf;
  --ink: #201e1d;
  --muted: #5c5958;              /* 6.5:1 on this ground */
  --line: rgba(32, 30, 29, 0.4);

  --accent: #ec3013;
  --accent-dim: rgba(236, 48, 19, 0.10);
  --accent-glow: rgba(236, 48, 19, 0.22);
  --accent-ink: #f3f2f2;
  --accent-deep: #ae1800;        /* accent at paragraph size */

  --sage: #4a6b52;
  --sage-dim: rgba(74, 107, 82, 0.12);
  --danger: #ae1800;
  --danger-dim: rgba(174, 24, 0, 0.10);
}

/* ---------- Noir theme (dark) ---------- */
html[data-theme="noir"],
html[data-theme="dark"] {
  --bg: #201e1d;
  --panel: #201e1d;
  --panel-2: #2d2b2b;
  --panel-3: #383535;
  --ink: #f3f2f2;
  --muted: #b3afaf;              /* 7:1 on this ground */
  --line: rgba(243, 242, 242, 0.28);

  --accent: #ec3013;
  --accent-dim: rgba(236, 48, 19, 0.16);
  --accent-glow: rgba(236, 48, 19, 0.28);
  --accent-ink: #f3f2f2;
  --accent-deep: #ff6a4d;

  --sage: #6a9472;
  --sage-dim: rgba(106, 148, 114, 0.14);
  --danger: #ff7a5c;
  --danger-dim: rgba(255, 122, 92, 0.14);
}

/* ============================================================
   Base reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--ui);
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(236, 48, 19, 0.3); color: var(--ink); }

a { color: var(--accent-deep); text-decoration: underline; }
a:hover { color: var(--accent); }

hr {
  border: none;
  border-top: var(--rule-w) solid var(--ink);
  margin: var(--space-5) 0;
}

/* ============================================================
   Typography — display is condensed, running copy is the light cut
   ============================================================ */
h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.02;
  text-transform: uppercase;
  margin: 0;
  color: var(--ink);
}

h1, .display-lg { font-size: clamp(2rem, 4vw, 3.2rem); }
h2, .display-md { font-size: 1.75rem; }
h3, .display-sm { font-size: 1.2rem; }

h1 em, h2 em, .display em {
  font-style: normal;
  color: var(--accent);
}

.eyebrow {
  font-family: var(--font-body);
  font-size: var(--ui-sm);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.eyebrow.accent { color: var(--accent-deep); }

p {
  font-family: var(--font-light);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink);
  max-width: 70ch;
  text-wrap: pretty;
}

.muted { color: var(--muted); }

.mono {
  font-family: var(--font-mono);
  font-size: 1rem;
}

/* ============================================================
   Layout shells
   ============================================================ */
.page {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-5) var(--space-8);
}

/* ============================================================
   Tool header — divided cells, not spaced items
   ============================================================ */
.tool-header {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  height: 54px;
  border-bottom: var(--rule-w) solid var(--ink);
  background: var(--bg);
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.tool-header h1 {
  font-family: var(--font-display);
  font-size: var(--ui-lg);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-tight);
  margin: 0;
  padding: 0 26px 0 20px;
  border-right: var(--rule-w) hidden var(--ink);
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  white-space: nowrap;
}

.tool-header .dot { display: none; }

.tool-header .brand-mark {
  height: 15px;
  width: auto;
  border-radius: 0;
  flex-shrink: 0;
}

.brand-crumb {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  line-height: 0;
}

.tool-header .spacer { flex: 1; }

.tool-header .home-link {
  display: flex;
  align-items: center;
  padding: 0 18px;
  border-left: var(--border-w) solid var(--line);
  font-family: var(--font-body);
  font-size: var(--ui-sm);
  font-weight: 700;
  letter-spacing: var(--track);
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}
.tool-header .home-link:hover { background: var(--ink); color: var(--bg); }

/* The cell edge IS the divider — no floating hairlines. */
.tool-header .header-divider { display: none; }

/* ============================================================
   Panels / cards — no radius, ruled edges only
   ============================================================ */
.panel, .card {
  background: var(--panel);
  border: var(--border-w) solid var(--line);
  border-radius: 0;
  box-shadow: none;
  padding: var(--space-4);
}

.card {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: border-color var(--transition), background var(--transition);
}

.card:hover {
  border-left-width: 3px;
  border-left-color: var(--accent);
  background: var(--panel-2);
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

.card-desc {
  font-family: var(--font-light);
  font-size: 1rem;
  color: var(--ink);
  line-height: 1.6;
}

.card-link {
  margin-top: var(--space-2);
  font-family: var(--font-body);
  font-size: var(--ui-sm);
  font-weight: 700;
  letter-spacing: var(--track);
  color: var(--muted);
  text-transform: uppercase;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
}

/* ============================================================
   Buttons — flush-left labels, square, one height
   ============================================================ */
button, .btn {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: var(--track);
  text-transform: uppercase;
  background: transparent;
  border: var(--border-w) solid var(--line);
  color: var(--ink);
  height: var(--control-h);
  min-height: var(--control-h);
  padding: 0 1rem;
  border-radius: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;   /* Modernist: labels are never centered */
  gap: var(--space-2);
  white-space: nowrap;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}

button.small, .btn.small {
  height: var(--control-h-sm);
  min-height: var(--control-h-sm);
  font-size: var(--ui-sm);
}

button:hover:not(:disabled), .btn:hover:not(:disabled) {
  border-color: var(--ink);
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
button:active:not(:disabled), .btn:active:not(:disabled) {
  background: color-mix(in srgb, var(--ink) 14%, transparent);
}

button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled, .btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Primary: solid accent fill — the one place red runs as a field. */
button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
button.primary:hover:not(:disabled), .btn.primary:hover:not(:disabled) {
  background: #dd2b0f;
  border-color: #dd2b0f;
  opacity: 1;
  color: var(--accent-ink);
}

button.danger, .btn.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover:not(:disabled), .btn.danger:hover:not(:disabled) {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--bg);
}

/* Icon-only buttons are the one exception: square and centered. */
.icon-btn, button.icon-only {
  width: 44px;
  height: 44px;
  min-height: 0;
  padding: 0;
  justify-content: center;
  flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }

/* ============================================================
   Forms — one control height, labels tight to their field
   ============================================================ */
input, select, textarea {
  font-family: var(--font-body);
  font-size: var(--ui-lg);       /* 15px keeps iOS from zooming on focus */
  background: var(--panel);
  border: var(--border-w) solid var(--line);
  color: var(--ink);
  border-radius: 0;
  height: var(--control-h);
  min-height: var(--control-h);
  padding: 0 0.7rem;
  appearance: none;
  -webkit-appearance: none;
}

textarea {
  height: auto;
  min-height: 96px;
  padding: 10px 12px;
  line-height: 1.6;
}

input[type="checkbox"], input[type="radio"] {
  appearance: auto;
  -webkit-appearance: checkbox;
  width: 20px;
  height: 20px;
  min-height: 0;
  background: revert;
  border: revert;
  border-radius: revert;
  padding: revert;
  accent-color: var(--ink);
}

/* Range: 2px ink track, square accent thumb, no field border. */
input[type="range"] {
  height: var(--control-h);
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 20px;
  margin-top: -9px;
  border: none; border-radius: 0;
  background: var(--accent);
}
input[type="range"]::-moz-range-track { height: 2px; background: var(--line); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 20px;
  border: none; border-radius: 0;
  background: var(--accent);
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--ink);
}

label {
  display: block;
  margin: 0 0 6px;
  font-family: var(--font-body);
  font-size: var(--ui-sm);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field { display: flex; flex-direction: column; gap: 6px; }

/* Rows align on the control baseline, never on text. */
.field-row, .toolbar-row, .modal-actions, .dialog-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.modal-actions, .dialog-actions {
  justify-content: flex-end;
  padding-top: var(--space-4);
  margin-top: var(--space-5);
  border-top: var(--border-w) solid var(--line);
}
.modal-actions .danger, .dialog-actions .danger { margin-right: auto; }

/* Drop-zone */
.dropzone {
  border: 1px dashed var(--line);
  border-radius: 0;
  padding: var(--space-6);
  color: var(--muted);
  font-family: var(--font-body);
  font-size: var(--ui);
  transition: border-color var(--transition), color var(--transition);
}
.dropzone.active, .dropzone:hover {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent-dim);
}

/* ============================================================
   Status / pills / badges — readouts stay typewriter
   ============================================================ */
.status {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--muted);
}
.status.err { color: var(--danger); }
.status.ok  { color: var(--sage); }

.help-text {
  font-family: var(--font-light);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink);
  max-width: 70ch;
  margin-top: var(--space-2);
  text-wrap: pretty;
}
.help-text a { color: var(--accent-deep); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-family: var(--font-body);
  font-size: var(--ui-sm);
  font-weight: 700;
  letter-spacing: var(--track);
  text-transform: uppercase;
  padding: 0.3em 0.6em;
  border-radius: 0;
  border: var(--border-w) solid var(--line);
  color: var(--muted);
}
.pill.accent { border-color: var(--accent); color: var(--accent-deep); background: var(--accent-dim); }
.pill.ok  { border-color: var(--sage); color: var(--sage); background: var(--sage-dim); }
.pill.err { border-color: var(--danger); color: var(--danger); background: var(--danger-dim); }

/* ============================================================
   Rows / tables
   ============================================================ */
.row-list {
  border: var(--border-w) solid var(--line);
  border-radius: 0;
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-bottom: var(--border-w) solid var(--line);
  font-family: var(--font-mono);
  font-size: 1rem;
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--panel-2); }

.row .type {
  width: 110px;
  flex-shrink: 0;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: var(--ui-sm);
  font-weight: 700;
  letter-spacing: var(--track);
  text-transform: uppercase;
}
.row .text { color: var(--ink); white-space: pre-wrap; font-family: var(--font-mono); }

/* ============================================================
   Tab navigation — the active tab is a solid ink block
   ============================================================ */
nav.tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: var(--bg);
  border-bottom: var(--rule-w) solid var(--ink);
  flex-shrink: 0;
}

nav.tabs button {
  background: transparent;
  border: none;
  border-right: var(--border-w) solid var(--line);
  border-radius: 0;
  height: auto;
  min-height: 0;
  align-self: stretch;
  padding: 0 20px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: var(--ui);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  justify-content: center;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  white-space: nowrap;
}
nav.tabs button:hover:not(.active) {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
nav.tabs button.active {
  background: var(--ink);
  color: var(--bg);
}

.tabs-spacer { flex: 1; }

/* ============================================================
   Theme toggle
   ============================================================ */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-size: var(--ui-sm);
  color: var(--muted);
}

.theme-toggle button.theme-swatch {
  display: flex;
  align-items: center;
  gap: 0.4em;
  height: var(--control-h-sm);
  min-height: var(--control-h-sm);
  padding: 0 0.6rem;
  border-radius: 0;
}
.theme-toggle button.theme-swatch.active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}
.swatch-dot { width: 10px; height: 10px; border-radius: 0; flex-shrink: 0; }

/* ============================================================
   Section titles — 2px rule, tracked label
   ============================================================ */
.section-title {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 10px;
  border-bottom: var(--rule-w) solid var(--ink);
  margin: 0 0 var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ============================================================
   Motion & accessibility
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (prefers-contrast: more) {
  :root { --line: var(--ink); --muted: var(--ink); }
  button, .btn, input, select, textarea { border-color: var(--ink); }
}

/* Small viewports: the chrome gets bigger, not smaller. */
@media (max-width: 860px) {
  nav.tabs button { font-size: 1rem; padding: 0 16px; }
  .icon-btn { width: 48px; height: 48px; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--ink); }
