:root { --title: var(--c-earth); }

:root[data-theme="dark"] { --title: var(--ink); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --title: var(--ink); }
}

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

html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

h1, h2, p { margin: 0; }

button, input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--ink);
  appearance: none;
  -webkit-appearance: none;
}

button {
  padding: 8px 18px;
  cursor: pointer;
  font-weight: var(--fw-medium);
}
button:hover { background: var(--ink); color: var(--bg); }
button.primary { background: var(--ink); color: var(--bg); padding: 11px 30px; }
button.primary:hover { background: var(--bg); color: var(--ink); }
button.text {
  border: 0;
  padding: 0;
  background: none;
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
button.text:hover { background: none; color: var(--ink); text-decoration-thickness: 2px; }

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

label, .smallcaps, .kind, .sys-line, .record h2 {
  font-variant-caps: small-caps;
  letter-spacing: 0.04em;
}

/* setup */
.col { max-width: 36rem; margin: 0 auto; padding: 40px 16px 64px; }
.wordmark { display: block; width: 126px; height: auto; }
.title {
  margin-top: 28px;
  font-size: 44px;
  line-height: 1.1;
  font-weight: var(--fw-medium);
  color: var(--title);
  letter-spacing: -0.01em;
}
.lede { margin-top: 12px; font-size: 18px; }
.lede + .lede { margin-top: 4px; }

.form {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--title);
  display: grid;
  gap: 6px;
}
.form label { display: block; font-size: 15px; color: var(--ink-soft); }
.form input, .form textarea, .form select { width: 100%; padding: 9px 10px; }
.form textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; }
.select { position: relative; display: block; }
.select select { padding-right: 36px; cursor: pointer; }
.caret {
  position: absolute;
  right: 12px;
  top: 50%;
  margin-top: -3px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
  pointer-events: none;
}
.note { font-size: 14px; color: var(--ink-soft); margin-bottom: 10px; }
.own { display: grid; gap: 6px; }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.error { color: var(--error); min-height: 1.5em; font-size: 15px; }
.form .primary { justify-self: start; margin-top: 2px; }

.record { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--title); }
.record h2 { font-size: 18px; font-weight: var(--fw-medium); color: var(--title); }
#record-empty { margin-top: 8px; color: var(--ink-soft); }
.record-list { list-style: none; margin: 10px 0 0; padding: 0; }
.record-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--ink-soft);
  font-size: 14px;
}
.record-line { white-space: pre-wrap; }
#record-clear { margin-top: 14px; font-size: 14px; }

/* play: the 32 x 20 grid, 2 rows of header, 10 of tune, 8 of hands */
.play {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 2fr 10fr 8fr;
  grid-template-columns: minmax(0, 1fr);
  padding: 0 16px;
  overflow: hidden;
}
.play-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--title);
  min-height: 0;
}
.play-title { min-width: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-title .mark { color: var(--title); font-weight: var(--fw-medium); margin-right: 8px; }

.play-band {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 0 8px;
  gap: 6px;
}
.sys-line { font-size: 15px; color: var(--ink-soft); }
.live-row {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(12rem, 18rem);
  gap: 20px;
}
.live-staff { min-height: 0; min-width: 0; }
.live-staff svg { display: block; width: 100%; height: 100%; }
.margin { font-size: 14px; line-height: 1.5; }
.margin p { color: var(--error); }
.live-margin {
  overflow-y: auto;
  min-height: 0;
  border-left: 1px solid var(--title);
  padding: 2px 0 2px 12px;
}
.play-help { font-size: 15px; }

.halves {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  min-height: 0;
  padding: 6px 4px 14px;
}
.side { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.half {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px solid var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.half[data-state="waiting"], .half[data-state="hiccup"] { border-style: dotted; }
.half[data-state="hiccup"] { outline: 3px solid var(--error); outline-offset: 2px; }
.who { display: flex; align-items: center; gap: 12px; }
.big { font-size: clamp(56px, 11vh, 112px); line-height: 1; font-weight: var(--fw-medium); }
.swatch { width: 18px; height: 18px; border: 1px solid var(--ink); }
.swatch-a { background: var(--c-mustard); }
.swatch-b { background: var(--c-lav); }
.keycap {
  min-width: 2.2em;
  padding: 2px 8px 1px;
  text-align: center;
  font-size: 20px;
  font-weight: var(--fw-medium);
  border: 1px solid var(--ink);
  border-bottom-width: 3px;
}
.half-name { font-size: 15px; color: var(--ink-soft); min-height: 1.5em; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.half-status { min-height: 3em; padding-top: 6px; font-size: 14px; line-height: 1.5; }

/* sheets */
.sheets { max-width: 52rem; margin: 0 auto; padding: 28px 16px 72px; }
.sheets-bar { display: grid; gap: 14px; padding-bottom: 20px; border-bottom: 1px solid var(--title); }
.finish-line { font-size: 17px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.sheet { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--title); }
.sheet:first-child { border-top: 0; margin-top: 8px; padding-top: 8px; }
.sheet-head { padding-bottom: 14px; border-bottom: 1px solid var(--title); }
.sheet-title { font-size: 26px; line-height: 1.25; font-weight: var(--fw-medium); color: var(--title); }
.sheet-head p { font-size: 15px; }
.blank { display: inline-block; width: 12em; border-bottom: 1px solid var(--ink); }

.system {
  display: grid;
  grid-template-columns: minmax(0, 33rem) minmax(9rem, 1fr);
  gap: 18px;
  margin-top: 14px;
  break-inside: avoid;
}
.system svg { display: block; width: 100%; height: auto; }
.system .margin { border-left: 1px solid var(--title); padding-left: 10px; font-size: 13px; }

.sheet-foot { margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--title); font-size: 15px; }
.colophon { margin-top: 6px; font-size: 12px; line-height: 1.45; color: var(--ink-soft); }

@media screen and (max-width: 719.98px) {
  .live-row { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 8px; }
  .live-staff svg { height: auto; }
  .live-margin { border-left: 0; border-top: 1px solid var(--title); padding: 6px 0 0; }
  .system { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .system .margin { border-left: 0; padding-left: 0; }
  .play-help, .sys-line { font-size: 14px; }
}

/* engraving */
/* rules stay hairlines at any scale: 1 px on screen, 0.26 mm on paper */
.staff .sl, .staff .ledger { stroke: var(--title); stroke-width: 1; vector-effect: non-scaling-stroke; shape-rendering: crispEdges; }
.staff .clef { fill: var(--title); }
.staff .head, .staff .rest { fill: var(--ink); }
.staff .acc { fill: none; stroke: var(--ink); stroke-width: 1.2; }
.staff .num, .staff .row-label { fill: var(--ink-soft); font-family: var(--font-body); font-variant-numeric: tabular-nums; }
.staff .num.next { fill: var(--ink); font-weight: var(--fw-bold); }
.staff .sq { stroke: var(--ink); stroke-width: 1; vector-effect: non-scaling-stroke; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.staff .sq-a { fill: var(--c-mustard); }
.staff .sq-b { fill: var(--c-lav); }
.staff .note.dim .head { fill: var(--ink-soft); opacity: 0.45; }
.staff .note.dim .acc { stroke: var(--ink-soft); opacity: 0.45; }

/* the wordmark is plum on its own stock: on the dark ground it keeps a cream label */
:root[data-theme="dark"] .wordmark { background: var(--c-cream); padding: 6px 8px; box-sizing: content-box; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .wordmark { background: var(--c-cream); padding: 6px 8px; box-sizing: content-box; }
}

/* print: one sheet per page, a system is never split */
@media print {
  @page { margin: 14mm; }
  :root, :root:not([data-theme="light"]) { color-scheme: light; }
  html, body { background: var(--bg); }
  body { font-size: 10pt; line-height: 4.5mm; }
  #setup, #play, .sheets-bar { display: none !important; }
  .sheets { max-width: none; margin: 0; padding: 0; }
  .sheet { margin: 0; padding: 0; border-top: 0; break-before: page; }
  .sheet:first-child { break-before: auto; margin: 0; padding: 0; }
  .sheet-head { padding-bottom: 2mm; }
  .sheet-title { font-size: 14pt; line-height: 6mm; }
  .sheet-head p, .sheet-foot { font-size: 10pt; line-height: 4.5mm; }
  .system { grid-template-columns: 110mm minmax(0, 1fr); gap: 4mm; margin-top: 3mm; break-inside: avoid; }
  .system svg { width: 110mm; height: auto; }
  .system .margin { font-size: 10pt; line-height: 4.5mm; border-left: 0.2mm solid var(--title); padding-left: 3mm; }
  .sheet-foot { margin-top: 3mm; padding-top: 1.5mm; }
  .colophon { margin-top: 1mm; font-size: 8pt; line-height: 3.6mm; }
  .blank { width: 50mm; }
}

@media print { :root, :root[data-theme], :root:not([data-theme="light"]) { --bg:#FFFFFF; --ink:#1A1A1A; --ink-soft:#5B5B5B; --error:#BE3B27; --title:#530E36; } }
