/* Third Tone. A one-page examination form: ruled sections, square boxes, no cards.
   The token radius scale is deliberately unused; every radius is 0. */

:root {
  --target-line: var(--c-earth);
  --heading: var(--c-earth);
  --trace-mic: var(--c-copper);
  --gutter: 16px;
  --indent: 0px;
}

[data-theme="dark"] {
  --target-line: var(--c-peach);
  --heading: var(--ink);
  --trace-mic: var(--c-mustard);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --target-line: var(--c-peach);
    --heading: var(--ink);
    --trace-mic: var(--c-mustard);
  }
}

@media (min-width: 720px) {
  :root {
    --gutter: 24px;
    --indent: 44px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-radius: 0;
}

html {
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.45 var(--font-body);
}

[hidden] {
  display: none !important;
}

.sheet {
  max-width: 1232px;
  margin: 0 auto;
  padding: 20px var(--gutter) 40px;
}

/* Title block */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.wordmark {
  display: block;
  width: auto;
  height: 34px;
}

.formno {
  font-size: 16px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.titleblock {
  border-bottom: 3px double var(--ink);
  padding: 14px 0 16px;
}

h1 {
  margin: 0 0 4px;
  font-size: 40px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--heading);
}

.subtitle {
  margin: 0;
}

.print-only {
  display: none;
}

/* Sections, numbered like form boxes */

.step {
  border-top: 1px solid var(--ink);
  padding: 18px 0 22px;
}

#s1 {
  border-top: 0;
}

h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 700;
  color: var(--heading);
}

.num {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.step.active .num {
  text-decoration-line: underline;
  text-decoration-color: var(--c-mustard);
}

.body {
  padding-left: var(--indent);
}

p {
  margin: 0 0 12px;
  max-width: 68ch;
}

.note {
  font-size: 16px;
  color: var(--ink-soft);
}

.note.quiet {
  visibility: hidden;
}

.status {
  min-height: 1.45em;
  font-size: 16px;
}

.count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin-right: 10px;
}

.count:empty {
  margin-right: 0;
}

.error {
  color: var(--error);
}

.steps {
  margin: 0 0 12px;
  padding-left: 1.4em;
  max-width: 68ch;
}

.steps li {
  margin-bottom: 2px;
}

.warning {
  font-weight: 700;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin: 0 0 12px;
}

/* Controls: square, outlined, plain */

button {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  padding: 9px 16px;
  min-height: 44px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}

button:active:not(:disabled),
button.held {
  background: var(--ink);
  color: var(--bg);
}

button:disabled {
  color: var(--ink-soft);
  border-color: var(--ink-soft);
  cursor: not-allowed;
}

button.link {
  border: 0;
  padding: 9px 4px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

button.link:hover:not(:disabled) {
  background: transparent;
  text-decoration-thickness: 2px;
}

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

input[type="radio"],
input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  display: inline-grid;
  place-content: center;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
}

input[type="radio"]:checked::before,
input[type="checkbox"]:checked::before {
  content: "";
  width: 12px;
  height: 12px;
  background: var(--ink);
}

input[type="radio"]:disabled,
input[type="checkbox"]:disabled {
  border-color: var(--ink-soft);
  cursor: not-allowed;
}

input:disabled:checked::before {
  background: var(--ink-soft);
}

fieldset {
  border: 0;
  margin: 0 0 6px;
  padding: 0;
  min-width: 0;
}

legend {
  float: left;
  padding: 0;
  margin-right: 14px;
  line-height: 44px;
  font-weight: 700;
}

fieldset label,
label.check {
  display: inline-flex;
  vertical-align: top;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-right: 18px;
  cursor: pointer;
}

.kinds legend {
  float: none;
  line-height: 1.45;
  margin-bottom: 2px;
}

.kinds label {
  display: flex;
  min-height: 40px;
}

.sliders {
  display: grid;
  grid-template-columns: 9em minmax(0, 1fr) 6.5em;
  align-items: center;
  gap: 4px 12px;
  margin: 0 0 8px;
}

output {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: var(--ink);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 26px;
  margin-top: -12.5px;
  background: var(--bg);
  border: 1px solid var(--ink);
  border-radius: 0;
}

input[type="range"]::-moz-range-track {
  height: 1px;
  background: var(--ink);
}

input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 24px;
  background: var(--bg);
  border: 1px solid var(--ink);
  border-radius: 0;
}

input[type="range"]:disabled {
  cursor: not-allowed;
}

input[type="range"]:disabled::-webkit-slider-runnable-track {
  background: var(--ink-soft);
}

input[type="range"]:disabled::-webkit-slider-thumb {
  border-color: var(--ink-soft);
}

/* Section 3 */

.cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px 40px;
}

.readout {
  width: 100%;
  border-collapse: collapse;
  margin: 2px 0 16px;
  font-variant-numeric: tabular-nums;
}

.readout th,
.readout td {
  padding: 6px 8px 6px 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  text-align: left;
  font-weight: 400;
}

.readout .hz {
  text-align: right;
  padding-right: 16px;
  white-space: nowrap;
}

.readout .nm {
  white-space: nowrap;
}

.readout .mark {
  text-align: right;
  padding-right: 0;
  font-weight: 700;
  white-space: nowrap;
}

.spectrum {
  margin: 0 0 18px;
}

.spectrum canvas {
  display: block;
  width: 100%;
  height: 280px;
}

.spectrum figcaption {
  margin-top: 6px;
  font-size: 16px;
  color: var(--ink-soft);
}

.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-bottom: 4px;
}

.key::before {
  content: "";
  display: inline-block;
  width: 22px;
  margin-right: 8px;
  vertical-align: middle;
  border-top: 1px solid var(--ink);
}

.key-mic::before {
  border-top-color: var(--trace-mic);
}

.key-target::before {
  border-top: 1px dashed var(--target-line);
}

.control {
  margin-bottom: 8px;
}

.control .sliders {
  grid-template-columns: 9em minmax(0, 1fr) 4.5em;
}

.freqs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0 8px;
}

.freq {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 68px;
  padding: 8px 4px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.freq b {
  font-size: 18px;
}

.freq span {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.answer button {
  min-width: 9em;
}

/* Section 4 */

.record-area {
  display: grid;
  gap: 20px 32px;
  align-items: start;
}

.audiogram {
  margin: 0;
  order: -1;
}

.audiogram svg {
  display: block;
  width: 300px;
  max-width: 100%;
  height: auto;
  color: var(--ink);
}

.audiogram figcaption {
  max-width: 300px;
  margin-top: 4px;
  font-size: 16px;
  color: var(--ink-soft);
}

.ag-grid line {
  stroke: var(--c-teal);
  stroke-width: 1;
}

.ag-frame {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
}

.ag-text {
  fill: var(--ink-soft);
  font-size: 16px;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
}

.ag-mark {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.record {
  width: 100%;
  border-collapse: collapse;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.record th,
.record td {
  text-align: left;
  vertical-align: top;
  padding: 7px 12px 7px 0;
  border-bottom: 1px solid var(--ink);
}

.record td {
  white-space: nowrap;
}

.record td[data-label="Target"],
.record td[data-label="Report"] {
  white-space: normal;
}

.record .nw {
  white-space: nowrap;
}

.record .line {
  display: block;
}

.record thead th {
  border-top: 1px solid var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.record td p {
  margin: 0;
}

.record .basis {
  font-size: 16px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.record-table .note {
  margin-top: 10px;
}

#s4 > .row {
  margin: 16px 0 0;
  padding-left: var(--indent);
}

.foot {
  border-top: 1px solid var(--ink);
  padding-top: 12px;
  font-size: 16px;
  color: var(--ink-soft);
}

@media (min-width: 720px) {
  .audiogram {
    display: flex;
    align-items: flex-end;
    gap: 24px;
  }

  .audiogram figcaption {
    max-width: 22em;
  }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .wordmark {
    filter: brightness(0) invert(1);
    opacity: 0.9;
  }
}

[data-theme="dark"] .wordmark {
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

/* Phone */

@media screen and (max-width: 719px) {
  .sliders,
  .control .sliders {
    grid-template-columns: minmax(0, 1fr) 6.5em;
  }

  .sliders label {
    grid-column: 1 / -1;
    margin-top: 6px;
  }

  .freqs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* Two lines a row, so no readout breaks inside a value: name and mark, then Hz and note */
  .readout,
  .readout tbody {
    display: block;
  }

  .readout tr {
    display: grid;
    grid-template-columns: 6.5em minmax(0, 1fr);
    column-gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--ink);
  }

  .readout tr:first-child {
    border-top: 1px solid var(--ink);
  }

  .readout th,
  .readout td,
  .readout .hz,
  .readout .mark {
    padding: 0;
    border: 0;
    text-align: left;
  }

  .readout .mark {
    grid-area: 1 / 2;
  }

  .readout .hz {
    grid-area: 2 / 1;
  }

  .readout .nm {
    grid-area: 2 / 2;
  }
}

/* Below desktop width the record rows stack, label beside value */

@media screen and (max-width: 1199px) {
  .record thead {
    display: none;
  }

  .record,
  .record tbody,
  .record tr {
    display: block;
    width: 100%;
  }

  .record tr {
    border-top: 1px solid var(--ink);
    padding: 8px 0;
  }

  .record td {
    display: grid;
    grid-template-columns: 7.5em minmax(0, 1fr);
    gap: 12px;
    padding: 3px 0;
    border: 0;
  }

  .record td::before {
    content: attr(data-label);
    color: var(--ink-soft);
    font-size: 16px;
  }

  .record td[data-label="Report"] {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    padding: 8px 0 4px;
  }

  .record .witness::after {
    content: "";
    height: 2em;
    border-bottom: 1px solid var(--ink);
  }
}

/* Desktop: sections 1 and 2 side by side, the instrument in two columns */

@media (min-width: 1024px) {
  .sheet {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .masthead,
  .titleblock,
  #s3,
  #s4,
  .foot {
    grid-column: 1 / -1;
  }

  #s1 {
    padding-right: 28px;
    border-right: 1px solid var(--ink);
  }

  #s2 {
    border-top: 0;
    padding-left: 28px;
  }

  .cols {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  }
}


/* Print: the record only, black on white, hairlines */

@media print {
  @page {
    margin: 10mm;
  }

  *,
  *::before,
  *::after {
    color: #000 !important;
    background: transparent !important;
    border-color: #000 !important;
    box-shadow: none !important;
    filter: none !important;
  }

  html,
  body {
    background: #fff !important;
    font-size: 8pt;
    line-height: 1.25;
  }

  .sheet {
    display: block;
    position: relative;
    max-width: none;
    padding: 0;
  }

  #s1,
  #s2,
  #s3,
  .noprint,
  .record-table .note {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  .masthead {
    width: 100mm;
  }

  .wordmark {
    height: 6mm;
    filter: brightness(0) !important;
  }

  .formno {
    font-size: 8pt;
  }

  .titleblock {
    min-height: 56mm;
    padding: 3mm 0 0;
    border-bottom: 0;
  }

  h1 {
    font-size: 18pt;
  }

  .subtitle {
    font-size: 9pt;
    margin-bottom: 4mm;
  }

  .fields {
    font-size: 8pt;
  }

  .fields > span {
    display: inline-block;
    white-space: nowrap;
    margin: 0 4mm 1.5mm 0;
  }

  .fields .blank {
    display: inline-block;
    width: 34mm;
    border-bottom: 0.5pt solid #000;
  }

  .step {
    padding: 0;
  }

  #s4 {
    border-top: 0;
  }

  h2 {
    display: none;
  }

  .body {
    padding: 0;
  }

  .record-area {
    display: block;
  }

  .audiogram {
    display: block;
    position: absolute;
    top: 0;
    right: 0;
    width: 75mm;
  }

  .audiogram svg {
    width: 75mm;
    height: 50mm;
  }

  .audiogram figcaption {
    max-width: 75mm;
    font-size: 6.5pt;
  }

  .ag-grid line,
  .ag-frame {
    stroke: #000 !important;
    stroke-width: 0.5;
  }

  .ag-text {
    fill: #000 !important;
    font-size: 11px;
  }

  /* Column widths measured for the widest common system sans; the report column takes the rest,
     wide enough that each basis line stays on one line, so ten rows fit one A4 or Letter page. */
  .record {
    table-layout: fixed;
    width: 100%;
    font-size: 6.5pt;
    line-height: 1.22;
    border-top: 0.75pt solid #000;
  }

  .record td,
  .record thead th {
    white-space: normal;
  }

  .record thead {
    display: table-header-group;
  }

  .record tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .record th,
  .record td {
    padding: 1mm 1mm 1mm 0;
    border-bottom: 0.5pt solid #000;
  }

  .record th:nth-child(1) { width: 5.5mm; }
  .record th:nth-child(2) { width: 15.5mm; }
  .record th:nth-child(3),
  .record th:nth-child(4) { width: 11mm; }
  .record th:nth-child(5) { width: 13mm; }
  .record th:nth-child(6) { width: 18.5mm; }
  .record th:nth-child(7) { width: 7mm; }
  .record th:nth-child(8) { width: 10.5mm; }
  .record th:nth-child(10) { width: 22mm; }

  .record .basis {
    font-size: 6pt;
    margin-bottom: 0.5mm;
  }

  .foot {
    break-before: avoid;
    page-break-before: avoid;
    margin-top: 4mm;
    padding-top: 2mm;
    border-top: 0.5pt solid #000;
    font-size: 7.5pt;
  }
}
