:root {
  --ink: #1d1914;
  --muted: #5e564c;
  --line: #d9d0c3;
  --paper: #f6f1e8;
  --sheet: #fffaf3;
  --desk: #e4ddd2;
  --teal: #0f5c57;
  --teal-soft: #e5f1ef;
  --record: #8e2430;
  --ok: #1d6b3a;
  --warn: #8a5a12;
  color-scheme: light;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--desk);
}

button, input, textarea, select { font: inherit; color: inherit; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 22px 28px 8px;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
}

h1, h2, h3 { font-family: Palatino, "Iowan Old Style", Georgia, serif; font-weight: 600; }

h1 { margin: 2px 0 0; font-size: 34px; }

h2 { margin: 0 0 10px; font-size: 18px; }

.stt {
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 14px;
}

.stt.ready { color: var(--ok); }
.stt.error { color: var(--record); }
.stt.loading { color: var(--warn); }

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  gap: 18px;
  padding: 18px 28px 32px;
  align-items: start;
}

.rail, .dictate, .sheet {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.rail, .dictate { padding: 16px; }

.rail section + section { margin-top: 22px; }

.stack { display: flex; flex-direction: column; gap: 8px; }

.stack button, .quiet, .ghost {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--sheet);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.stack button strong { display: block; }

.stack button span, .study-meta { color: var(--muted); font-size: 13px; }

.stack button.active, .quiet:hover, .stack button:hover { border-color: var(--teal); }

.sheet {
  position: relative;
  min-height: 70vh;
  padding: 28px 32px 40px;
  background: var(--sheet);
}

#protocol { position: relative; z-index: 1; }

.last-mark {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 0;
  border: 1.5px solid #0f5c57;
  border-radius: 8px;
  background: #fff;
  pointer-events: none;
  opacity: 0;
  transform: translate(0, 0);
  transition: transform 0.45s cubic-bezier(0.22, 0.85, 0.24, 1), width 0.45s cubic-bezier(0.22, 0.85, 0.24, 1), height 0.45s cubic-bezier(0.22, 0.85, 0.24, 1), opacity 0.2s linear;
}

.last-mark.is-on { opacity: 1; }

.empty { color: var(--muted); font-size: 18px; line-height: 1.5; max-width: 42rem; }

.identity {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 0.7fr;
  gap: 12px;
  margin: 16px 0 8px;
}

.identity label, .purpose { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

.identity input, .identity select, .purpose input, .measures input, .section textarea, .dictate textarea {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  padding: 8px 10px;
}

.purpose { margin-bottom: 18px; }

.who { display: flex; gap: 16px; color: var(--muted); font-size: 14px; margin-bottom: 8px; }

.who label { display: flex; gap: 6px; align-items: center; }

.who input { border: none; border-bottom: 1px solid var(--line); background: transparent; min-width: 0; width: 180px; padding: 2px 0; }

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

.toolbar p { margin: 0; color: var(--muted); }

.ghost { background: transparent; }

.section {
  position: relative;
  max-width: 38rem;
  margin-top: 16px;
  padding: 12px 14px 14px;
  border-radius: 14px;
  border: 1px solid transparent;
  opacity: 0.8;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.section.active {
  opacity: 1;
  background: var(--teal-soft);
  border-color: #b7d6d2;
}

.section h3 { margin: 0 0 8px; font-size: 22px; }

.line, .measures, .section h3, .section textarea { position: relative; z-index: 1; }

.line {
  margin: 0 0 2px;
  padding-top: 16px;
  line-height: 1.7;
  font-size: 16.5px;
}

.line strong { font-family: Palatino, "Iowan Old Style", Georgia, serif; }

input.blank {
  border: none;
  border-bottom: 1px solid #8d8478;
  background: transparent;
  border-radius: 0;
  padding: 0 3px 1px;
  margin: 0 3px;
  text-align: center;
  vertical-align: baseline;
}

input.blank.num { width: 4.4em; }
input.blank.pair { width: 6.4em; }
input.blank.text { width: 9.5em; text-align: left; }

select.blank {
  border: none;
  border-bottom: 1px solid #8d8478;
  background: transparent;
  border-radius: 0;
  padding: 0 2px 1px;
  margin: 0 3px;
  font: inherit;
  font-size: 16.5px;
  vertical-align: baseline;
  color: inherit;
}

select.blank.choice {
  min-width: 0;
  width: auto;
  field-sizing: content;
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
  cursor: pointer;
}

.measures { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 8px; }

.measures label { display: flex; align-items: center; gap: 6px; font-size: 14px; }

.measures input { width: 96px; font-variant-numeric: tabular-nums; }

.section textarea { width: 100%; min-height: 72px; resize: vertical; line-height: 1.45; }

.record {
  width: 100%;
  min-height: 84px;
  border: none;
  border-radius: 16px;
  background: var(--teal);
  color: white;
  cursor: pointer;
  font-size: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.record:disabled { background: #8d887f; cursor: wait; }

.record[aria-pressed="true"] { background: var(--record); }

.record-kicker { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.8; }

#record-label { font-size: 22px; }

.meter { height: 8px; margin: 10px 0; background: #ddd4c8; border-radius: 99px; overflow: hidden; }

#level { display: block; height: 100%; width: 0; background: var(--teal); }

.heard { min-height: 3.2em; color: var(--muted); font-size: 14px; }

.block { display: block; margin: 8px 0 6px; font-size: 13px; color: var(--muted); }

.track { width: 100%; margin: 0 0 8px; }

.dictate textarea { width: 100%; resize: vertical; }

.row { display: flex; gap: 8px; margin: 8px 0 16px; }

.row .quiet { flex: 1; text-align: center; }

.log { margin: 0 0 12px; padding-left: 18px; }

.log li { margin: 0 0 8px; }

.log strong { font-family: Palatino, Georgia, serif; }

.log span { display: block; color: var(--muted); }

.hints { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }

.hints li { margin: 6px 0; }

.fine { color: var(--muted); font-size: 13px; line-height: 1.4; }

details summary { cursor: pointer; }

.sheet-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.patient-name {
  width: 16rem;
  max-width: 46%;
  padding: 0;
  border: none;
  background: transparent;
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-size: 26px;
  font-weight: 600;
}
.visit-no, .visit-stat { color: var(--muted); font-size: 16px; white-space: nowrap; }
.visit-no:not(:empty)::before, .visit-stat:not(:empty)::before { content: "·"; margin-right: 8px; }
.visit-stat.sim-good { color: var(--ok); }
.visit-stat.sim-mid { color: var(--warn); }
.visit-stat.sim-bad { color: var(--record); }

.spare { margin-top: 16px; }

.sized { position: relative; display: inline-block; vertical-align: baseline; }
.prior {
  position: absolute;
  z-index: 2;
  padding: 0 6px;
  border: 1px solid #9fc9c4;
  border-radius: 999px;
  background: white;
  color: var(--teal);
  font-size: 11px;
  line-height: 16px;
  white-space: nowrap;
  cursor: default;
  transition: top 0.28s ease, right 0.28s ease, left 0.28s ease, transform 0.28s ease, opacity 0.28s ease;
}
.sized:not(.has-value) .prior {
  left: 50%;
  right: auto;
  top: 50%;
  transform: translate(-50%, -58%);
  opacity: 0.45;
}
.sized.has-value .prior {
  left: auto;
  right: -2px;
  top: -12px;
  transform: none;
  opacity: 1;
}
.prior-pop { display: none; }
.prior-pop.is-open {
  display: block;
  position: fixed;
  z-index: 40;
  width: 260px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px 8px 0;
}
.prior-chart b { display: block; margin-top: 4px; font-size: 12px; font-weight: 600; }
.prior-chart svg { width: 100%; height: 112px; display: block; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .identity { grid-template-columns: 1fr; }
}

@media print {
  body { background: white; }
  .top, .rail, .dictate, .toolbar, .no-print { display: none !important; }
  .layout { display: block; padding: 0; }
  .sheet { border: none; }
  .section { max-width: none; break-inside: avoid; opacity: 1 !important; }
  .prior, .prior-pop, .last-mark { display: none !important; }
  input, textarea, select { border: none !important; background: transparent !important; }
  input.blank, select.blank { border-bottom: 1px solid #222 !important; }
}
