/* Experiment 001 — a controlled experiment recorded in a lab notebook.
   Palette, type and structure all derive from that one object:
   notebook stock + graph grid + red margin rule; litmus acid/alkaline as the
   only two accents, because the duality is the experiment's own. */

:root {
  --paper:      #EDEFE9;   /* notebook stock, cool not cream */
  --paper-deep: #E4E7E0;   /* recessed panels */
  --grid:       #CDD5CC;   /* graph rule */
  --graphite:   #1B2021;   /* pencil / display type */
  --pencil:     #6B7472;   /* annotation grey */
  --margin-red: #A32E22;   /* the notebook's margin rule */

  --acid:     #A32E22;     /* NEGATIVE — litmus acid */
  --alkaline: #12626B;     /* POSITIVE — litmus alkaline */

  --display: "Instrument Serif", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --rule: 1px solid var(--grid);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background-color: var(--paper);
  /* the graph grid — the page's structural device, not decoration */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px, 28px 28px;
  background-position: -1px -1px, -1px -1px;
  color: var(--graphite);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
}

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

/* The sheet: a notebook page with a real margin rule down the left. */
.sheet {
  max-width: 1180px;
  margin: 0 auto;
  padding: 3.5rem 2rem 3rem 4.25rem;
  position: relative;
}
.sheet::before {
  content: "";
  position: absolute;
  left: 2.75rem; top: 0; bottom: 0;
  width: 1px;
  background: var(--margin-red);
  opacity: .55;
}

/* ─── Head ─────────────────────────────────────────────────────────────── */

.ledger-head {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 2.5rem;
  align-items: end;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--graphite);
}

.folio {
  margin: 0 0 .9rem;
  font-size: .7rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--margin-red);
}

.ledger-head h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.9rem, 7vw, 5rem);
  line-height: .92;
  letter-spacing: -.015em;
}
.ledger-head h1 em { font-style: italic; color: var(--pencil); }

.head-meta { margin: 0; display: grid; gap: .7rem; }
.head-meta > div {
  display: grid;
  grid-template-columns: 5.6rem 1fr;
  gap: .75rem;
  align-items: start;
  padding-bottom: .55rem;
  border-bottom: var(--rule);
}
.head-meta dt {
  font-size: .64rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--pencil); padding-top: .15rem;
}
.head-meta dd { margin: 0; font-size: .76rem; line-height: 1.4; }

/* ─── Section rubrics ──────────────────────────────────────────────────── */

.rubric {
  display: flex; align-items: baseline; gap: .8rem;
  margin: 3rem 0 1.25rem;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.5rem;
  letter-spacing: .01em;
}
.rubric span {
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .14em;
  color: var(--margin-red);
  border: 1px solid currentColor;
  padding: .18rem .4rem;
  border-radius: 2px;
}

/* ─── Specimen charge (the input) ──────────────────────────────────────── */

.charge-form { display: flex; align-items: flex-end; gap: 1.25rem; flex-wrap: wrap; }

#text-input {
  flex: 1 1 24rem;
  min-width: 0;
  background: transparent;
  border: 0;
  border-bottom: 1.5px solid var(--graphite);
  padding: .55rem .2rem;
  font-family: var(--display);
  font-size: clamp(1.15rem, 2.4vw, 1.6rem);
  color: var(--graphite);
  border-radius: 0;
}
#text-input::placeholder { color: var(--pencil); opacity: .65; font-style: italic; }
#text-input:focus { outline: 0; border-bottom-color: var(--margin-red); }

/* Button reads as a stamped instruction, not a rounded CTA pill. */
#analyze-btn {
  position: relative;
  background: transparent;
  border: 1.5px solid var(--graphite);
  padding: .7rem 1.5rem;
  font-family: var(--mono);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--graphite);
  cursor: pointer;
  overflow: hidden;
}
#analyze-btn .btn-rule {
  position: absolute; inset: 0;
  background: var(--graphite);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .28s cubic-bezier(.6,.05,.2,1);
  z-index: 0;
}
#analyze-btn .btn-label { position: relative; z-index: 1; transition: color .2s .06s; }
#analyze-btn:hover:not(:disabled) .btn-rule { transform: scaleX(1); }
#analyze-btn:hover:not(:disabled) .btn-label { color: var(--paper); }
#analyze-btn:disabled { color: var(--pencil); border-color: var(--grid); cursor: progress; }

.charge-note {
  margin: 1rem 0 0;
  font-size: .72rem;
  color: var(--pencil);
  max-width: 46ch;
}

/* ─── The bench: three specimen columns ────────────────────────────────── */

.specimens {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-top: 1px solid var(--graphite);
}

/* Ruled lanes, sharing hairlines — a notebook table, not three floating cards. */
.specimen {
  position: relative;
  padding: 2.4rem 1.5rem 1.5rem;
  border-right: var(--rule);
  border-bottom: 1px solid var(--graphite);
  display: flex;
  flex-direction: column;
}
.specimen:first-child { padding-left: 0; }
.specimen:last-child  { border-right: 0; padding-right: 0; }

/* Hanging tube label, like a taped-on specimen tag. */
.tube-label {
  position: absolute;
  top: 0; left: 1.5rem;
  transform: translateY(-50%);
  display: flex; align-items: stretch;
  background: var(--paper);
  border: 1px solid var(--graphite);
  font-size: .62rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.specimen:first-child .tube-label { left: 0; }
.tube-letter {
  background: var(--graphite); color: var(--paper);
  padding: .22rem .5rem; font-weight: 600;
}
.tube-var { padding: .22rem .6rem; color: var(--pencil); }

.specimen h3 {
  margin: 0 0 1rem;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.6rem;
  line-height: 1.05;
  letter-spacing: -.01em;
}

.spec-meta { margin: 0 0 1.6rem; display: grid; gap: .3rem; }
.spec-meta > div {
  display: grid; grid-template-columns: 5.2rem 1fr; gap: .5rem;
  align-items: baseline;
}
.spec-meta dt {
  font-size: .6rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--pencil); line-height: 1.35;
}
.spec-meta dd { margin: 0; font-size: .68rem; line-height: 1.35; }

/* ─── The reading ──────────────────────────────────────────────────────── */

.reading {
  flex: 1;
  min-height: 8.5rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: 1rem;
}

.idle, .running {
  margin: 0;
  font-size: .7rem;
  color: var(--pencil);
  font-style: italic;
}
.running::after {
  content: "";
  display: inline-block;
  width: 1.6em;
  text-align: left;
  animation: dots 1.1s steps(4, end) infinite;
}
@keyframes dots { 0%{content:""} 25%{content:"."} 50%{content:".."} 75%{content:"..."} }

/* Verdict: large display type, colour carries the acid/alkaline reading. */
.verdict {
  font-family: var(--display);
  font-size: clamp(2rem, 4.6vw, 2.9rem);
  line-height: 1;
  letter-spacing: -.01em;
  margin: 0 0 .55rem;
  display: flex;
  flex-wrap: wrap;
}
.verdict .ch {
  display: inline-block;
  opacity: 0;
  transform: translateY(.32em);
  animation: settle .42s cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes settle { to { opacity: 1; transform: none; } }
.verdict.POSITIVE { color: var(--alkaline); }
.verdict.NEGATIVE { color: var(--acid); }

.figure {
  font-size: .72rem;
  color: var(--pencil);
  margin: 0 0 .7rem;
  font-variant-numeric: tabular-nums;
}
.figure b { color: var(--graphite); font-weight: 600; }

/* Titration strip — fills like an indicator, not a progress bar. */
.strip {
  height: 10px;
  border: 1px solid var(--graphite);
  position: relative;
  overflow: hidden;
  background:
    repeating-linear-gradient(90deg, var(--grid) 0 1px, transparent 1px 14px);
}
.strip i {
  position: absolute; inset: 0 auto 0 0;
  width: 0;
  transition: width .85s cubic-bezier(.25,.8,.3,1);
}
.strip i.POSITIVE { background: var(--alkaline); }
.strip i.NEGATIVE { background: var(--acid); }

.fault {
  margin: 0;
  font-size: .68rem;
  color: var(--acid);
  word-break: break-word;
}

.elapsed {
  margin: 0;
  padding-top: .8rem;
  border-top: var(--rule);
  font-size: .66rem;
  letter-spacing: .04em;
  color: var(--pencil);
  min-height: 2.1em;
  font-variant-numeric: tabular-nums;
}
.elapsed b { color: var(--graphite); font-weight: 600; font-size: .8rem; }

/* Rubber-stamped, slightly askew — a notebook annotation. */
.stamp {
  display: inline-block;
  margin-left: .5rem;
  padding: .1rem .4rem;
  border: 1.5px solid var(--margin-red);
  color: var(--margin-red);
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  transform: rotate(-4deg) scale(1.5);
  opacity: 0;
  animation: stamp .34s cubic-bezier(.2,1.3,.4,1) .1s forwards;
}
@keyframes stamp { to { opacity: 1; transform: rotate(-4deg) scale(1); } }

/* ─── The record card — the signature element ──────────────────────────── */

.record-card {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper-deep);
  border: 1px solid var(--graphite);
}
.record-card th, .record-card td {
  text-align: left;
  vertical-align: top;
  padding: .85rem 1.1rem;
  border-bottom: var(--rule);
  font-size: .76rem;
  font-weight: 400;
}
.record-card tr:last-child th, .record-card tr:last-child td { border-bottom: 0; }
.record-card th {
  width: 8.5rem;
  font-size: .62rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--pencil);
  border-right: var(--rule);
}
.rec-observation td { font-variant-numeric: tabular-nums; }
.pending-dash { color: var(--pencil); }
.rec-value { transition: opacity .3s; }

.colophon {
  display: flex; gap: .6rem; flex-wrap: wrap;
  margin-top: 2.5rem; padding-top: 1rem;
  border-top: var(--rule);
  font-size: .64rem;
  letter-spacing: .06em;
  color: var(--pencil);
}
.colophon code { font-size: 1em; color: var(--graphite); }

/* ─── Narrow ───────────────────────────────────────────────────────────── */

@media (max-width: 880px) {
  .sheet { padding: 2.5rem 1.25rem 2rem 2.5rem; }
  .sheet::before { left: 1.25rem; }
  .ledger-head { grid-template-columns: 1fr; gap: 1.75rem; align-items: start; }
  .specimens { grid-template-columns: 1fr; }
  .specimen { padding: 2.4rem 0 1.5rem; border-right: 0; }
  .specimen .tube-label { left: 0; }
  .record-card th { width: 6.5rem; }
}

/* ─── Reduced motion ───────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important;
      transition-duration: .001ms !important; }
  .verdict .ch { opacity: 1; transform: none; }
  .stamp { opacity: 1; transform: rotate(-4deg); }
}
