/* CounterLab
   Direction: squared exercise paper + instrument readout.
   The student's world is graph paper, a ruler and a cheap printed lab sheet, so
   the page is built from those materials. Data (variables, units, counts) is set
   in mono because it IS data; prose is set in Space Grotesk.
   Severity deliberately avoids traffic-light: alarm is magenta, commit is teal. */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --paper:      #EFF2F1;
  --paper-2:    #FFFFFF;
  --grid:       rgba(24, 54, 74, .055);
  --grid-bold:  rgba(24, 54, 74, .10);
  --ink:        #11161B;
  --ink-2:      #47555F;
  --ink-3:      #7E8C96;
  --rule:       #D3DBD9;

  --break:      #D81B54;
  --repair:     #A8720E;
  --commit:     #0B6E6C;
  --pass:       #16714A;
  --link:       #2050C8;

  --break-wash:  rgba(216, 27, 84, .07);
  --repair-wash: rgba(168, 114, 14, .07);
  --commit-wash: rgba(11, 110, 108, .07);

  --display: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --r: 3px;
  --shadow: 0 1px 0 rgba(20,40,60,.05), 0 6px 22px -14px rgba(20,40,60,.35);
}

/* Dark tokens live in one place and are applied by either the OS preference or
   an explicit choice. The explicit choice must win in both directions, so the
   attribute selectors come after the media query. */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0D1116;  --paper-2: #141A21;
    --grid: rgba(150, 200, 230, .045); --grid-bold: rgba(150, 200, 230, .085);
    --ink: #E9EFF2;   --ink-2: #A2B0BA;  --ink-3: #6E7E8A;  --rule: #263039;
    --break: #FF5C86;  --repair: #E3A63C;  --commit: #35C4B6;
    --pass: #3ECF8E;   --link: #77A9FF;
    --break-wash: rgba(255,92,134,.10); --repair-wash: rgba(227,166,60,.10);
    --commit-wash: rgba(53,196,182,.10);
    --shadow: 0 1px 0 rgba(0,0,0,.3), 0 8px 26px -16px rgba(0,0,0,.9);
  }
}

:root[data-theme="dark"] {
  --paper: #0D1116;  --paper-2: #141A21;
  --grid: rgba(150, 200, 230, .045); --grid-bold: rgba(150, 200, 230, .085);
  --ink: #E9EFF2;   --ink-2: #A2B0BA;  --ink-3: #6E7E8A;  --rule: #263039;
  --break: #FF5C86;  --repair: #E3A63C;  --commit: #35C4B6;
  --pass: #3ECF8E;   --link: #77A9FF;
  --break-wash: rgba(255,92,134,.10); --repair-wash: rgba(227,166,60,.10);
  --commit-wash: rgba(53,196,182,.10);
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 8px 26px -16px rgba(0,0,0,.9);
}

:root[data-theme="light"] {
  --paper: #EFF2F1;  --paper-2: #FFFFFF;
  --grid: rgba(24, 54, 74, .055); --grid-bold: rgba(24, 54, 74, .10);
  --ink: #11161B;   --ink-2: #47555F;  --ink-3: #7E8C96;  --rule: #D3DBD9;
  --break: #D81B54;  --repair: #A8720E;  --commit: #0B6E6C;
  --pass: #16714A;   --link: #2050C8;
  --break-wash: rgba(216,27,84,.07); --repair-wash: rgba(168,114,14,.07);
  --commit-wash: rgba(11,110,108,.07);
  --shadow: 0 1px 0 rgba(20,40,60,.05), 0 6px 22px -14px rgba(20,40,60,.35);
}

.theme {
  background: none; border: 1px solid var(--rule); border-radius: 999px;
  width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer;
  color: var(--ink-2); padding: 0; flex: none;
  transition: border-color .14s, color .14s;
}
.theme:hover { border-color: var(--ink); color: var(--ink); }
.theme svg { width: 15px; height: 15px; }
.theme .moon { display: none; }
:root[data-theme="dark"] .theme .sun,
:root:not([data-theme="light"]) .theme .sun { display: block; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theme .sun { display: none; } }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theme .moon { display: block; } }
:root[data-theme="dark"] .theme .sun { display: none; }
:root[data-theme="dark"] .theme .moon { display: block; }
:root[data-theme="light"] .theme .sun { display: block; }
:root[data-theme="light"] .theme .moon { display: none; }

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--display);
  font-size: 17px;
  line-height: 1.58;
  -webkit-text-size-adjust: 100%;
  background-color: var(--paper);
  /* squared exercise paper: 5mm minor, 25mm major */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(var(--grid-bold) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-bold) 1px, transparent 1px);
  background-size: 22px 22px, 22px 22px, 110px 110px, 110px 110px;
}

.wrap { max-width: 780px; margin: 0 auto; padding: 30px 20px 90px; }

::selection { background: var(--break); color: #fff; }

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------------- masthead ---------------- */

.mast {
  display: flex; align-items: center; gap: 11px; flex-wrap: wrap;
  padding-bottom: 13px; margin-bottom: 26px;
  border-bottom: 1.5px solid var(--ink);
}
.logo {
  font-family: var(--mono); font-weight: 600; font-size: 15px;
  letter-spacing: .015em; text-decoration: none; color: var(--ink);
}
.logo i { font-style: normal; color: var(--break); }
.mast .gap { flex: 1 1 auto; }

.tick {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase;
  padding: 3px 8px; border: 1px solid var(--rule); border-radius: 999px;
  color: var(--ink-3); white-space: nowrap; background: var(--paper-2);
}
.tick.on   { color: var(--commit); border-color: color-mix(in srgb, var(--commit) 45%, transparent); }
.tick.warn { color: var(--repair); border-color: color-mix(in srgb, var(--repair) 50%, transparent); }
.tick.det  { color: var(--link);   border-color: color-mix(in srgb, var(--link) 40%, transparent); }
.tick.dot::before {
  content: ''; display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; margin-right: 6px; vertical-align: 1px;
}

/* ---------------- hero ---------------- */

h1 {
  font-size: clamp(30px, 6.4vw, 50px);
  line-height: 1.02; letter-spacing: -.035em; font-weight: 700;
  margin: 0 0 16px; text-wrap: balance;
}
h1 mark {
  background: none; color: var(--break);
  /* the word that carries the whole thesis gets underlined like a marked-up script */
  box-shadow: inset 0 -.11em 0 color-mix(in srgb, var(--break) 30%, transparent);
}
.lede { color: var(--ink-2); margin: 0; max-width: 54ch; font-size: 17.5px; }
.lede b { color: var(--ink); font-weight: 500; }

/* the pendulum case, set as a specimen card - the hero IS the problem */
.specimen {
  margin: 24px 0 6px; background: var(--paper-2);
  border: 1px solid var(--rule); border-left: 3px solid var(--break);
  border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow);
}
.specimen .stamp {
  font-family: var(--mono); font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--break); font-weight: 600; margin-bottom: 9px;
}
.specimen p { margin: 0 0 8px; font-size: 15.5px; line-height: 1.5; }
.specimen p:last-child { margin-bottom: 0; }
.specimen .q { font-family: var(--mono); font-size: 14px; color: var(--ink-2); }
.specimen .q b { color: var(--ink); font-weight: 500; }

/* ---------------- fixtures ---------------- */

.fixhead {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .15em;
  text-transform: uppercase; color: var(--ink-3); margin: 34px 0 10px;
  display: flex; align-items: center; gap: 10px;
}
.fixhead::after { content: ''; flex: 1; height: 1px; background: var(--rule); }

.fixrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 9px; }
.fix {
  text-align: left; background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: var(--r); padding: 11px 13px; cursor: pointer;
  font-family: inherit; color: var(--ink); position: relative;
  transition: border-color .14s, transform .14s, box-shadow .14s;
}
.fix:hover { border-color: var(--ink); transform: translateY(-2px); box-shadow: var(--shadow); }
.fix[aria-pressed="true"] { border-color: var(--link); box-shadow: inset 0 0 0 1px var(--link); }
.fix .n {
  font-family: var(--mono); font-size: 10px; color: var(--ink-3);
  letter-spacing: .1em; display: block; margin-bottom: 3px;
}
.fix .t { font-weight: 500; font-size: 15px; display: block; letter-spacing: -.01em; }
.fix .d { font-family: var(--mono); font-size: 11px; color: var(--ink-3); display: block; margin-top: 2px; }

/* ---------------- form ---------------- */

form { margin-top: 26px; }
.field { margin-bottom: 17px; }
label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; }
label .hint { color: var(--ink-3); font-weight: 400; }

textarea, select {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: var(--r); padding: 11px 13px; resize: vertical;
  transition: border-color .14s;
}
textarea::placeholder { color: var(--ink-3); }
textarea:hover, select:hover { border-color: var(--ink-3); }
textarea:focus, select:focus { border-color: var(--link); }

.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.go {
  width: 100%; margin-top: 6px; padding: 15px; cursor: pointer;
  font: 600 17px/1 var(--display); letter-spacing: -.01em;
  color: var(--paper-2); background: var(--ink);
  border: 0; border-radius: var(--r);
  transition: transform .12s, opacity .14s;
}
.go:hover { transform: translateY(-1px); }
.go:active { transform: translateY(0); }
.go:disabled { opacity: .55; cursor: progress; transform: none; }

.alert {
  background: var(--break-wash); border: 1px solid color-mix(in srgb, var(--break) 40%, transparent);
  border-radius: var(--r); padding: 11px 14px; font-size: 15px; margin-bottom: 18px;
}

/* ---------------- verdict ---------------- */

.verdict {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 15px 18px; border-radius: var(--r); margin-bottom: 22px;
  background: var(--paper-2); border: 1px solid var(--rule);
  border-left: 3px solid var(--ink-3); box-shadow: var(--shadow);
}
.verdict .v {
  font-family: var(--mono); font-weight: 600; font-size: 14px;
  letter-spacing: .07em; text-transform: uppercase;
}
.verdict .gap { flex: 1 1 auto; }
.verdict.bad  { border-left-color: var(--break); }
.verdict.bad .v { color: var(--break); }
.verdict.good { border-left-color: var(--pass); }
.verdict.good .v { color: var(--pass); }
.verdict.stop { border-left-color: var(--repair); }
.verdict.stop .v { color: var(--repair); }

.notice {
  background: var(--repair-wash); border: 1px solid color-mix(in srgb, var(--repair) 35%, transparent);
  border-radius: var(--r); padding: 12px 15px; font-size: 14.5px; margin-bottom: 20px; color: var(--ink-2);
}
.notice b { color: var(--repair); }

/* ---------------- act cards ---------------- */

.act {
  background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: var(--r); padding: 20px 22px; margin-bottom: 15px;
  box-shadow: var(--shadow); position: relative;
}
.act > h2 {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: .17em; text-transform: uppercase; margin: 0 0 14px;
  display: flex; align-items: center; gap: 9px; color: var(--ink-3);
}
.act > h2 .step {
  width: 19px; height: 19px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; color: var(--paper-2); flex: none;
}
.act > h2::after { content: ''; flex: 1; height: 1px; background: var(--rule); }
.act.brk    { border-top: 2px solid var(--break); }
.act.brk    > h2 { color: var(--break); }  .act.brk    > h2 .step { background: var(--break); }
/* On a pass there is nothing broken, so the alarm colour would be lying. */
.act.brk.ok { border-top-color: var(--pass); }
.act.brk.ok > h2 { color: var(--pass); }   .act.brk.ok > h2 .step { background: var(--pass); }
.act.rep    { border-top: 2px solid var(--repair); }
.act.rep    > h2 { color: var(--repair); } .act.rep    > h2 .step { background: var(--repair); }
.act.com    { border-top: 2px solid var(--commit); }
.act.com    > h2 { color: var(--commit); } .act.com    > h2 .step { background: var(--commit); }
.act.deep   { border-top: 2px solid var(--link); }
.act.deep   > h2 { color: var(--link); }   .act.deep   > h2 .step { background: var(--link); }

.claim {
  font-size: clamp(19px, 3.4vw, 24px); font-weight: 500; line-height: 1.28;
  letter-spacing: -.02em; margin: 0 0 13px; text-wrap: pretty;
}
.because { color: var(--ink-2); margin: 0; font-size: 15.5px; }
.because .k {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .13em;
  text-transform: uppercase; color: var(--ink-3); display: block; margin-bottom: 4px;
}

/* ---------------- SIGNATURE: the readout ---------------- */

.readout {
  margin-top: 18px; border: 1px solid var(--rule); border-radius: var(--r);
  overflow: hidden; background: var(--paper);
}
.readout .rhead {
  display: flex; align-items: center; gap: 8px; padding: 8px 13px;
  border-bottom: 1px solid var(--rule); background: var(--paper-2);
  font-family: var(--mono); font-size: 10px; letter-spacing: .15em;
  text-transform: uppercase; color: var(--ink-3);
}
.slot {
  display: grid; grid-template-columns: 132px 1fr auto; gap: 12px; align-items: baseline;
  padding: 10px 13px; border-bottom: 1px solid var(--rule);
  font-size: 15px; position: relative;
}
.slot:last-child { border-bottom: 0; }
.slot .k {
  font-family: var(--mono); font-size: 11px; letter-spacing: .05em;
  color: var(--ink-3); text-transform: uppercase;
}
.slot .val { min-width: 0; overflow-wrap: anywhere; }
.slot .val.empty { color: var(--ink-3); font-style: italic; }
.slot .tag {
  font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; padding: 2px 7px; border-radius: 999px;
  border: 1px solid currentColor; white-space: nowrap; opacity: .85;
}
.slot .tag.ok    { color: var(--ink-3); }
.slot .tag.miss  { color: var(--repair); }
.slot .tag.bad   { color: var(--break); }
.slot.flag { background: var(--break-wash); }
.slot.flag .val { color: var(--break); font-weight: 500; }
.slot.flag::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--break);
}

/* ---------------- repairs ---------------- */

ol.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
ol.steps li {
  counter-increment: s; position: relative; padding-left: 34px; margin-bottom: 11px;
  font-size: 15.5px;
}
ol.steps li::before {
  content: counter(s, decimal-leading-zero);
  position: absolute; left: 0; top: 1px;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  color: var(--repair); letter-spacing: .04em;
}

.falsify {
  margin-top: 17px; padding: 14px 16px; border-radius: var(--r);
  background: var(--repair-wash); border: 1px dashed color-mix(in srgb, var(--repair) 42%, transparent);
}
.k {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .13em;
  text-transform: uppercase; color: var(--ink-3); display: block; margin-bottom: 5px; font-weight: 500;
}

/* ---------------- pre-registration card ---------------- */

.card { border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; margin-top: 4px; }
.card .row { display: grid; grid-template-columns: 118px 1fr; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--rule); font-size: 15px; }
.card .row:last-of-type { border-bottom: 0; }
.card .row .k { margin: 0; }
.card .row .n { font-family: var(--mono); font-weight: 600; }

.reject {
  background: var(--commit-wash); padding: 15px 16px;
  border-top: 1px solid color-mix(in srgb, var(--commit) 35%, transparent);
}
.reject .k { color: var(--commit); }
.reject .txt { font-size: 16.5px; line-height: 1.42; }
.sign {
  display: flex; gap: 22px; padding: 13px 14px; border-top: 1px dashed var(--rule);
  font-family: var(--mono); font-size: 11px; color: var(--ink-3); flex-wrap: wrap;
}
.sign span { flex: 1 1 120px; border-bottom: 1px solid var(--rule); padding-bottom: 3px; }

.btnrow { display: flex; gap: 8px; margin-top: 15px; flex-wrap: wrap; }
.btn {
  background: transparent; border: 1px solid var(--rule); color: var(--ink);
  border-radius: var(--r); padding: 9px 15px; cursor: pointer;
  font: 500 14px var(--display); transition: border-color .14s, background .14s;
}
.btn:hover { border-color: var(--ink); background: var(--paper); }
.btn.primary { background: var(--link); border-color: var(--link); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); background: var(--link); }
.btn[disabled] { opacity: .5; cursor: progress; }

/* ---------------- findings ---------------- */

details {
  background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: var(--r); margin-bottom: 11px; box-shadow: var(--shadow);
}
details > summary {
  cursor: pointer; padding: 13px 18px; font-size: 15px; font-weight: 500;
  list-style: none; display: flex; align-items: center; gap: 9px;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: '+'; font-family: var(--mono); color: var(--ink-3); font-size: 15px;
  width: 12px; flex: none;
}
details[open] > summary::before { content: '\2212'; }
details > summary:hover { color: var(--link); }
details .body { padding: 0 18px 15px; }
details ul { margin: 0; padding-left: 19px; color: var(--ink-2); font-size: 15px; }
details li { margin-bottom: 7px; }

.find { padding: 12px 0; border-top: 1px solid var(--rule); }
.find:first-child { border-top: 0; padding-top: 2px; }
.find .t { font-weight: 500; font-size: 15.5px; margin-bottom: 3px; }
.find .r { color: var(--ink-2); font-size: 14.5px; }
.find .meta { display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap; }
.sev {
  font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; padding: 2px 7px; border-radius: 999px;
  border: 1px solid currentColor; color: var(--ink-3);
}
.sev.fatal { color: var(--break); }
.sev.major { color: var(--repair); }

.lens { margin-bottom: 20px; }
.lens > .h {
  font-weight: 600; font-size: 16px; letter-spacing: -.01em; margin-bottom: 3px;
  display: flex; align-items: baseline; gap: 9px;
}
.lens > .h .n { font-family: var(--mono); font-size: 11px; color: var(--link); }
.lens > .sum { color: var(--ink-2); font-size: 14.5px; margin-bottom: 9px; }

.src { display: block; padding: 11px 0; border-top: 1px solid var(--rule); text-decoration: none; color: inherit; }
.src:first-of-type { border-top: 0; }
.src .t { color: var(--link); font-weight: 500; font-size: 15px; }
.src:hover .t { text-decoration: underline; }
.src .s { color: var(--ink-2); font-size: 13.5px; margin-top: 2px; }
.src .o { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }

/* ---------------- chrome ---------------- */

.back {
  display: inline-flex; align-items: center; gap: 7px; margin-bottom: 20px;
  font-family: var(--mono); font-size: 12px; letter-spacing: .04em;
  color: var(--ink-2); text-decoration: none;
}
.back:hover { color: var(--link); }

footer {
  margin-top: 42px; padding-top: 20px; border-top: 1px solid var(--rule);
  color: var(--ink-3); font-size: 13.5px;
}
footer p { margin: 0 0 8px; }
footer b { color: var(--ink-2); }
footer a { color: var(--ink-2); }

/* ---------------- loading ---------------- */

#load {
  position: fixed; inset: 0; z-index: 60; display: none;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  align-items: center; justify-content: center; backdrop-filter: blur(2px);
}
#load.on { display: flex; }
#load .box { text-align: center; padding: 26px; max-width: 340px; }
.bar { height: 2px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-bottom: 20px; }
.bar i { display: block; height: 100%; width: 30%; background: var(--break); animation: sweep 1.15s ease-in-out infinite; }
@keyframes sweep { 0% { transform: translateX(-110%); } 100% { transform: translateX(370%); } }
#stage {
  font-family: var(--mono); font-size: 13px; color: var(--ink-2);
  letter-spacing: .03em; min-height: 40px;
}

/* ---------------- orchestrated entrance ---------------- */

@keyframes rise { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }
.rise { animation: rise .42s cubic-bezier(.2,.7,.3,1) both; }
.rise-1 { animation-delay: .04s; } .rise-2 { animation-delay: .12s; }
.rise-3 { animation-delay: .20s; } .rise-4 { animation-delay: .28s; }
.rise-5 { animation-delay: .36s; }
.slot { animation: rise .34s cubic-bezier(.2,.7,.3,1) both; }
.slot:nth-child(2){animation-delay:.30s} .slot:nth-child(3){animation-delay:.36s}
.slot:nth-child(4){animation-delay:.42s} .slot:nth-child(5){animation-delay:.48s}
.slot:nth-child(6){animation-delay:.54s}

@media (prefers-reduced-motion: reduce) {
  .rise, .slot { animation: none !important; }
  .bar i { animation: none; width: 100%; }
  .fix:hover, .go:hover { transform: none; }
}

@media (max-width: 560px) {
  .slot { grid-template-columns: 1fr auto; row-gap: 3px; }
  .slot .k { grid-column: 1 / -1; }
  .card .row { grid-template-columns: 1fr; gap: 3px; }
  /* keep the masthead on one line instead of orphaning the theme button */
  .mast { gap: 7px; }
  .tick { font-size: 9.5px; padding: 2px 6px; letter-spacing: .07em; }
  .theme { width: 27px; height: 27px; }
  .act { padding: 17px 15px; }
  .wrap { padding: 22px 15px 70px; }
}

@media print {
  body { background: #fff; color: #000; }
  #load, .btnrow, form, .fixrow, .fixhead, .back, .act.deep, .specimen { display: none; }
  .act { break-inside: avoid; box-shadow: none; border: 1px solid #999; }
}
