:root {
  --paper:       #EDEFE8;
  --sheet:       #F8F9F4;
  --sheet-band:  #E3E7DE;
  --ink:         #1B2724;
  --ink-soft:    #57655F;
  --rule:        #BFC8BF;
  --rule-strong: #8B978F;
  --stamp:       #B93A2E;
  --tint:        #3F5C52;
  --field-bg:    rgba(63, 92, 82, 0.05);

  --f-display: "Archivo Narrow", "Arial Narrow", Helvetica, sans-serif;
  --f-body:    "Public Sans", -apple-system, "Segoe UI", Helvetica, sans-serif;
  --f-mono:    "Courier Prime", "Courier New", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:       #101513;
    --sheet:       #1A211E;
    --sheet-band:  #222B27;
    --ink:         #E5EAE4;
    --ink-soft:    #9BAAA3;
    --rule:        #35413B;
    --rule-strong: #566761;
    --stamp:       #E4685B;
    --tint:        #93B7A9;
    --field-bg:    rgba(147, 183, 169, 0.07);
  }
}

:root[data-theme="dark"] {
  --paper:       #101513;
  --sheet:       #1A211E;
  --sheet-band:  #222B27;
  --ink:         #E5EAE4;
  --ink-soft:    #9BAAA3;
  --rule:        #35413B;
  --rule-strong: #566761;
  --stamp:       #E4685B;
  --tint:        #93B7A9;
  --field-bg:    rgba(147, 183, 169, 0.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: clamp(16px, 4vw, 56px) clamp(12px, 4vw, 32px) clamp(40px, 8vw, 90px);
  background-color: var(--paper);
  background-image: repeating-linear-gradient(45deg, transparent 0 9px, var(--rule) 9px 10px);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--paper);
  opacity: 0.94;
  pointer-events: none;
  z-index: 0;
}

.stack {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 4vw, 32px);
}

.sheet {
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  box-shadow: 0 1px 0 var(--rule), 0 18px 40px -28px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

/* ---------- masthead ---------- */
.band {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(18px, 4vw, 28px) clamp(18px, 4vw, 34px) 14px;
  background: var(--sheet-band);
  border-bottom: 3px double var(--rule-strong);
}
.band h1 {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: clamp(26px, 5.4vw, 40px);
  letter-spacing: 0.01em;
  line-height: 1.05;
  text-transform: uppercase;
  text-wrap: balance;
}
.eyebrow {
  display: block;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--tint);
  margin-bottom: 6px;
}
.stampcode {
  font-family: var(--f-mono);
  font-size: 11px;
  line-height: 1.7;
  text-align: right;
  color: var(--ink-soft);
  white-space: nowrap;
}
.stampcode b { color: var(--ink); font-weight: 700; }

.preamble {
  padding: 14px clamp(18px, 4vw, 34px) 0;
  font-size: 14px;
  color: var(--ink-soft);
  max-width: 62ch;
}

/* ---------- counters ---------- */
.counters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--rule);
}
.counters div {
  padding: 14px clamp(10px, 2vw, 18px) 16px;
  border-right: 1px dotted var(--rule);
}
.counters div:last-child { border-right: 0; }
.counters .n {
  display: block;
  font-family: var(--f-mono);
  font-weight: 700;
  font-size: clamp(20px, 4.4vw, 30px);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.counters .k {
  display: block;
  font-family: var(--f-mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tint);
  margin-top: 4px;
}
.counters .zero .n { color: var(--stamp); }
@media (max-width: 520px) {
  .counters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .counters div:nth-child(2) { border-right: 0; }
  .counters div:nth-child(-n+2) { border-bottom: 1px dotted var(--rule); }
}

/* ---------- form ---------- */
form { padding: clamp(16px, 4vw, 28px) clamp(18px, 4vw, 34px) 8px; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 26px; }
.full { grid-column: 1 / -1; }
@media (max-width: 560px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.label {
  font-family: var(--f-mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tint);
}
.label .no { color: var(--ink-soft); font-weight: 400; }

input[type="text"], select, textarea {
  width: 100%;
  font-family: var(--f-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--field-bg);
  border: 0;
  border-bottom: 1.5px solid var(--rule-strong);
  border-radius: 0;
  padding: 8px 10px;
  appearance: none;
}
textarea { min-height: 104px; resize: vertical; line-height: 1.5; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--tint) 50%),
                    linear-gradient(135deg, var(--tint) 50%, transparent 50%);
  background-position: right 14px top 17px, right 8px top 17px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
select option { color: var(--ink); background: var(--sheet); }
::placeholder { color: var(--ink-soft); opacity: 0.7; font-style: italic; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible, .opt:focus-within {
  outline: 2px solid var(--stamp);
  outline-offset: 2px;
}

.counter {
  align-self: flex-end;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.counter.over { color: var(--stamp); }

/* ---------- boxed choices ---------- */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid var(--rule-strong);
  background: var(--field-bg);
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}
.opt input, .checkline input { position: absolute; opacity: 0; width: 0; height: 0; }
.box {
  position: relative;
  flex: none;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--rule-strong);
  background: var(--sheet);
}
.box::after {
  content: "\00D7";
  position: absolute;
  inset: -7px 0 0 0;
  font-family: var(--f-mono);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  color: var(--stamp);
  opacity: 0;
}
.opt input:checked ~ .box::after,
.checkline input:checked ~ .box::after { opacity: 1; }
.opt:has(input:checked) { border-color: var(--stamp); }

.checkline {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}
.checkline .box { margin-top: 3px; }
.checkline:has(input:checked) { color: var(--ink); }
.checkline:focus-within .box { outline: 2px solid var(--stamp); outline-offset: 2px; }

/* ---------- actions ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin: 26px 0 4px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}
button.file {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sheet);
  background: var(--ink);
  border: 0;
  padding: 13px 30px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease;
}
button.file:hover { background: var(--stamp); }
button.file:active { transform: translateY(1px); }
button.file[disabled] { background: var(--ink-soft); cursor: progress; }

.queue { font-family: var(--f-mono); font-size: 12px; color: var(--ink-soft); }
.queue b { color: var(--stamp); }

.err {
  margin: 0 clamp(18px, 4vw, 34px) 0;
  padding: 12px 14px;
  border: 1px solid var(--stamp);
  border-left-width: 5px;
  background: var(--field-bg);
  font-family: var(--f-mono);
  font-size: 12.5px;
  color: var(--ink);
}
.err[hidden] { display: none; }

/* ---------- receipt ---------- */
.receipt {
  position: relative;
  margin: 0 clamp(18px, 4vw, 34px);
  padding: 20px 22px 22px;
  border: 1px solid var(--rule-strong);
  border-left: 5px solid var(--stamp);
  background: var(--field-bg);
}
.receipt[hidden] { display: none; }
.rec-label {
  font-family: var(--f-mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--tint);
}
.ticket {
  font-family: var(--f-mono);
  font-weight: 700;
  font-size: clamp(24px, 5.2vw, 34px);
  letter-spacing: 0.06em;
  margin: 4px 0 10px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.receipt dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 18px;
  margin: 0 0 14px;
  font-size: 13.5px;
}
.receipt dt {
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding-top: 3px;
}
.receipt dd { margin: 0; color: var(--ink); }
.receipt .perma { font-family: var(--f-mono); font-size: 11.5px; }

.stamp {
  position: absolute;
  right: clamp(-6px, 1vw, 14px);
  top: 14px;
  transform: rotate(-13deg);
  border: 3px double var(--stamp);
  color: var(--stamp);
  font-family: var(--f-display);
  font-weight: 700;
  font-size: clamp(15px, 3.2vw, 20px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 6px 12px 5px;
  opacity: 0.92;
  pointer-events: none;
  animation: slam 0.42s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.stamp small {
  display: block;
  font-family: var(--f-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  font-weight: 400;
  text-align: center;
  margin-top: 2px;
}
@keyframes slam {
  from { transform: rotate(-13deg) scale(2.7); opacity: 0; }
  70%  { opacity: 0.92; }
  to   { transform: rotate(-13deg) scale(1); opacity: 0.92; }
}

/* ---------- record tables ---------- */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 16px clamp(18px, 4vw, 34px) 12px;
  border-bottom: 1px solid var(--rule);
}
.section-head h2 {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.section-head span {
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--tint);
}

.scroll { overflow-x: auto; }
table.records {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.records th {
  font-family: var(--f-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tint);
  text-align: left;
  padding: 10px clamp(10px, 2vw, 16px);
  border-bottom: 1px solid var(--rule-strong);
  white-space: nowrap;
}
table.records td {
  padding: 9px clamp(10px, 2vw, 16px);
  border-bottom: 1px dotted var(--rule);
  vertical-align: top;
}
table.records tr:last-child td { border-bottom: 0; }
table.records td.tk {
  font-family: var(--f-mono);
  font-size: 12.5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.records td.tk a { color: var(--stamp); text-decoration: none; border-bottom: 1px dotted var(--stamp); }
table.records td.tk a:hover { background: var(--field-bg); }
table.records td.who { font-weight: 600; white-space: nowrap; }
table.records td.st { color: var(--ink-soft); font-style: italic; min-width: 22ch; }
table.records td.ag {
  font-family: var(--f-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  text-align: right;
}

.rank {
  font-family: var(--f-mono);
  font-size: 12.5px;
  color: var(--ink-soft);
  width: 1%;
  font-variant-numeric: tabular-nums;
}
.tally {
  font-family: var(--f-mono);
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
tr.top .tally { color: var(--stamp); }

.empty, .loading {
  padding: 20px clamp(18px, 4vw, 34px) 24px;
  font-family: var(--f-mono);
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ---------- lookup ---------- */
.lookup {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 18px clamp(18px, 4vw, 34px) 22px;
}
.lookup input {
  flex: 1 1 200px;
  font-family: var(--f-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.lookup button {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sheet);
  background: var(--ink);
  border: 0;
  padding: 10px 22px;
  cursor: pointer;
}
.lookup button:hover { background: var(--stamp); }

.progress-row { margin: 2px 0 14px; }
.bar {
  height: 10px;
  border: 1px solid var(--rule-strong);
  background: var(--sheet);
  background-image: repeating-linear-gradient(45deg, transparent 0 4px, var(--rule) 4px 5px);
}

/* ---------- footer / nav ---------- */
footer {
  padding: 16px clamp(18px, 4vw, 34px) 22px;
  background: var(--sheet-band);
  border-top: 3px double var(--rule-strong);
  font-family: var(--f-mono);
  font-size: 11px;
  line-height: 1.75;
  color: var(--ink-soft);
}
footer p { margin: 0; max-width: 74ch; }
footer p + p { margin-top: 6px; }
footer a { color: var(--stamp); }

.colophon {
  text-align: center;
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.colophon a { color: var(--tint); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .stamp { animation: none; opacity: 0.92; }
}

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