/* Entry Table: a page of a printed code book. Ink on cream, ruled, square. */

*, *::before, *::after { box-sizing: border-box; border-radius: 0; }
[hidden] { display: none !important; }

html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

main {
  max-width: 52rem;
  margin: 0 0 0 calc(100vw / 32 * 3);
  padding: 3.5rem 0 3rem;
}

h1 {
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 1.05;
  margin: 0 0 .75rem;
  color: var(--c-earth);
  letter-spacing: -.01em;
}
h2 { font-size: 1.375rem; margin: 3rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1.75rem 0 .5rem; }
p { margin: 0 0 .5rem; }
.lede { max-width: 38rem; margin-bottom: 2rem; }

label, legend, caption, th, dt, .smallcaps {
  font-variant-caps: all-small-caps;
  letter-spacing: .06em;
}
kbd, #strip, #text, #together td, #together th { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

a { color: var(--ink); text-decoration: underline; text-underline-offset: .15em; }

/* Controls: rectangles, 1 px ink, no fill */
button, select, input[type="text"] {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  padding: .35rem .75rem;
  cursor: pointer;
}
input[type="text"] { cursor: text; }
button:disabled { color: var(--ink-soft); border-color: var(--ink-soft); cursor: default; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
input[type="range"] { accent-color: var(--ink); width: 11rem; vertical-align: middle; }
input[type="radio"] {
  appearance: none;
  width: 1rem;
  height: 1rem;
  margin: 0 .3rem 0 0;
  border: 1px solid var(--ink);
  vertical-align: -.15rem;
  cursor: pointer;
}
input[type="radio"]:checked { background: var(--ink); box-shadow: inset 0 0 0 3px var(--bg); }
select option { background: var(--bg); color: var(--ink); }

/* The keys */
#keys { display: flex; flex-wrap: wrap; gap: .25rem; }
.key {
  width: 2.75rem;
  height: 4.25rem;
  padding: .35rem 0 .3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  font-size: .75rem;
}
.key kbd { font-size: .9375rem; font-weight: 700; }
.key.black { background: var(--ink); color: var(--bg); }
#keyhelp { margin: .6rem 0 1.25rem; color: var(--ink-soft); font-size: .875rem; }

/* The strip: bars wrap whole, never split */
#strip {
  display: flex;
  flex-wrap: wrap;
  row-gap: .5rem;
  min-height: 3.6rem;
  border-bottom: 1px solid var(--ink-soft);
  padding-bottom: .5rem;
}
#strip .bar { display: flex; border-left: 1.5px solid var(--ink); }
#strip .bar:last-child { border-right: 1.5px solid var(--ink); }
#strip [data-beat] {
  width: 2.75rem;
  text-align: center;
  font-size: .875rem;
  border-top: 3px solid transparent;
  padding: .1rem 0 .15rem;
}
#strip [data-beat]::before {
  content: attr(data-n);
  display: block;
  font-size: .625rem;
  color: var(--ink-soft);
  font-weight: 400;
}
#strip [data-strong] { font-weight: 700; border-top-color: var(--ink); }
#count { margin: .5rem 0 1.5rem; font-size: .875rem; }

.controls { display: flex; flex-wrap: wrap; gap: 1rem 1.75rem; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: .2rem; }
.field.wide { flex: 1 1 18rem; }
#text { width: 100%; font-size: .875rem; }
#voices { border: 0; padding: 0; margin: 0; min-width: 0; }
#voices legend { padding: 0; margin-bottom: .2rem; }
#voices label { display: inline-flex; align-items: center; height: 2.2rem; margin-right: 1rem; font-variant-caps: normal; letter-spacing: 0; cursor: pointer; white-space: nowrap; }
#problem { margin: .6rem 0 0; font-weight: 700; }
.onfile { margin: 1.25rem 0 0; display: flex; flex-wrap: wrap; gap: .5rem; }

/* The answer */
#answer { margin-top: 2.75rem; border-top: 1.5px solid var(--ink); padding-top: 1.25rem; }
#summary p { margin: 0 0 .2rem; }
#summary p:first-child { font-weight: 700; }
/* The audio line stays in view over the table, so Stop is always one press away */
.audio {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .9rem;
  margin: 1.25rem 0 1.5rem;
  padding: .6rem 0;
  border-bottom: 1px solid var(--ink-soft);
  font-size: .875rem;
}
#audio-status { flex-basis: 100%; }
#audio-status:empty { display: none; }

#entries { width: 100%; border-collapse: collapse; font-size: 14px; }
#entries caption { text-align: left; font-weight: 700; padding-bottom: .35rem; }
#entries th { text-align: left; font-weight: 700; padding: .3rem .6rem; border-bottom: 1.5px solid var(--ink); }
#entries td { padding: .65rem .6rem; border-bottom: 1px solid var(--ink-soft); vertical-align: top; }
#entries td.off { width: 11.5rem; }
#entries td.hear-col { width: 9rem; }
.pick { display: block; padding: .15rem .5rem .2rem; font-size: .8125rem; text-align: left; }
.pick .num { font-size: 1.5rem; line-height: 1.1; margin-right: .15rem; }
tr[aria-selected="true"] td.off { box-shadow: inset 4px 0 0 var(--ink); }
tr[aria-selected="true"] .num { font-weight: 700; }
.cite { display: inline-block; margin-top: .35rem; }
.sign {
  display: inline-block;
  margin-top: .35rem;
  padding: .2rem .55rem;
  font-weight: 700;
  font-size: .875rem;
  border: 1.5px solid var(--ink);
  background: var(--error);
  color: var(--error-fg);
}
.hear { white-space: nowrap; font-size: .875rem; }
#covers { margin-top: .75rem; font-size: .875rem; }

/* The rules */
#rules { padding-left: 2.25rem; margin: 0; }
#rules li { margin: 0 0 .9rem; padding-left: .35rem; }
#rules li::marker { color: var(--c-earth); font-weight: 700; font-size: 1.25rem; }
#rules .gloss { display: block; color: var(--ink-soft); font-size: .875rem; }
#words { margin: 0 0 1.25rem; }
#words dt { font-weight: 700; margin-top: .6rem; }
#words dd { margin: 0; }

/* Parts */
#parts { margin-top: 1rem; }
#entry-list { padding-left: 1.5rem; }
#together { border-collapse: collapse; font-size: 13px; margin: 1rem 0; }
#together th, #together td { text-align: left; padding: .2rem .9rem .2rem 0; border-bottom: 1px solid var(--ink-soft); white-space: pre; }
#together thead th { border-bottom: 1.5px solid var(--ink); font-family: var(--font-body); }
#together tbody th { font-variant-caps: normal; letter-spacing: 0; font-weight: 400; color: var(--ink-soft); }

footer { margin-top: 7rem; padding-top: 1rem; border-top: 1px solid var(--ink-soft); font-size: .8125rem; color: var(--ink-soft); }
.wordmark { display: block; height: 1.5rem; width: auto; margin-bottom: .75rem; }
.print-only { display: none; }

/* Dark: plum measures 1.33:1 on the dark ground, so the title and rule numbers take the ink */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) h1,
  :root:not([data-theme="light"]) #rules li::marker { color: var(--ink); }
  :root:not([data-theme="light"]) .wordmark { filter: brightness(0) invert(1); }
}
:root[data-theme="dark"] h1,
:root[data-theme="dark"] #rules li::marker { color: var(--ink); }
:root[data-theme="dark"] .wordmark { filter: brightness(0) invert(1); }

/* Phone: 16 px gutter, keys wrap, every row a stacked block */
@media (max-width: 640px) {
  main { margin: 0; padding: 2rem 16px 2.5rem; }
  h1 { font-size: 2.25rem; }
  #entries, #entries tbody, #entries tr, #entries td { display: block; width: auto; }
  #entries thead { display: none; }
  #entries caption { display: block; }
  #entries tr { border-bottom: 1px solid var(--ink-soft); padding: .6rem 0 .7rem .6rem; }
  #entries td, #entries td.off, #entries td.hear-col { border: 0; padding: .2rem 0; width: auto; text-align: left; }
  tr[aria-selected="true"] td.off { box-shadow: none; }
  #entries tr[aria-selected="true"] { box-shadow: inset 4px 0 0 var(--ink); }
  #together, #together tbody, #together tr, #together td, #together th { display: block; }
  #together thead { display: none; }
  #together tr { padding: .4rem 0; border-bottom: 1px solid var(--ink-soft); }
  #together th, #together td { border: 0; padding: .05rem 0; }
  #together tbody th::before { content: "Bar "; }
  #together td::before { content: attr(data-label) "  "; font-family: var(--font-body); color: var(--ink-soft); }
}

/* Print: A4, light values always, the sheet carries its own source */
@media print {
  @page { size: A4; margin: 14mm; }
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) {
    --bg: #FCF0DD;
    --ink: #1A1A1A;
    --ink-soft: #5B5B5B;
    --error: #BE3B27;
    --error-fg: #FCF0DD;
    color-scheme: light;
  }
  :root h1, :root:not([data-theme="light"]) h1, :root[data-theme="dark"] h1 { color: var(--c-earth); }
  :root #rules li::marker, :root:not([data-theme="light"]) #rules li::marker, :root[data-theme="dark"] #rules li::marker { color: var(--c-earth); }
  :root .wordmark, :root:not([data-theme="light"]) .wordmark, :root[data-theme="dark"] .wordmark { filter: none; }

  html, body { background: none; }
  body { font-size: 10pt; line-height: 1.35; }
  main { margin: 0; padding: 0; max-width: none; }
  h1 { font-size: 26pt; }
  h2 { font-size: 13pt; margin: 6mm 0 2mm; }
  h3 { margin: 4mm 0 1mm; }
  #strip { row-gap: 1mm; }
  #rules li { margin-bottom: 2mm; }
  #rules li::marker { font-size: 12pt; }
  #rules .gloss, footer { font-size: 8.5pt; }
  .lede { margin-bottom: 4mm; }
  #keys, #keyhelp, .audio, #tempo, label[for="tempo"], #text, label[for="text"], #bar, label[for="bar"],
  #voices, #voices legend, #voices label, .controls, .onfile, #problem, .hear-col, .screen-only,
  button:not(.pick) { display: none !important; }
  .print-only { display: block; }
  #count { margin-bottom: 4mm; }
  #answer { margin-top: 4mm; }
  .pick { border: 0; padding: 0; color: var(--ink); background: none; }
  .pick .num { font-size: 13pt; }
  #entries { font-size: 9pt; }
  #entries td { padding: 1.6mm 2mm; }
  #entries td.off { width: 38mm; }
  tr { break-inside: avoid; }
  .sign { print-color-adjust: exact; -webkit-print-color-adjust: exact; font-size: 8.5pt; }
  #together { font-size: 8.5pt; }
  #parts { break-before: page; }
  #parts h2 { margin-top: 0; }
  footer { margin-top: 8mm; break-inside: avoid; }
}
