@import url("tokens.css");

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sheet-ink: #1A1A1A;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font-body);
}

/* Page chrome: one column, set like a form */
.top, .col { max-width: 760px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.top { padding-top: 20px; }
.mark { display: block; width: 120px; height: auto; }
.col { padding-bottom: 72px; }

h1 {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: 40px;
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin: 44px 0 12px;
}
.lede { max-width: 36em; margin: 0 0 36px; }

section { border-top: 1px solid var(--ink); padding: 14px 0 32px; }
h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: var(--fw-bold);
  margin: 0 0 16px;
}
.num {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 1px solid var(--ink);
  text-align: center;
  line-height: 22px;
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
}

label { display: block; font-size: 14px; margin: 0 0 6px; }
textarea {
  display: block;
  width: 100%;
  font: 18px/1.5 var(--font-body);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 8px 10px;
  resize: vertical;
}
.status { color: var(--error); font-size: 14px; }
.status p { margin: 8px 0 0; }

.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
button {
  font: 15px/1 var(--font-body);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 11px 16px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--accent); color: var(--accent-fg); }
button:disabled { opacity: 0.4; cursor: default; }
textarea:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* The hymn page: white paper, scaled to the column. 1 mm on paper = 100cqw / 180 inside the sheet. */
.paper {
  background: #fff;
  color: var(--sheet-ink);
  border: 1px solid var(--ink-soft);
  padding: 7.1429%;            /* 15 mm of 210 */
}
.sheet {
  container-type: inline-size;
  --mm: calc(100cqw / 180);
  --pt: calc(100cqw / 180 * 0.35278);
  font-family: var(--serif);
  color: var(--sheet-ink);
}
.head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  column-gap: calc(4 * var(--mm));
  border-top: max(1px, calc(0.5 * var(--pt))) solid var(--sheet-ink);
  padding-top: calc(3 * var(--mm));
}
.no { font-size: calc(28 * var(--pt)); line-height: 0.9; font-variant-numeric: lining-nums; min-width: 1ch; }
.title { font-size: calc(16 * var(--pt)); line-height: 1.25; padding-top: calc(1 * var(--mm)); overflow-wrap: anywhere; }
.tuneblock { text-align: right; font-size: calc(9 * var(--pt)); line-height: 1.45; padding-top: calc(1.2 * var(--mm)); }
.tune { letter-spacing: 0.14em; white-space: nowrap; }
.metre { font-style: italic; }
/* The empty frame: blank lines where the title, tune and metre will be written, and no staves */
#title:empty::after, #tune:empty::after, #metre:empty::after {
  content: "";
  display: block;
  border-bottom: max(1px, calc(0.5 * var(--pt))) dotted var(--sheet-ink);
}
#title:empty::after { width: 72%; height: calc(19 * var(--pt)); }
#tune:empty::after, #metre:empty::after { width: calc(26 * var(--mm)); height: calc(12 * var(--pt)); margin-left: auto; }

.music-wrap { margin-top: calc(5 * var(--mm)); min-height: calc(46.5 * var(--mm)); }
.music { display: block; width: 100%; height: auto; }
.music text { font-family: var(--serif); }
.music .syl { paint-order: stroke; stroke: #fff; stroke-width: 0.7; stroke-linejoin: round; }
#shade { fill: var(--c-peach); fill-opacity: 0.45; }
.toomany { font-size: calc(10 * var(--pt)); margin: 0; padding: calc(12 * var(--mm)) 0; }

.foot { margin-top: calc(3 * var(--mm)); font-size: calc(8 * var(--pt)); line-height: 1.45; }
.foot p { margin: 0; }
.credit { margin-bottom: calc(2 * var(--mm)) !important; }
.rules { border-top: max(1px, calc(0.5 * var(--pt))) solid var(--sheet-ink); padding-top: calc(2 * var(--mm)); margin-bottom: calc(1.5 * var(--mm)) !important; }

/* The working */
details { margin-top: 28px; border-top: 1px solid var(--ink-soft); padding-top: 12px; }
summary { cursor: pointer; font-weight: var(--fw-bold); }
#working-body { font-size: 14px; overflow-x: auto; }
#working-body h3 { font-size: 14px; margin: 22px 0 6px; }
#working-body dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
#working-body dt { color: var(--ink-soft); }
#working-body dd { margin: 0; }

table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 5px 12px 5px 0; border-bottom: 1px solid var(--ink-soft); vertical-align: top; }
th { font-weight: var(--fw-medium); border-bottom-color: var(--ink); }
#working-body td, #working-body th { padding-right: 14px; white-space: nowrap; }

/* The index of tunes */
#index { width: 100%; font-size: 15px; }
#index .r { text-align: right; padding-right: 14px; }
#index .tn { letter-spacing: 0.1em; }
#index .r, #index .tn, #index .set { white-space: nowrap; }
#index-empty { margin: 0; }
.index-head { display: none; }

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

@media (max-width: 480px) {
  h1 { font-size: 32px; margin-top: 32px; }
  #index { font-size: 14px; }
  #index th, #index td { padding-right: 8px; }
}

@page { size: auto; margin: 15mm; }

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: var(--sheet-ink); }
  .top, h1, .lede, #s-names, #s-hymn > h2, .buttons, details, #s-index > h2 { display: none !important; }
  .col { max-width: none; margin: 0; padding: 0; }
  section { border: 0; padding: 0; }
  .paper { border: 0; padding: 0; break-inside: avoid; }
  #shade { display: none; }
  body[data-print="sheet"] #s-index { display: none; }
  body[data-print="index"] #s-hymn { display: none; }

  #index-print { font-family: var(--serif); color: var(--sheet-ink); }
  .index-head { display: block; border-top: 0.5pt solid var(--sheet-ink); padding-top: 3mm; margin-bottom: 4mm; font-size: 16pt; }
  #index { font-size: 10pt; }
  #index th, #index td { border-bottom: 0.5pt solid var(--sheet-ink); color: var(--sheet-ink); }
}
