:root {
  --page: #f4f5f8;
  --surface: #ffffff;

  --ink: #0e0f17;
  --ink-muted: #4f5565;

  --line: #d6dae4;
  --line-strong: #4f5565;

  --accent: #5b4cf0;
  --accent-strong: #3f32c4;
  --accent-pale: #eceafe;
  --accent-gradient: linear-gradient(100deg, #5b4cf0, #1b7aa8);
  --accent-gradient-strong: linear-gradient(100deg, #3f32c4, #145f84);

  --error: #b42318;
  --error-bg: #fdf2f1;
  --error-ink: #8f1c13;

  --caution: #a86a00;
  --caution-bg: #fdf3d8;
  --caution-ink: #6d4b00;

  --font-sans: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --title-weight: 800;
  --status-size: 0.75rem;
  --status-tracking: 0.08em;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;

  --radius-card: 1rem;
  --radius-control: 0.5rem;
  --radius-pill: 9999px;

  --shadow-card: 0 1px 2px color-mix(in srgb, var(--ink) 6%, transparent),
    0 0.5rem 1.5rem color-mix(in srgb, var(--ink) 8%, transparent);

  --measure: min(52rem, calc(100% - 2rem));

  color-scheme: light;
  accent-color: var(--accent);
  font-family: var(--font-sans);
  line-height: 1.6;
  color: var(--ink);
  background: var(--page);
}

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

body {
  margin: 0;
  overflow-wrap: break-word;
}

body::before {
  content: "";
  display: block;
  height: 4px;
  background: var(--accent);
}

.container {
  width: var(--measure);
  margin-inline: auto;
  padding-block: 1.5rem;
}

h1 {
  max-width: 24ch;
  margin-block: 0 1rem;
  color: var(--ink);
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: var(--title-weight);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h2 {
  margin-block: 2rem 0.75rem;
  color: var(--ink);
  font-size: 1.375rem;
}

p {
  max-width: 70ch;
}

a {
  color: var(--accent);
}

a:hover {
  color: var(--accent-strong);
}

form {
  margin-top: 2rem;
}

fieldset,
.photo-field,
.boxed-field,
.card {
  margin: 0 0 var(--space-5);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

/* A legend sits in a gap cut out of the top border, so one long enough to wrap
   on a phone leaves its first line stranded outside the box. Floating it takes
   it out of the cut-out and puts it inside, where it can wrap. */
legend {
  float: left;
  width: 100%;
  margin-bottom: 0.75rem;
  color: var(--ink);
  font-weight: 700;
}

legend + * {
  clear: both;
}

fieldset::after {
  content: "";
  display: table;
  clear: both;
}

fieldset fieldset {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

.rows {
  list-style: none;
  padding-left: 0;
}

.rows > li:only-child [name^="remove"] {
  display: none;
}

fieldset .rows > li + li {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.rows > li {
  position: relative;
  max-width: 26rem;
}

.rows button.button-remove {
  position: absolute;
  top: 0;
  right: 0;
  padding: var(--space-1) var(--space-2);
  border: 0;
  background: none;
  color: var(--accent-strong);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: underline;
}

fieldset .rows > li + li > .button-remove,
fieldset .rows > li + li > fieldset > .button-remove {
  top: var(--space-4);
}

.rows > li > .field:first-child > label:first-child,
.rows > li > fieldset > legend {
  padding-right: 5rem;
}

.rows button.button-remove:hover {
  background: var(--accent-pale);
}

.photo-field {
  border-style: dashed;
  box-shadow: none;
}

#reproductive-health:has(#intake_reproductive_health_hysterectomy_oophorectomy_or_menopause_true:checked) #conception {
  display: none;
}

#medications:not(:has(#intake_medical_history_no_medications_false:checked)) #medication-entries,
#allergies:not(:has(#intake_medical_history_no_allergies_false:checked)) #allergy-entries,
#intake_medical_history_isotretinoin_use:not(:has(#intake_medical_history_isotretinoin_use_past:checked)) + #isotretinoin-month {
  display: none;
}

.photo-field label {
  display: block;
  margin: 1rem 0 0.25rem;
  font-weight: 600;
}

input[type="file"] {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 26rem;
  padding: 0.5rem;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  font: inherit;
}

input[type="file"]::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--page);
  color: var(--accent-strong);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--accent-pale);
}

.visually-hidden {
  position: absolute;
  overflow: hidden;
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  padding: 0.5rem 1rem;
  background: var(--surface);
  color: var(--ink);
  transform: translateY(-100%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  align-items: center;
  justify-content: space-between;
  width: var(--measure);
  margin-inline: auto;
  padding-block: 1rem;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  font-weight: 700;
}

.account {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: baseline;
  color: var(--ink-muted);
}

.account form {
  margin: 0;
}

.account button[type="submit"] {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 400;
  text-decoration: underline;
  cursor: pointer;
}

.field {
  margin: 0 0 1rem;
}

.field label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  max-width: 26rem;
  padding: 0.625rem 0.75rem;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: inherit;
  font: inherit;
}

.field textarea {
  min-height: 7rem;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.field-row select {
  width: auto;
  min-width: 0;
}

.field input[type="radio"] {
  flex: none;
  width: auto;
}

/* A wrapped radio label reads as a second choice unless its lines stay off the
   control, so the row is a flex pair rather than an inline one. */
.field:has(input[type="radio"]) {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.field:has(input[type="radio"]) label {
  margin-bottom: 0;
  font-weight: 400;
}

::placeholder {
  color: var(--ink-muted);
  opacity: 1;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--error);
  background: var(--error-bg);
}

.hint {
  display: block;
  margin: 0.25rem 0 0;
  color: var(--ink-muted);
}

.hint[hidden] {
  display: none;
}

.choice {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.choice input {
  width: auto;
  margin-inline-start: 0;
}

.reveals-other:has(option[value="other"]:not(:checked)) .other-detail {
  display: none;
}

.choice:has(> .hint) {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: var(--space-2);
}

.choice > .hint {
  grid-column: 2;
  padding-inline-start: var(--space-5);
}

[role="listbox"] {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
}

[role="option"] {
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

[role="option"][aria-selected="true"] {
  color: var(--surface);
  background: var(--accent-strong);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
  margin-top: 2rem;
}

.actions label:not([hidden]) {
  display: grid;
  flex: 1;
  align-items: center;
  color: var(--accent-strong);
  font-weight: 700;
}

.actions label > * {
  grid-area: 1 / 1;
}

.actions label span {
  justify-self: center;
  pointer-events: none;
}

.actions input[type="range"] {
  appearance: none;
  height: 3rem;
  margin: 0;
  padding: 0 0.125rem;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  background: var(--accent-pale);
  cursor: pointer;
}

.actions input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--accent-gradient);
}

.actions input[type="range"]::-moz-range-thumb {
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 50%;
  background: var(--accent-gradient);
}

input[type="submit"],
button[type="submit"],
.actions a {
  padding: 0.75rem 1.25rem;
  border: 2px solid var(--accent);
  border-radius: var(--radius-control);
  color: var(--surface);
  font: inherit;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

input[type="submit"],
button[type="submit"] {
  border-color: transparent;
  background: var(--accent-gradient);
}

.actions a,
button.button-secondary {
  border-width: 1px;
  border-color: var(--line-strong);
  background: transparent;
  color: var(--accent-strong);
  font-weight: 600;
}

input[type="submit"]:hover,
button[type="submit"]:hover {
  background: var(--accent-gradient-strong);
}

.actions a:hover,
button.button-secondary:hover {
  background: var(--accent-pale);
  color: var(--accent-strong);
}

:where(input, select, textarea) {
  scroll-margin-top: 6rem;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px var(--surface);
  border-radius: var(--radius-control);
}

.flash {
  width: var(--measure);
  margin: 1.5rem auto 0;
}

.container > .flash {
  width: auto;
  margin-inline: 0;
}

.alert,
.notice,
.status-caution,
.field-error {
  position: relative;
  max-width: none;
  margin-block: 0 var(--space-5);
  padding: 0.75rem 1rem 0.75rem 3rem;
  border: 1px solid;
  border-left-width: 4px;
  border-radius: var(--radius-card);
}

.alert::before,
.notice::before,
.status-caution::before,
.field-error::before {
  content: "";
  position: absolute;
  top: 0.85rem;
  left: 1rem;
  width: 1.25rem;
  height: 1.25rem;
  mask-repeat: no-repeat;
  mask-size: contain;
}

.notice {
  border-color: var(--accent);
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.notice::before {
  background-color: var(--accent);
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill-rule='evenodd'%3E%3Cpath d='M10 0a10 10 0 100 20 10 10 0 000-20zM8.6 15.2 3.3 9.9l1.9-1.9 3.4 3.4 5.9-5.9 1.9 1.9-7.8 7.8z'/%3E%3C/svg%3E");
}

.status-caution {
  border-color: var(--caution);
  background: var(--caution-bg);
  color: var(--caution-ink);
}

.status-caution::before {
  background-color: var(--caution-ink);
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill-rule='evenodd'%3E%3Cpath d='M10 1 19.6 18.5H.4L10 1zm1.2 12.6H8.8v3h2.4v-3zm0-6.4H8.8v5.2h2.4V7.2z'/%3E%3C/svg%3E");
}

.alert,
.field-error {
  border-color: var(--error);
  background: var(--error-bg);
  color: var(--error-ink);
}

.alert::before,
.field-error::before {
  background-color: var(--error);
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill-rule='evenodd'%3E%3Cpath d='M10 0a10 10 0 100 20 10 10 0 000-20zm1.2 15.4H8.8v-2.6h2.4v2.6zm0-4.2H8.8V4.4h2.4v6.8z'/%3E%3C/svg%3E");
}

.field-error {
  max-width: 26rem;
  margin: 0.375rem 0 0;
  padding: 0.375rem 0.625rem 0.375rem 2.25rem;
  border-radius: var(--radius-control);
}

.field-error::before {
  top: 0.5rem;
  left: 0.625rem;
  width: 1rem;
  height: 1rem;
}

.alert p,
.notice p,
.status-caution p,
.field-error p {
  max-width: none;
  margin-block: 0;
}

.alert ul {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

.table-scroll {
  overflow-x: auto;
  margin-block: 2rem var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  background:
    linear-gradient(to right, var(--surface) 40%, transparent) left
      center / 2rem 100% no-repeat local,
    linear-gradient(to left, var(--surface) 40%, transparent) right
      center / 2rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, color-mix(in srgb, var(--ink) 20%, transparent), transparent)
      left center / 0.75rem 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, color-mix(in srgb, var(--ink) 20%, transparent), transparent)
      right center / 0.75rem 100% no-repeat scroll,
    var(--surface);
}

table {
  width: 100%;
  min-width: 44rem;
  border-collapse: collapse;
}

td:has(p) {
  min-width: 13rem;
}

caption {
  padding: var(--space-3);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  font-weight: 700;
}

th,
td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

thead th {
  background: var(--page);
  color: var(--ink);
  white-space: nowrap;
}

tbody th[scope="row"] {
  color: var(--ink);
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

/* The min-width above keeps the wide clinical tables readable, but it is wider
   than the page, so a table of short columns would scroll for no reason. */
.table-narrow {
  min-width: 0;
}

dt {
  margin-top: 0.75rem;
  color: var(--ink-muted);
}

dd {
  margin-left: 0;
}

td p {
  margin-block: 0.25rem 0;
  color: var(--ink-muted);
}

main ol:not(.checklist) {
  max-width: 70ch;
  padding-left: 1.5rem;
}

main ol:not(.checklist) li {
  margin-bottom: 0.75rem;
}

.case-layout,
.review-layout {
  display: grid;
  gap: 2rem;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

/* A grid item carries its own top margin into the row, so a column that opens
   with an action row or a table starts lower than the rail beside it. */
:is(.case-layout, .review-layout) > *,
:is(.case-layout, .review-layout) > * > :first-child {
  margin-top: 0;
}

.case-rail > :last-child {
  margin-bottom: 0;
}

.case-rail :is(.actions, form) {
  margin-top: 0;
}

.card > h2:first-child {
  margin-top: 0;
}

.card .table-scroll {
  margin-block: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.photo-packet {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  padding: 0;
  list-style: none;
}

.photo-packet li {
  margin-bottom: 0;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.photo-packet figure {
  margin: 0;
}

.photo-packet img {
  display: block;
  max-width: 100%;
  max-height: 14rem;
  margin-inline: auto;
  border-radius: var(--radius-control);
  background: var(--page);
}

.photo-packet figcaption {
  margin-top: var(--space-2);
  color: var(--ink-muted);
}

.badge {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--page);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: var(--status-size);
  letter-spacing: var(--status-tracking);
  text-transform: uppercase;
}

.badge-flagged {
  background: var(--caution-bg);
  color: var(--caution-ink);
}

.checklist {
  padding-left: 0;
  list-style: none;
}

.checklist li {
  display: flex;
  gap: var(--space-3);
  align-items: baseline;
  padding-block: var(--space-2);
  border-bottom: 1px solid var(--line);
  color: var(--ink-muted);
}

.checklist li::before {
  flex: none;
  width: var(--space-4);
  content: "\25CB" / "";
  text-align: center;
}

.checklist li:last-child {
  border-bottom: 0;
}

.checklist .done::before {
  content: "\2713" / "";
  color: var(--accent);
}

.checklist .current {
  color: var(--ink);
  font-weight: 700;
}

.checklist.steps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.checklist.steps li {
  padding-block: 0;
  border-bottom: 0;
}

.toast {
  display: flex;
  gap: var(--space-3);
  margin-block: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-card);
  background: var(--ink);
  color: var(--surface);
}

@media (min-width: 30rem) {
  .actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
  }
}

@media (min-width: 48rem) {
  .container {
    padding-block: 3rem;
  }

  h2 {
    margin-block: 2.5rem 1rem;
  }

  table {
    min-width: 60rem;
  }

  td:has(p) {
    min-width: 18rem;
  }

  .card dl {
    display: grid;
    grid-template-columns: minmax(0, 14rem) minmax(0, 1fr);
    column-gap: var(--space-4);
  }

  .card dd {
    margin-top: 0.75rem;
  }

  caption {
    padding: var(--space-4);
  }

  th,
  td {
    padding: var(--space-3) var(--space-4);
  }
}

@media (min-width: 54rem) {
  .case-layout {
    grid-template-columns: 16rem minmax(0, 1fr);
  }

  .review-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .case-rail dl {
    display: block;
  }

  .case-rail dd {
    margin-top: 0;
  }

  /* A sticky box scrolls with its parent and grows no scrollbar of its own,
     so a rail taller than the window is capped to it and scrolls itself. */
  .case-rail {
    position: sticky;
    top: 1.5rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
  }
}
