:root {
  --paper: #efe9dc;
  --paper-2: #f6f2e8;
  --ink: #1d1b19;
  --ink-2: #4b4640;
  --ink-3: #6b645a;
  --grid: rgba(214, 92, 84, 0.10);
  --grid-major: rgba(214, 92, 84, 0.20);
  --red: #c8282f;
  --amber: #e2731d;
  --blue: #2f5fa8;
  --band: #fbfaf6;
  --band-edge: #d8dde3;
  --redact: #151312;

  --display: "Anybody", "Arial Narrow", sans-serif;
  --mono: "Martian Mono", ui-monospace, monospace;
  --serif: "Newsreader", Georgia, serif;
  --hand: "Reenie Beanie", cursive;

  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
  background-color: #d9d1c1;
  /* a desk under the chart: warm vignette + fine grain */
  background-image:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 250, 238, 0.55), transparent 60%),
    radial-gradient(80% 60% at 100% 100%, rgba(120, 90, 50, 0.18), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.3 0 0 0 0 0.24 0 0 0 0 0.16 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: inherit; }
p { margin: 0; }

.mono { font-family: var(--mono); font-size: 12px; letter-spacing: 0.02em; font-variation-settings: "wdth" 88; }
.dim { color: var(--ink-3); }

.skip {
  position: absolute; left: 16px; top: -60px; z-index: 50;
  background: var(--ink); color: var(--paper); padding: 8px 12px;
  font-family: var(--mono); font-size: 12px; text-decoration: none;
}
.skip:focus { top: 16px; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

/* the chart: ECG paper on a clipboard */
.chart {
  position: relative;
  max-width: 1080px;
  margin: 40px auto 64px;
  padding: 28px 64px 40px 96px;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(180deg, var(--paper-2), var(--paper) 40%);
  background-size: 40px 40px, 40px 40px, 8px 8px, 8px 8px, 100% 100%;
  background-position: -1px -1px;
  border-radius: 3px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 2px 3px rgba(60, 40, 20, 0.15),
    0 24px 60px -20px rgba(60, 40, 20, 0.45);
}
/* red margin rule, like a hospital form */
.chart::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 72px;
  width: 2px; background: rgba(200, 40, 47, 0.35);
}
.holes { position: absolute; left: 24px; top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: space-around; padding: 80px 0; }
.holes span {
  width: 22px; height: 22px; border-radius: 50%;
  background: #cfc6b4;
  box-shadow: inset 0 2px 4px rgba(60, 40, 20, 0.45), 0 1px 0 rgba(255, 255, 255, 0.6);
}

.masthead {
  display: flex; gap: 24px; align-items: baseline;
  padding-bottom: 14px; margin-bottom: 40px;
  border-bottom: 2px solid var(--ink);
}
.masthead .mono:first-child { font-weight: 700; letter-spacing: 0.18em; }
.masthead .portal { margin-left: auto; text-decoration: none; border-bottom: 1px dashed var(--ink-3); }
.masthead .portal:hover { color: var(--red); border-color: var(--red); }

/* admission */
.admit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 40px;
  align-items: center;
  margin-bottom: 72px;
}
.kicker { display: inline-flex; align-items: center; gap: 8px; text-transform: uppercase; }
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: #1f9d55;
  box-shadow: 0 0 0 0 rgba(31, 157, 85, 0.5);
  animation: ping 2.4s ease-out infinite;
}
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(31, 157, 85, 0.5); } 70%, 100% { box-shadow: 0 0 0 10px rgba(31, 157, 85, 0); } }

.name {
  margin: 6px 0 18px;
  font-family: var(--display);
  font-size: clamp(96px, 17vw, 188px);
  line-height: 0.82;
  font-weight: 900;
  font-variation-settings: "wdth" 78;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--ink);
  transition: font-variation-settings 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.name:hover { font-variation-settings: "wdth" 95; }

.lead { max-width: 34ch; font-size: 20px; line-height: 1.45; margin-bottom: 12px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.btn {
  font-family: var(--mono); font-size: 12px; font-variation-settings: "wdth" 88;
  padding: 10px 14px; border: 1.5px solid var(--ink); border-radius: 2px;
  background: transparent; color: var(--ink); text-decoration: none; cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-hint { opacity: 0.7; }
.btn-hint::before { content: "· "; }

/* wristband */
.band-wrap { position: relative; }
@media (min-width: 901px) { .band-wrap { transform: scale(1.08); transform-origin: 60% 50%; } }
.band {
  position: relative;
  display: flex; align-items: stretch;
  transform: rotate(-6deg);
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  filter: drop-shadow(0 10px 14px rgba(60, 40, 20, 0.25));
  outline: none;
}
.band:hover, .band:focus-visible { transform: rotate(-2deg) translateY(-4px); }
.band-strap {
  width: 56px; flex: none;
  background: repeating-linear-gradient(90deg, var(--band) 0 6px, #eef0f2 6px 7px);
  border: 1px solid var(--band-edge); border-right: 0;
  border-radius: 14px 0 0 14px;
  margin: 10px 0;
}
.band-card {
  flex: 1; min-width: 0;
  background: var(--band);
  border: 1px solid var(--band-edge);
  border-radius: 6px;
  padding: 14px 16px 12px;
  display: grid; gap: 6px;
}
.band-row { display: flex; align-items: baseline; gap: 4px 14px; flex-wrap: wrap; }
.band-pair { white-space: nowrap; }
.band-label { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-3); }
.band-val { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.barcode { height: 34px; margin-top: 4px; display: flex; align-items: stretch; gap: 0; overflow: hidden; min-width: 0; }
.barcode i { flex: none; }
.barcode i { display: block; background: var(--ink); }
.band-alert {
  flex: none; width: 88px;
  background: var(--red); color: #fff;
  border-radius: 6px; margin-left: -4px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  border: 1px solid #a51e24;
}
.band-alert .band-label { color: rgba(255, 255, 255, 0.9); }
.band-snap {
  flex: none; width: 70px; margin: 10px 0 10px -2px;
  background: repeating-linear-gradient(90deg, var(--band) 0 6px, #eef0f2 6px 7px);
  border: 1px solid var(--band-edge); border-left: 0;
  border-radius: 0 14px 14px 0;
  position: relative;
}
.band-snap::after {
  content: ""; position: absolute; right: 16px; top: 50%; translate: 0 -50%;
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #c9ced6);
  border: 1px solid #b9c0ca;
}

.scribble {
  font-family: var(--hand);
  color: var(--blue);
  font-size: 26px;
  line-height: 1;
  transform: rotate(-3deg);
  pointer-events: none;
}
.scribble-band { position: absolute; right: 6%; bottom: -54px; }

/* sections */
.sect { position: relative; margin-bottom: 64px; }
.sect-h {
  display: flex; align-items: baseline; gap: 14px;
  margin: 0 0 20px;
  font-family: var(--display);
  font-size: 34px; font-weight: 800; line-height: 1;
  font-variation-settings: "wdth" 62;
  text-transform: uppercase; letter-spacing: 0.01em;
}
.sect-h .mono {
  font-size: 11px; font-weight: 500; color: var(--paper);
  background: var(--ink); padding: 4px 6px; border-radius: 2px;
  translate: 0 -6px;
}

/* the ward: cases grouped by patient */
.ward { display: grid; gap: 22px; }
.patient {
  background: rgba(251, 249, 243, 0.82);
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  box-shadow: 5px 5px 0 rgba(29, 27, 25, 0.9);
}
.patient-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1.5px solid var(--ink);
  background: repeating-linear-gradient(-45deg, transparent 0 9px, rgba(29, 27, 25, 0.035) 9px 10px);
}
.bed {
  font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
  border: 1px solid var(--ink); padding: 3px 6px; border-radius: 2px;
}
.patient-name {
  font-family: var(--display); font-weight: 800; font-size: 26px; line-height: 1;
  font-variation-settings: "wdth" 75;
}
.redact {
  position: relative; display: inline-block;
  min-width: 7.5em; height: 0.9em; translate: 0 0.08em;
  background: var(--redact);
  border-radius: 1px;
  transform: rotate(-0.6deg);
  cursor: help;
}
.redact::after {
  content: "withheld";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.24em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0);
  transition: color 0.2s;
}
.redact:hover::after, .redact:focus-visible::after { color: rgba(255, 255, 255, 0.7); }
.patient-meta { flex: 1 1 auto; display: flex; align-items: baseline; gap: 6px 14px; flex-wrap: wrap; min-width: 0; }
.patient-kind { font-family: var(--serif); font-style: italic; color: var(--ink-2); }
.patient-stat { font-family: var(--mono); font-size: 12px; font-weight: 600; background: var(--ink); color: var(--paper); padding: 3px 7px; border-radius: 2px; white-space: nowrap; }
.patient-count { margin-left: auto; white-space: nowrap; }

.case {
  position: relative;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  align-items: start; gap: 16px;
  padding: 16px;
  border-top: 1px dashed rgba(29, 27, 25, 0.25);
  transition: background 0.15s;
}
.case:first-of-type { border-top: 0; }
.case:hover, .case:focus-within { background: rgba(200, 40, 47, 0.05); }
.case-date { font-family: var(--mono); font-size: 12px; color: var(--ink-3); font-variation-settings: "wdth" 80; padding-top: 4px; }
.case-title { font-size: 20px; line-height: 1.3; text-decoration: none; }
/* the whole row opens the write-up */
.case-title::after { content: ""; position: absolute; inset: 0; }
.case:hover .case-title { text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: 3px; }
.case-dx { display: block; font-family: var(--hand); font-size: 22px; color: var(--blue); line-height: 1.1; margin-top: 2px; }
.case-desc { margin-top: 6px; font-size: 16px; line-height: 1.45; color: var(--ink-2); max-width: 62ch; }
.case-read { display: inline-block; margin-top: 8px; font-family: var(--mono); font-size: 12px; color: var(--red); border-bottom: 1.5px solid currentColor; }
.case-tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; padding-top: 2px; }
.tag {
  font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 4px 7px; border-radius: 2px; white-space: nowrap;
  border: 1px solid currentColor;
}
.tag-crit { background: var(--red); border-color: var(--red); color: #fff; }
.tag-high { background: var(--amber); border-color: var(--amber); color: #1d1b19; }
.tag-med { background: #f2c94c; border-color: #d9ad25; color: #1d1b19; }
.tag-low { color: var(--ink-2); }
.tag-cve { color: var(--blue); }
.tag-fixed { color: #1f7a44; }
.tag-fixed::before { content: "✓ "; }
.scribble-ward { position: absolute; right: 8px; bottom: -40px; font-size: 24px; transform: rotate(-2deg); }

/* history + meds */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 48px; }

.history { list-style: none; margin: 0; padding: 0; position: relative; }
.history::before { content: ""; position: absolute; left: 76px; top: 8px; bottom: 8px; width: 1.5px; background: var(--ink); }
.history li { display: grid; grid-template-columns: 64px 1fr; gap: 26px; padding: 8px 0; position: relative; }
.history li::before {
  content: ""; position: absolute; left: 71px; top: 15px;
  width: 9px; height: 9px; border-radius: 50%; background: var(--paper); border: 1.5px solid var(--ink);
}
.history li.current::before { background: var(--red); border-color: var(--red); }
.nowrap { white-space: nowrap; }
.h-year { font-family: var(--mono); font-size: 12px; font-weight: 600; padding-top: 3px; text-align: right; }
.h-text { font-size: 17px; }

.meds { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.med { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 12px; }
.pill {
  flex: none; width: 46px; height: 20px; border-radius: 999px;
  background: linear-gradient(90deg, var(--c1) 50%, var(--c2) 50%);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12), inset 0 2px 0 rgba(255, 255, 255, 0.45), 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.med:hover .pill { transform: rotate(-24deg) scale(1.08); }
.med-name { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.med-dose { flex-basis: 100%; padding-left: 58px; font-style: italic; color: var(--ink-2); font-size: 16px; line-height: 1.3; }

.project {
  margin-top: 24px; padding: 14px 16px;
  border: 1.5px dashed var(--ink); border-radius: 3px;
  background: rgba(251, 249, 243, 0.7);
}
.project .mono { display: block; margin-bottom: 4px; }
.project strong { font-family: var(--display); font-variation-settings: "wdth" 80; font-size: 20px; }

/* referral (prescription pad) */
.rx {
  position: relative;
  max-width: 560px;
  padding: 22px 26px 24px;
  background:
    repeating-linear-gradient(180deg, transparent 0 31px, rgba(47, 95, 168, 0.16) 31px 32px),
    #fdfbf5;
  border-top: 10px solid var(--blue);
  box-shadow: 0 2px 3px rgba(60, 40, 20, 0.12), 0 20px 40px -18px rgba(60, 40, 20, 0.4);
  transform: rotate(0.8deg);
}
.rx-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.rx-symbol { font-family: var(--serif); font-size: 58px; line-height: 0.8; color: var(--blue); }
.rx-to { font-size: 14px; font-weight: 600; }
.rx-body { font-family: var(--hand); font-size: 32px; line-height: 1; color: var(--ink); margin-bottom: 10px; }
.rx-sig { color: var(--ink-2); }
.rx-row { display: flex; align-items: center; gap: 40px; flex-wrap: wrap; }
.rx { flex: 0 1 560px; }
.scribble-rx { font-size: 34px; color: var(--red); transform: rotate(-6deg); }

.foot {
  display: flex; gap: 20px; flex-wrap: wrap;
  padding-top: 16px; border-top: 2px solid var(--ink);
}
.foot a { text-decoration: none; border-bottom: 1px dashed var(--ink-3); }
.foot a:hover { color: var(--red); }
.foot span { margin-right: auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; translate: -50% 20px;
  background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 2px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, translate 0.2s;
}
.toast.show { opacity: 1; translate: -50% 0; }

/* small screens */
@media (max-width: 900px) {
  .chart { margin: 0; padding: 20px 16px 32px 16px; border-radius: 0; }
  .chart::before, .holes { display: none; }
  .admit { grid-template-columns: minmax(0, 1fr); gap: 40px; }
  .band-wrap { padding: 0 6px 40px; }
  .scribble-band { right: 12px; bottom: -8px; }
  .split { grid-template-columns: 1fr; }
  .rx { transform: none; }
}
@media (max-width: 600px) {
  body { font-size: 17px; }
  .masthead { gap: 12px; flex-wrap: wrap; }
  .masthead .dim { display: none; }
  .band-strap { width: 28px; }
  .band-snap { width: 40px; }
  .band-snap::after { right: 10px; }
  .band-alert { width: 64px; font-size: 10px; }
  .band-val { font-size: 12px; margin-right: 6px; }
  .case { grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 14px 12px; }
  .case-tags { justify-content: flex-start; order: 2; }
  .case-main { order: 3; }
  .patient-head { padding: 12px; gap: 8px 12px; }
  .patient-meta { flex-basis: 100%; }
  .band-label { font-size: 10px; }
  .scribble-ward { position: static; margin-top: 14px; }
  .history::before { left: 60px; }
  .history li { grid-template-columns: 48px 1fr; }
  .history li::before { left: 55px; }
  .patient-count { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
