/* theme.css: Poe Budget. "Wiring-closet clipboard": graphite ink on warm paper, one copper accent,
   monospace for every CLI line and watt figure. Signature: the ticket stub, a report card with a
   dashed tear line and a half-circle notch at each end of it.
   Loaded after styles.css, so these rules win. Structural template rules (.ad-slot height,
   .ads-off, footer, .consent) are restyled only, never resized. No images, no data URIs, no
   web fonts: every mark here is drawn with CSS. */

:root {
  color-scheme: light dark;

  /* Palette. Contrast figures are estimates against the surface named. */
  --bg: #f7f5f1;
  --surface: #ffffff;
  --raised: #efebe4;
  --text: #1d1b18;          /* ~16:1 on --bg */
  --muted: #57524a;         /* ~7.1:1 on --bg, ~6.5:1 on --raised */
  --border: #ddd6ca;
  --border-strong: #a39b8d;
  --accent: #9a4310;        /* white on it: ~6.6:1 */
  --accent-hover: #7e360c;  /* white on it: ~8.5:1 */
  --accent-text: #8a3c0e;   /* links: ~7.0:1 on --bg */
  --accent-tint: #f8e9dd;   /* --accent-text on it: ~6.3:1 */
  --on-accent: #ffffff;
  --success: #24683b;       /* ~5.8:1 on --success-tint */
  --success-tint: #e5f2e8;
  --warning: #85500a;       /* ~5.9:1 on --warning-tint */
  --warning-tint: #fbf0dc;
  --danger: #b02a1f;        /* ~5.6:1 on --danger-tint */
  --danger-tint: #fbeae7;
  --line: var(--border);    /* template token */

  /* Type */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.8125rem;     /* 13px caps labels */
  --text-sm: 0.9375rem;     /* 15px mono, small print */
  --text-md: 1.0625rem;     /* 17px body, report */
  --text-lg: 1.3125rem;     /* 21px h2 */
  --text-xl: 1.625rem;      /* 26px */
  --text-2xl: clamp(1.75rem, 4.6vw, 2.5rem); /* h1 */

  /* Space */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  /* Shape */
  --r-s: 6px;
  --r-m: 10px;
  --r-l: 16px;
  --shadow-1: 0 1px 2px rgb(29 27 24 / 0.06), 0 2px 6px rgb(29 27 24 / 0.04);
  --shadow-2: 0 10px 28px rgb(29 27 24 / 0.12), 0 2px 6px rgb(29 27 24 / 0.06);
  --ring: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent);

  /* The ticket stub: where the tear line sits, measured from the card's top edge. */
  --tear: 80px;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --fast: 160ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1c1a17;
    --raised: #25221e;
    --text: #ece7df;        /* ~15:1 on --bg */
    --muted: #b3aa9c;       /* ~7.5:1 on --surface, ~6.9:1 on --raised */
    --border: #36322c;
    --border-strong: #5f574c;
    --accent: #f0a46a;      /* --on-accent on it: ~8.7:1 */
    --accent-hover: #f6bb8c;
    --accent-text: #f4b583; /* ~10:1 on --bg */
    --accent-tint: #3a2516; /* --accent-text on it: ~7.5:1 */
    --on-accent: #2a1305;
    --success: #7ccf95;     /* ~8:1 on --success-tint */
    --success-tint: #17291d;
    --warning: #e9b45e;     /* ~7.8:1 on --warning-tint */
    --warning-tint: #2e2413;
    --danger: #ff9a8f;      /* ~8:1 on --danger-tint */
    --danger-tint: #35191a;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4), 0 2px 6px rgb(0 0 0 / 0.25);
    --shadow-2: 0 10px 28px rgb(0 0 0 / 0.5), 0 2px 6px rgb(0 0 0 / 0.3);
  }
}

/* ---------- Page ---------- */

html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
header, main, footer { max-width: 54rem; padding-left: var(--s5); padding-right: var(--s5); }
header { border-bottom: 1px solid var(--border); padding-top: var(--s3); padding-bottom: var(--s3); }
main { padding-top: var(--s6); padding-bottom: var(--s6); }

/* Reading text stays under about 70 characters a line; the tool panel uses the full column. */
main > p, main > ul, main > ol, main > h2, main > h3 { max-width: 68ch; }

h1 {
  font-size: var(--text-2xl);
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.12;
  margin: 0 0 var(--s3);
}
h2 {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin: var(--s7) 0 var(--s3);
}
h3 { font-size: var(--text-md); font-weight: 650; margin: var(--s5) 0 var(--s1); }
p { margin: 0 0 var(--s4); }
.lede { font-size: 1.125rem; color: var(--muted); margin-bottom: var(--s6); max-width: 60ch; }
main li { margin-bottom: var(--s2); }
main li::marker { color: var(--accent-text); font-weight: 700; }

a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

code, kbd {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--r-s);
  padding: 0 var(--s1);
}

/* ---------- Header brand: copper tile with a drawn RJ45 port ---------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  font-size: var(--text-md);
  font-weight: 750;
  letter-spacing: -0.01em;
  color: var(--text);
  position: relative;
}
.brand::before {
  content: "";
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
}
.brand::after {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 26px;
  height: 26px;
  margin-top: -13px;
  background: var(--on-accent);
  clip-path: polygon(21.9% 25%, 78.1% 25%, 78.1% 65.6%, 62.5% 65.6%, 62.5% 78.1%, 37.5% 78.1%, 37.5% 65.6%, 21.9% 65.6%);
}
header nav a { color: var(--muted); font-weight: 600; text-decoration: none; padding: 0 var(--s2); border-radius: var(--r-s); }
header nav a:hover { color: var(--text); background: var(--raised); }

/* ---------- Tool panel ---------- */

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-1);
  padding: var(--s5);
  margin: 0 0 var(--s6);
}

.field { display: block; margin: 0 0 var(--s2); }
.field-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text);
}
.field-hint { display: block; margin-top: var(--s1); font-size: var(--text-sm); color: var(--muted); }

.tool textarea,
textarea {
  display: block;
  width: 100%;
  min-height: 15rem;
  padding: var(--s3) var(--s4);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-m);
  font: var(--text-sm)/1.55 var(--font-mono);
  tab-size: 8;
  resize: vertical;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
textarea::placeholder { color: var(--muted); opacity: 1; }
textarea:hover { border-color: var(--text); }
textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

input[type="text"], input[type="search"], select {
  min-height: 44px;
  padding: var(--s2) var(--s3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-m);
  font: inherit;
}
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- Buttons: one filled primary, outlined secondary, quiet text ---------- */

.actions { display: flex; flex-wrap: wrap; gap: var(--s3); margin: var(--s4) 0 var(--s3); }

button,
.actions button {
  min-height: 44px;
  padding: 0 var(--s5);
  border-radius: var(--r-m);
  font: inherit;
  font-size: var(--text-md);
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
button:hover { border-color: var(--text); background: var(--raised); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

button.primary,
.actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }

button.quiet { background: transparent; border-color: transparent; color: var(--accent-text); padding: 0 var(--s3); }
button.quiet:hover { background: var(--accent-tint); }

/* Copy keeps its width whatever the status says. */
button.copy { min-width: 9.5rem; }

:focus-visible { outline: none; box-shadow: var(--ring); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; box-shadow: none; border-radius: 2px; }

/* ---------- Status line (two lines reserved, icon drawn in CSS) ---------- */

#status {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  min-height: calc(2 * 1.5em + 2 * var(--s2));
  margin: 0 0 var(--s3);
  padding: var(--s2) 0;
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.5;
  color: var(--muted);
}
#status::before {
  content: "";
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  display: none;
  font: 800 13px/20px var(--font-ui);
  text-align: center;
}
#status[data-state="success"] { color: var(--success); font-weight: 650; }
#status[data-state="success"]::before {
  display: block;
  background: var(--success);
}
/* The tick: a rotated L over the green dot. */
#status[data-state="success"] { position: relative; }
#status[data-state="success"]::after {
  content: "";
  position: absolute;
  left: 7px;
  top: calc(var(--s2) + 5px);
  width: 6px;
  height: 10px;
  border: solid var(--success-tint);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
#status[data-state="error"] {
  color: var(--danger);
  font-weight: 600;
  background: var(--danger-tint);
  border-radius: var(--r-m);
  padding: var(--s2) var(--s3);
}
#status[data-state="error"]::before { content: "!"; display: block; background: var(--danger); color: var(--danger-tint); }
#status[data-state="warning"] {
  color: var(--warning);
  font-weight: 600;
  background: var(--warning-tint);
  border-radius: var(--r-m);
  padding: var(--s2) var(--s3);
}
#status[data-state="warning"]::before { content: "i"; display: block; background: var(--warning); color: var(--warning-tint); font-family: ui-serif, Georgia, serif; }
#status code { background: transparent; border-color: currentColor; }
/* The template's own error class, in case the builder keeps it. */
#status.error { color: var(--danger); }

/* ---------- The ticket stub (signature) ---------- */

.report {
  position: relative;
  min-height: 15rem;
  padding: var(--s5);
  border-radius: var(--r-m);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  animation: stub-in 180ms var(--ease);
}
/* The two half-circle notches at the ends of the tear line, cut in the panel's colour. */
.report::before,
.report::after {
  content: "";
  position: absolute;
  top: calc(var(--tear) - 10px);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
}
.report::before { left: -11px; clip-path: inset(0 0 0 50%); }
.report::after { right: -11px; clip-path: inset(0 50% 0 0); }

.report-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  height: calc(var(--tear) - var(--s5));
  margin: 0 calc(-1 * var(--s5)) var(--s4);
  padding: 0 var(--s5) var(--s2);
  border-bottom: 2px dashed var(--accent);
}
.report-head .field-label { color: var(--accent-text); }

.report .report-text,
#report {
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: 500 var(--text-md)/1.65 var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: pre-wrap;
  resize: none;
  field-sizing: content;
}
#report:hover { border: 0; }
#report:focus { box-shadow: none; }
#report:focus-visible { box-shadow: var(--ring); border-radius: var(--r-s); }
#report::selection { background: var(--accent-tint); color: var(--text); }

.report-note { margin: var(--s4) 0 0; font-size: var(--text-sm); color: var(--muted); }

/* Empty and error: the same stub, ghosted, so the visitor sees where the result will land. */
.report[data-state="empty"],
.report[data-state="error"] {
  background: transparent;
  box-shadow: none;
  border-style: dashed;
  border-color: var(--border-strong);
  animation: none;
}
.report[data-state="empty"]::before, .report[data-state="empty"]::after,
.report[data-state="error"]::before, .report[data-state="error"]::after { border-style: dashed; }
.report-placeholder {
  margin: calc(var(--tear) - var(--s5)) calc(-1 * var(--s5)) 0;
  padding: var(--s5) var(--s5) 0;
  border-top: 2px dashed var(--border);
  font: var(--text-sm)/1.5 var(--font-mono);
  color: var(--muted);
}

@keyframes stub-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Worked example ---------- */

.example {
  margin: var(--s4) 0 var(--s5);
  padding: var(--s5);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
}
.example figcaption { margin: 0 0 var(--s2); color: var(--muted); }
.example figcaption ~ figcaption { margin-top: var(--s5); }
pre, .example pre {
  margin: 0;
  padding: var(--s3) var(--s4);
  overflow-x: auto;
  font: var(--text-sm)/1.55 var(--font-mono);
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-m);
  white-space: pre;
}
.example pre.ticket {
  border-color: var(--border-strong);
  border-top: 2px dashed var(--accent);
  border-radius: 0 0 var(--r-m) var(--r-m);
}

/* ---------- Tables (if the explanation uses one) ---------- */

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.07em; color: var(--text); }
th, td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); }

/* ---------- Ad slot, house card, consent, footer (restyled, never resized) ---------- */

.ad-slot { background: var(--raised); border: 1px solid var(--border); border-radius: var(--r-l); }
.ad-label { color: var(--muted); opacity: 1; font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.house-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-m);
  transition: border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.house-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.house-card strong { color: var(--accent-text); }
.house-card span { color: var(--muted); }

.consent { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-l); box-shadow: var(--shadow-2); }
.consent button { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.consent button:first-of-type { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

footer { opacity: 1; color: var(--muted); font-size: var(--text-sm); border-top: 1px solid var(--border); padding-top: var(--s5); padding-bottom: var(--s6); }
footer a { color: var(--accent-text); }

/* ---------- Phone ---------- */

@media (max-width: 36rem) {
  header, main, footer { padding-left: var(--s4); padding-right: var(--s4); }
  main { padding-top: var(--s5); }
  .tool { padding: var(--s4); border-radius: var(--r-m); }
  .actions { flex-direction: column; gap: var(--s2); }
  .actions button { width: 100%; }
  .report { padding: var(--s4); }
  .report-head { margin: 0 calc(-1 * var(--s4)) var(--s4); padding: 0 var(--s4) var(--s2); height: calc(var(--tear) - var(--s4)); }
  .report-placeholder { margin: calc(var(--tear) - var(--s4)) calc(-1 * var(--s4)) 0; padding: var(--s4) var(--s4) 0; }
  .report .report-text, #report { font-size: var(--text-sm); }
  .example { padding: var(--s4); }
}

/* ---------- Motion off ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  button:active, .house-card:hover { transform: none; }
}
