/* Trace Read theme: "mail-room routing slip".
   Cool sorting-room paper, graphite ink, one copper postmark accent.
   Signature: the ticket summary is a monospace slip with a copper dashed tear line on top.
   Loaded after the template stylesheet; structural template rules (.ad-slot height, footer,
   consent banner) are styled here but never resized. */

:root {
  color-scheme: light;

  /* Palette */
  --tr-bg: #f1f2ee;
  --tr-surface: #fafaf7;
  --tr-raised: #ffffff;
  --tr-text: #1b2025;
  --tr-muted: #4a535c;
  --tr-border: #858e96;
  --tr-hairline: #d5d9d6;
  --tr-accent: #94450f;
  --tr-accent-hover: #7a380b;
  --tr-accent-active: #622c08;
  --tr-on-accent: #ffffff;
  --tr-accent-soft: #f6e8db;
  --tr-success: #1f6139;
  --tr-success-soft: #e3f1e7;
  --tr-warning: #7f4d00;
  --tr-warning-soft: #fbefd8;
  --tr-danger: #9f2b25;
  --tr-danger-soft: #fbe9e6;
  --tr-focus: #94450f;

  /* Type */
  --tr-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --tr-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --tr-step-label: 0.8125rem;  /* 13px labels, set apart by weight + tracking */
  --tr-step-small: 0.9375rem;  /* 15px help text */
  --tr-step-body: 1.0625rem;   /* 17px body */
  --tr-step-section: 1.3125rem;/* 21px card headings */
  --tr-step-figure: 2.25rem;   /* 36px tally numbers */
  --tr-step-title: 2.75rem;    /* 44px page title */

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

  /* Shape and depth */
  --tr-radius-sm: 6px;
  --tr-radius: 10px;
  --tr-radius-lg: 16px;
  --tr-shadow: 0 1px 2px rgb(27 32 37 / 6%), 0 4px 12px rgb(27 32 37 / 5%);
  --tr-shadow-slip: 0 2px 4px rgb(27 32 37 / 6%), 0 16px 36px rgb(27 32 37 / 10%);

  --tr-motion: 170ms;
  --tr-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --tr-bg: #14181c;
    --tr-surface: #1b2025;
    --tr-raised: #22282e;
    --tr-text: #eef1f3;
    --tr-muted: #b4bdc5;
    --tr-border: #7f8a93;
    --tr-hairline: #343c43;
    --tr-accent: #f0a566;
    --tr-accent-hover: #f6bd8c;
    --tr-accent-active: #e48f48;
    --tr-on-accent: #2b1504;
    --tr-accent-soft: #3a2a1d;
    --tr-success: #8fd5a6;
    --tr-success-soft: #1f3327;
    --tr-warning: #f2c46b;
    --tr-warning-soft: #3a2f17;
    --tr-danger: #ffaba2;
    --tr-danger-soft: #3e2422;
    --tr-focus: #f0a566;
    --tr-shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 12px rgb(0 0 0 / 20%);
    --tr-shadow-slip: 0 2px 4px rgb(0 0 0 / 30%), 0 16px 36px rgb(0 0 0 / 35%);
  }
}

/* ---------- Base ---------- */

html {
  background: var(--tr-bg);
}

body {
  margin: 0;
  background: var(--tr-bg);
  color: var(--tr-text);
  font-family: var(--tr-font);
  font-size: var(--tr-step-body);
  line-height: 1.5;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

.tr-page {
  box-sizing: border-box;
  width: min(100%, 68rem);
  margin-inline: auto;
  padding: var(--tr-s7) var(--tr-s6) var(--tr-s7);
  display: grid;
  gap: var(--tr-s5);
}

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

.tr-page h1,
.tr-page h2,
.tr-page h3,
.tr-page p,
.tr-page pre,
.tr-page ol,
.tr-page ul,
.tr-page dl,
.tr-page dd {
  margin: 0;
}

.tr-page h1 {
  font-size: var(--tr-step-title);
  line-height: 1.05;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.tr-page h2 {
  font-size: var(--tr-step-section);
  line-height: 1.25;
  font-weight: 680;
  letter-spacing: -0.005em;
}

.tr-page h3 {
  font-size: var(--tr-step-body);
  line-height: 1.35;
  font-weight: 650;
}

.tr-page p,
.tr-page li {
  max-width: 68ch;
}

/* Masthead: a small copper postmark ring beside the title */
.tr-head {
  display: grid;
  gap: var(--tr-s3);
}

.tr-mark {
  display: inline-flex;
  align-items: center;
  gap: var(--tr-s3);
}

.tr-mark svg {
  inline-size: 40px;
  block-size: 40px;
  flex: none;
  color: var(--tr-accent);
}

.tr-intro {
  font-size: 1.1875rem;
  line-height: 1.5;
  color: var(--tr-muted);
}

.tr-label,
.tr-eyebrow {
  font-size: var(--tr-step-label);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tr-text);
}

.tr-help,
.tr-muted {
  font-size: var(--tr-step-small);
  color: var(--tr-muted);
}

.tr-page code,
.tr-filename,
.tr-mono {
  font-family: var(--tr-mono);
  font-size: 0.92em;
}

.tr-page :not(pre) > code {
  padding: 1px var(--tr-s1);
  border-radius: var(--tr-radius-sm);
  background: var(--tr-accent-soft);
  color: var(--tr-text);
}

/* ---------- Links ---------- */

.tr-page a,
.tr-link {
  color: var(--tr-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: color var(--tr-motion) var(--tr-ease);
}

.tr-page a:hover,
.tr-link:hover {
  color: var(--tr-accent-hover);
  text-decoration-thickness: 2px;
}

.tr-page a:active,
.tr-link:active {
  color: var(--tr-accent-active);
}

/* ---------- Focus ---------- */

.tr-page :focus-visible,
.site-footer :focus-visible,
.consent-banner :focus-visible,
#consent :focus-visible {
  outline: 3px solid var(--tr-focus);
  outline-offset: 3px;
  border-radius: var(--tr-radius-sm);
}

/* ---------- Input cards ---------- */

.tr-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: var(--tr-s5);
  align-items: stretch;
}

.tr-card {
  display: grid;
  align-content: start;
  gap: var(--tr-s3);
  padding: var(--tr-s5);
  background: var(--tr-surface);
  border: 1px solid var(--tr-hairline);
  border-radius: var(--tr-radius-lg);
  box-shadow: var(--tr-shadow);
  transition: border-color var(--tr-motion) var(--tr-ease);
}

.tr-card:focus-within {
  border-color: var(--tr-border);
}

.tr-card-step {
  display: inline-flex;
  align-items: center;
  gap: var(--tr-s2);
}

.tr-card-step .tr-num {
  display: inline-grid;
  place-items: center;
  inline-size: 24px;
  block-size: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--tr-accent);
  color: var(--tr-accent);
  font-size: var(--tr-step-label);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

/* File picker: native input stays keyboard operable; styled label follows it */
.tr-file-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--tr-s3);
  padding: var(--tr-s4);
  border: 1.5px dashed var(--tr-border);
  border-radius: var(--tr-radius);
  background: var(--tr-raised);
  min-block-size: 76px;
}

.tr-file-controls.is-loaded {
  border-style: solid;
  border-color: var(--tr-success);
  background: var(--tr-success-soft);
}

.tr-file-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

.tr-file-input:focus-visible + .tr-button {
  outline: 3px solid var(--tr-focus);
  outline-offset: 3px;
}

.tr-filename {
  min-inline-size: 0;
  flex: 1 1 12rem;
  color: var(--tr-muted);
}

.tr-file-controls.is-loaded .tr-filename {
  color: var(--tr-text);
  font-weight: 600;
}

/* Textarea, text inputs, selects */
.tr-textarea,
.tr-page textarea,
.tr-page input[type="text"],
.tr-page input[type="email"],
.tr-page select {
  inline-size: 100%;
  font: inherit;
  color: var(--tr-text);
  background: var(--tr-raised);
  border: 1.5px solid var(--tr-border);
  border-radius: var(--tr-radius);
  padding: var(--tr-s3) var(--tr-s4);
  min-block-size: 44px;
  transition: border-color var(--tr-motion) var(--tr-ease), box-shadow var(--tr-motion) var(--tr-ease);
}

.tr-textarea,
.tr-page textarea {
  font-family: var(--tr-mono);
  font-size: var(--tr-step-small);
  line-height: 1.6;
  min-block-size: 11rem;
  resize: vertical;
}

.tr-page textarea::placeholder {
  color: var(--tr-muted);
  opacity: 1;
}

.tr-textarea:hover,
.tr-page textarea:hover,
.tr-page select:hover {
  border-color: var(--tr-text);
}

.tr-page textarea:focus-visible,
.tr-page input[type="text"]:focus-visible,
.tr-page input[type="email"]:focus-visible,
.tr-page select:focus-visible {
  outline: 3px solid var(--tr-focus);
  outline-offset: 1px;
  border-color: var(--tr-accent);
}

.tr-page [aria-invalid="true"] {
  border-color: var(--tr-danger);
}

.tr-page input[type="checkbox"] {
  inline-size: 20px;
  block-size: 20px;
  accent-color: var(--tr-accent);
}

/* Field errors sit directly under their input; reserved line so nothing jumps */
.tr-error {
  min-block-size: 1.5em;
  font-size: var(--tr-step-small);
  font-weight: 600;
  color: var(--tr-danger);
}

.tr-error:not(:empty) {
  display: flex;
  gap: var(--tr-s2);
  align-items: flex-start;
  padding: var(--tr-s2) var(--tr-s3);
  border-radius: var(--tr-radius-sm);
  background: var(--tr-danger-soft);
}

.tr-error svg {
  flex: none;
  inline-size: 18px;
  block-size: 18px;
  margin-block-start: 2px;
}

/* ---------- Buttons ---------- */

.tr-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--tr-s2);
  min-block-size: 44px;
  padding: var(--tr-s2) var(--tr-s5);
  border: 1.5px solid var(--tr-accent);
  border-radius: var(--tr-radius);
  background: transparent;
  color: var(--tr-accent);
  font: inherit;
  font-size: var(--tr-step-body);
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--tr-motion) var(--tr-ease),
    border-color var(--tr-motion) var(--tr-ease),
    color var(--tr-motion) var(--tr-ease),
    transform var(--tr-motion) var(--tr-ease);
}

.tr-button svg {
  inline-size: 18px;
  block-size: 18px;
  flex: none;
}

.tr-button:hover {
  background: var(--tr-accent-soft);
}

.tr-button:active {
  transform: translateY(1px);
}

.tr-button--primary {
  background: var(--tr-accent);
  color: var(--tr-on-accent);
  min-block-size: 52px;
  padding-inline: var(--tr-s6);
  box-shadow: var(--tr-shadow);
}

.tr-button--primary:hover {
  background: var(--tr-accent-hover);
  border-color: var(--tr-accent-hover);
}

.tr-button--primary:active {
  background: var(--tr-accent-active);
  border-color: var(--tr-accent-active);
}

.tr-button--secondary {
  background: var(--tr-raised);
}

.tr-button--quiet {
  border-color: transparent;
  background: transparent;
  padding-inline: var(--tr-s3);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.tr-button--quiet:hover {
  background: var(--tr-accent-soft);
}

.tr-button[disabled],
.tr-button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

/* Copy button keeps its width when "Copy summary" becomes "Copied" */
.tr-copy {
  min-inline-size: 11.5rem;
}

.tr-copy.is-done {
  border-color: var(--tr-success);
  color: var(--tr-success);
  background: var(--tr-success-soft);
}

/* ---------- Run row ---------- */

.tr-run {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--tr-s3) var(--tr-s4);
}

.tr-run .tr-button--primary {
  min-inline-size: 16rem;
}

.tr-status {
  min-block-size: 1.5em;
  font-size: var(--tr-step-small);
  color: var(--tr-muted);
  font-variant-numeric: tabular-nums;
}

.tr-privacy {
  display: flex;
  gap: var(--tr-s2);
  align-items: flex-start;
  font-size: var(--tr-step-small);
  color: var(--tr-muted);
}

.tr-privacy svg {
  flex: none;
  inline-size: 18px;
  block-size: 18px;
  margin-block-start: 2px;
  color: var(--tr-success);
}

/* ---------- Result slot ---------- */

.tr-result {
  min-block-size: 12rem;
  display: grid;
}

.tr-state {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--tr-s3);
  min-block-size: 12rem;
  padding: var(--tr-s6) var(--tr-s5);
  border: 1.5px dashed var(--tr-hairline);
  border-radius: var(--tr-radius-lg);
  color: var(--tr-muted);
  text-align: center;
}

.tr-state svg {
  inline-size: 40px;
  block-size: 40px;
  color: var(--tr-border);
}

.tr-state--loading {
  border-style: solid;
  border-color: var(--tr-border);
  color: var(--tr-text);
}

.tr-state--loading svg {
  color: var(--tr-accent);
  animation: tr-spin 900ms linear infinite;
}

.tr-state--error {
  border-style: solid;
  border-color: var(--tr-danger);
  background: var(--tr-danger-soft);
  color: var(--tr-danger);
  font-weight: 600;
}

.tr-state--error svg {
  color: var(--tr-danger);
}

@keyframes tr-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Result: tally + slip ---------- */

.tr-report {
  display: grid;
  gap: var(--tr-s4);
  animation: tr-rise var(--tr-motion) var(--tr-ease) both;
}

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

.tr-report-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--tr-s3) var(--tr-s4);
}

.tr-report-head h2 {
  font-size: 1.625rem;
}

.tr-report-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--tr-s2) var(--tr-s3);
}

.tr-tally {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--tr-s3);
  padding: 0;
  list-style: none;
}

.tr-tally-item {
  display: grid;
  gap: var(--tr-s1);
  padding: var(--tr-s4) var(--tr-s4) var(--tr-s3);
  border-radius: var(--tr-radius);
  background: var(--tr-surface);
  border: 1px solid var(--tr-hairline);
  border-block-start: 4px solid var(--tr-success);
}

.tr-tally-item .tr-figure {
  font-size: var(--tr-step-figure);
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--tr-text);
}

.tr-tally-item .tr-label {
  color: var(--tr-muted);
}

.tr-tally-item--missing.is-attention {
  border-block-start-color: var(--tr-warning);
  background: var(--tr-warning-soft);
}

.tr-tally-item--missing.is-attention .tr-figure,
.tr-tally-item--missing.is-attention .tr-label {
  color: var(--tr-warning);
}

.tr-tally-item--expansion {
  border-block-start-color: var(--tr-border);
}

/* The signature: a routing slip with a copper dashed tear line across the top */
.tr-slip {
  position: relative;
  margin: 0;
  padding: var(--tr-s6) var(--tr-s6) var(--tr-s5);
  background: var(--tr-raised);
  color: var(--tr-text);
  border: 1px solid var(--tr-hairline);
  border-radius: 0 0 var(--tr-radius-lg) var(--tr-radius-lg);
  box-shadow: var(--tr-shadow-slip);
  font-family: var(--tr-mono);
  font-size: 0.9375rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
  user-select: text;
  font-variant-numeric: tabular-nums;
}

.tr-slip::before {
  content: "";
  position: absolute;
  inset: -1px -1px auto -1px;
  block-size: 0;
  border-block-start: 3px dashed var(--tr-accent);
}

.tr-slip:focus-visible {
  outline: 3px solid var(--tr-focus);
  outline-offset: 3px;
}

.tr-slip ::selection,
.tr-slip::selection {
  background: var(--tr-accent-soft);
  color: var(--tr-text);
}

/* Optional spans inside the slip; they never change its text */
.tr-slip-id {
  font-weight: 700;
}

.tr-slip-head {
  font-weight: 700;
  color: var(--tr-accent);
}

.tr-slip-caveat {
  color: var(--tr-muted);
}

.tr-copy-note {
  min-block-size: 1.5em;
  font-size: var(--tr-step-small);
  font-weight: 600;
  color: var(--tr-success);
}

.tr-copy-note.is-manual {
  color: var(--tr-warning);
}

/* ---------- Preparation guide (disclosure) ---------- */

.tr-prep {
  border: 1px solid var(--tr-hairline);
  border-radius: var(--tr-radius-lg);
  background: var(--tr-surface);
}

.tr-prep > summary {
  display: flex;
  align-items: center;
  gap: var(--tr-s2);
  min-block-size: 56px;
  padding: var(--tr-s3) var(--tr-s5);
  font-weight: 650;
  font-size: var(--tr-step-body);
  cursor: pointer;
  border-radius: var(--tr-radius-lg);
  list-style: none;
  transition: background-color var(--tr-motion) var(--tr-ease);
}

.tr-prep > summary::-webkit-details-marker {
  display: none;
}

.tr-prep > summary::before {
  content: "";
  inline-size: 8px;
  block-size: 8px;
  border-inline-end: 2px solid var(--tr-accent);
  border-block-end: 2px solid var(--tr-accent);
  transform: rotate(-45deg);
  transition: transform var(--tr-motion) var(--tr-ease);
  margin-inline-end: var(--tr-s2);
}

.tr-prep[open] > summary::before {
  transform: rotate(45deg);
}

.tr-prep > summary:hover {
  background: var(--tr-accent-soft);
}

.tr-prep-body {
  display: grid;
  gap: var(--tr-s4);
  padding: 0 var(--tr-s5) var(--tr-s5);
}

.tr-prep ol {
  padding-inline-start: 1.4em;
  display: grid;
  gap: var(--tr-s2);
}

.tr-prep pre {
  padding: var(--tr-s4);
  border-radius: var(--tr-radius);
  background: var(--tr-raised);
  border: 1px solid var(--tr-hairline);
  font-family: var(--tr-mono);
  font-size: var(--tr-step-small);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Column mapping table */
.tr-table {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: var(--tr-step-small);
}

.tr-table th,
.tr-table td {
  text-align: start;
  vertical-align: top;
  padding: var(--tr-s2) var(--tr-s3);
  border-block-end: 1px solid var(--tr-hairline);
}

.tr-table th {
  font-size: var(--tr-step-label);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tr-table td:first-child {
  font-family: var(--tr-mono);
  white-space: nowrap;
}

/* ---------- Utilities ---------- */

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Template furniture: restyle only, never resize ---------- */

.ad-slot {
  border: 1px dashed var(--tr-hairline);
  border-radius: var(--tr-radius);
  background: var(--tr-surface);
  color: var(--tr-muted);
}

.site-footer {
  color: var(--tr-muted);
  font-size: var(--tr-step-small);
  border-block-start: 1px solid var(--tr-hairline);
}

.site-footer a {
  color: var(--tr-accent);
  min-block-size: 44px;
  display: inline-flex;
  align-items: center;
}

.site-footer a:hover {
  color: var(--tr-accent-hover);
}

.consent-banner,
#consent {
  background: var(--tr-raised);
  color: var(--tr-text);
  border-block-start: 1px solid var(--tr-hairline);
  box-shadow: var(--tr-shadow-slip);
}

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

@media (max-width: 46rem) {
  :root {
    --tr-step-title: 2.125rem;
    --tr-step-figure: 1.875rem;
  }

  .tr-page {
    padding: var(--tr-s6) var(--tr-s4) var(--tr-s7);
    gap: var(--tr-s4);
  }

  .tr-inputs {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--tr-s4);
  }

  .tr-card {
    padding: var(--tr-s4);
  }

  .tr-run .tr-button--primary,
  .tr-report-actions,
  .tr-report-actions .tr-button {
    inline-size: 100%;
  }

  .tr-tally {
    gap: var(--tr-s2);
  }

  .tr-tally-item {
    padding: var(--tr-s3);
  }

  .tr-tally-item .tr-label {
    letter-spacing: 0.04em;
  }

  .tr-slip {
    padding: var(--tr-s5) var(--tr-s4) var(--tr-s4);
    font-size: 0.875rem;
  }

  .tr-prep-body {
    padding: 0 var(--tr-s4) var(--tr-s4);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .tr-page *,
  .tr-page *::before,
  .tr-page *::after {
    animation: none !important;
    transition: none !important;
  }

  .tr-button:active {
    transform: none;
  }
}
