/* cookfail.dev — base styles and decoder. No framework, no web fonts. */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-2: #f2f0ec;
  --text: #1d1b18;
  --muted: #5d5850;
  --border: #dcd7cf;
  --accent: #b5401f;
  --accent-text: #ffffff;
  --link: #9a3412;
  --focus: #1d4ed8;
  --log-bg: #1e1d1b;
  --log-text: #e8e4dc;
  --log-no: #8a847a;
  --log-hit: #5a2a12;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #854d0e;
  --warn-bg: #fef3c7;
  --low: #57534e;
  --low-bg: #e7e5e4;
  --error: #b91c1c;
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --surface: #1f1e1c;
    --surface-2: #2a2826;
    --text: #ece8e1;
    --muted: #aaa398;
    --border: #3b3835;
    --accent: #e0693f;
    --accent-text: #161514;
    --link: #f29a72;
    --focus: #93c5fd;
    --log-bg: #0f0e0d;
    --log-hit: #5a2a12;
    --ok: #86efac;
    --ok-bg: #14321f;
    --warn: #fcd34d;
    --warn-bg: #3a2c0b;
    --low: #d6d3d1;
    --low-bg: #33302d;
    --error: #fca5a5;
    color-scheme: dark;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
}

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

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

code, pre { font-family: var(--mono); font-size: 0.9em; }
:not(pre) > code { background: var(--surface-2); padding: 0.1em 0.3em; border-radius: 4px; overflow-wrap: anywhere; }

h1, h2, h3, h4 { line-height: 1.25; }

.container { max-width: 960px; margin: 0 auto; padding: 0 16px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

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

.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0.5em 1.1em;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.button:hover { background: var(--surface-2); }
.button-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button-primary:hover { background: var(--accent); filter: brightness(1.08); }
.button:disabled { opacity: 0.6; cursor: progress; }

.link-button {
  border: 0; padding: 0; background: none;
  color: var(--link); font: inherit; text-decoration: underline; cursor: pointer;
}

/* Decoder ---------------------------------------------------------------- */

/* minmax(0, 1fr): long log lines scroll inside their block instead of widening the page. */
.decoder, .decoder-form, .decoder-results { grid-template-columns: minmax(0, 1fr); }
.decoder { display: grid; gap: 1rem; }

.decoder-form {
  display: grid; gap: 0.75rem;
  padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}

.privacy-badge {
  margin: 0; padding: 0.6rem 0.8rem;
  border-radius: var(--radius); background: var(--ok-bg); color: var(--ok);
}
.privacy-icon { margin-right: 0.4em; }

.decoder-label { font-weight: 600; }

.decoder-input {
  width: 100%; min-height: 10rem; resize: vertical;
  padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  font: 0.85rem/1.45 var(--mono);
}

.dropzone {
  padding: 1rem; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius);
  color: var(--muted);
}
.dropzone p { margin: 0; }
.dropzone.is-over { border-color: var(--accent); background: var(--surface-2); }
.dropzone-file { display: block; margin-top: 0.4rem; color: var(--text); font-weight: 600; overflow-wrap: anywhere; }

.decoder-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.decoder-help summary { cursor: pointer; color: var(--muted); }
.decoder-help ul { margin: 0.5rem 0 0; padding-left: 1.2rem; }

.decoder-status { margin: 0; min-height: 1.6em; color: var(--muted); }
.decoder-status.is-error { color: var(--error); font-weight: 600; }

.decoder-results { display: grid; gap: 1rem; }
.decoder-results:empty { display: none; }
.results-title { margin: 0; }
.results-title:focus { outline: none; }

.facts {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin: 0;
  color: var(--muted); font-size: 0.9rem;
}
.facts div { display: flex; gap: 0.4em; }
.facts dt::after { content: ":"; }
.facts dd { margin: 0; color: var(--text); font-weight: 600; }

.callout {
  padding: 1rem; border-left: 4px solid var(--accent); border-radius: var(--radius);
  background: var(--surface-2);
}
.callout > p:first-child { margin-top: 0; }

.match {
  min-width: 0;
  padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.match.is-top { border-color: var(--accent); border-width: 2px; }
.match-header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.match-header h3 { margin: 0; font-size: 1.15rem; }
.match-lines { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.4rem; }
.match h4 { margin: 1rem 0 0.3rem; }
.fix-steps { padding-left: 1.4rem; }
.fix-steps li + li { margin-top: 0.3rem; }
.more-link { font-weight: 600; }

.match-more > summary {
  cursor: pointer; padding: 0.6rem 0.8rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.match-more[open] > summary { margin-bottom: 0.5rem; }

.badge {
  display: inline-block; padding: 0.15em 0.6em; border-radius: 999px;
  font-size: 0.8rem; font-weight: 700; white-space: nowrap;
}
.badge-high { background: var(--ok-bg); color: var(--ok); }
.badge-medium { background: var(--warn-bg); color: var(--warn); }
.badge-low { background: var(--low-bg); color: var(--low); }

.log {
  margin: 0; padding: 0.6rem 0; overflow-x: auto;
  border-radius: var(--radius); background: var(--log-bg); color: var(--log-text);
  font-size: 0.8rem; line-height: 1.5;
}
.log code { display: block; min-width: max-content; }
.log-line { display: block; padding: 0 0.8rem; white-space: pre; }
.log-line.is-hit { background: var(--log-hit); box-shadow: inset 3px 0 0 var(--accent); }
.log-no {
  display: inline-block; min-width: 4.5ch; margin-right: 1ch;
  color: var(--log-no); text-align: right; user-select: none;
}

.log-file { color: var(--log-no); font-style: italic; user-select: none; }

.callout-action { border-left-color: var(--focus); }
.callout .path { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
.culprit { margin: 0.5rem 0 0; font-weight: 600; }

/* Latent problems: below the blocking cause, never in front of it. */
.latent {
  padding: 1rem; border: 1px solid var(--border); border-left: 4px solid var(--warn); border-radius: var(--radius);
  background: var(--surface);
}
.latent h3 { margin-top: 0; }
.latent-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.75rem; }
.latent-item { min-width: 0; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.latent-item p { margin: 0 0 0.3rem; overflow-wrap: anywhere; }
.latent-rules { color: var(--muted); font-size: 0.9rem; }
.latent-item summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }

.copy-box {
  padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.copy-box h3 { margin-top: 0; }
.checkbox input { width: 1.1rem; height: 1.1rem; vertical-align: -0.15em; }
.copy-feedback { color: var(--ok); font-weight: 600; }
.fine-print { margin-bottom: 0; color: var(--muted); font-size: 0.85rem; }

/* Site and error pages ---------------------------------------------------- */

.skip-link { position: absolute; left: -999px; top: 0; padding: 0.5rem 1rem; background: var(--surface); }
.skip-link:focus { left: 16px; z-index: 10; }

.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.site-header-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; min-height: 56px; }
.site-name { color: var(--text); font-weight: 800; font-size: 1.15rem; text-decoration: none; }
.site-name span { color: var(--accent); }
.site-header nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: center; }
.nav-cta { font-weight: 700; }

.page { padding-top: 1rem; padding-bottom: 2rem; display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); }
.page section { min-width: 0; }
.page h2 { margin: 0 0 0.5rem; font-size: 1.35rem; }
.page h3 { margin: 1rem 0 0.4rem; font-size: 1.05rem; }

.breadcrumb { color: var(--muted); font-size: 0.9rem; }
.error-page { display: grid; gap: 1.75rem; grid-template-columns: minmax(0, 1fr); }
.error-header h1 {
  margin: 0 0 0.75rem; font-family: var(--mono); font-size: clamp(1.15rem, 3.2vw, 1.6rem);
  line-height: 1.35; overflow-wrap: anywhere;
}
.lede { font-size: 1.1rem; margin: 0 0 1rem; }
.error-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin: 1rem 0 0; }

.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.tag {
  display: inline-block; padding: 0.2em 0.65em; border-radius: 999px;
  background: var(--surface-2); color: var(--text); font-size: 0.85rem;
}
.tag-blocking { background: var(--accent); color: var(--accent-text); }
.tag-latent { background: var(--warn-bg); color: var(--warn); }
.tag-lab-validated { background: var(--ok-bg); color: var(--ok); }

.excerpt h3 { margin-top: 1.25rem; }
.excerpt-file { margin: 0.6rem 0 0.25rem; color: var(--muted); font: 0.8rem/1.4 var(--mono); }
.excerpt-note { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.9rem; }
.excerpt-none { margin: 0.4rem 0 0; padding: 0.6rem 0.8rem; border-left: 4px solid var(--warn); background: var(--warn-bg); color: var(--text); }
.log-gap .log-no { color: var(--log-no); }

.faq { border-top: 1px solid var(--border); padding: 0.6rem 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { margin: 0.5rem 0 0; }

.sources li, .error-list li { overflow-wrap: anywhere; }
.error-list { padding-left: 1.2rem; }
.error-list li { margin-bottom: 0.6rem; }
.error-list code { display: block; margin: 0.15rem 0; font-size: 0.8rem; color: var(--muted); }

.decoder-section { padding-top: 1rem; border-top: 2px solid var(--accent); }
/* Decoder at the top (page.decoder_position): the paragraph under "Decode your log" repeats the privacy badge
   and the drop zone of the decoder, right below. */
.decoder-top .decoder-section > p { display: none; }

/* Home page: the decoder comes first. */
.home-header h1 { margin: 0 0 0.5rem; font-size: clamp(1.5rem, 4.5vw, 2.1rem); line-height: 1.2; }
.home-header .lede { margin: 0; }
.home-steps { padding-left: 1.4rem; }
.home-steps li { margin-bottom: 0.5rem; }
/* Signup form (#signup, every page with the decoder). */
.signup { padding: 1rem 1.25rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.signup h2 { margin-top: 0; }
.signup-form { display: grid; gap: 0.5rem; }
.signup-form p { margin: 0; }
.signup-field { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.signup-field label { flex: 1 0 100%; font-weight: 600; }
.signup-field input {
  flex: 1 1 16rem; min-width: 0; padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
.signup-field input[aria-invalid="true"] { border-color: var(--error); }
.signup-consent { display: flex; gap: 0.5rem; align-items: flex-start; }
.signup-consent input { flex: none; margin-top: 0.2rem; }
/* Honeypot: off screen, not display:none (some bots skip hidden fields). */
.signup-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.signup-status, .feedback-status { min-height: 1.5em; color: var(--muted); }
.feedback-status:empty { min-height: 0; margin: 0; }
.feedback-status.is-ok { color: var(--ok); font-weight: 600; }
.signup-status.is-ok { color: var(--ok); font-weight: 600; }
.signup-status.is-error, .feedback-status.is-error { color: var(--error); font-weight: 600; }

/* "Was this the right cause?" in the top cause card, or under "No known pattern found" (feedback.js). */
.feedback { margin: 1rem 0; padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.feedback h3, .match .feedback h3 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.feedback p { margin: 0.4rem 0; }
.feedback-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.feedback-buttons .button { gap: 0.4em; }
.feedback .feedback-privacy { margin: 0.6rem 0 0; font-size: 0.8rem; }
.feedback-more { display: grid; gap: 0.3rem; }
.feedback-more[hidden] { display: none; }
.feedback-more label { font-weight: 600; }
.feedback-cause {
  width: 100%; padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; resize: vertical;
}

/* Legal and status pages. */
.legal, .status-page { max-width: 46rem; }
.legal h1, .status-page h1 { margin: 0 0 0.5rem; }
.legal section { margin-top: 1.5rem; }
.legal-facts { margin: 0; display: grid; gap: 0.5rem; }
.legal-facts div { display: grid; grid-template-columns: minmax(8rem, 12rem) minmax(0, 1fr); gap: 0.75rem; }
.legal-facts dt { font-weight: 600; }
.legal-facts dd { margin: 0; }
/* Information still to fill in (legal drafts): impossible to miss. */
.placeholder {
  background: var(--warn-bg); color: var(--warn); border: 1px dashed var(--warn); border-radius: 3px;
  padding: 0 0.15em; margin: 0 0.05em; font-family: var(--mono); font-size: 0.85em; -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.error-reasons { padding-left: 1.2rem; }

/* Admin (backend pages). */
.admin-table { border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 0.3rem 0.8rem 0.3rem 0; text-align: left; border-bottom: 1px solid var(--border); }
.form-error { color: var(--error); font-weight: 600; }
.admin-scroll { overflow-x: auto; }
.admin-review { padding-left: 1.2rem; }
.admin-review li { margin: 0 0 1.25rem; }
.admin-meta { margin: 0 0 0.3rem; font-size: 0.9rem; color: var(--muted); }
/* Visitor text, escaped: line breaks kept, long words wrapped. */
.admin-cause { margin: 0 0 0.5rem; padding: 0.5rem 0.75rem; border-left: 3px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-review-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; }
.admin-review-form input[type="text"] { flex: 1 1 14rem; min-width: 0; }

.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; padding: 1rem 0 2rem; }
.site-footer p { margin: 0.3rem 0; }

@media (max-width: 600px) {
  .decoder-form, .match, .copy-box, .callout, .latent { padding: 0.75rem; }
  .decoder-actions .button { flex: 1 1 auto; }
  .signup { padding: 0.75rem; }
  .legal-facts div { grid-template-columns: minmax(0, 1fr); gap: 0.1rem; }
  .page { padding-top: 0.75rem; gap: 1.25rem; }
  .home-header .lede { font-size: 1rem; }
  /* Decoder at the top: a tighter introduction keeps the text area on the first screen. */
  .decoder-top .error-header .lede { font-size: 1rem; line-height: 1.5; margin-bottom: 0.75rem; }
  .decoder-top .decoder-section { padding-top: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
