/* ===========================================================================
   The House of Piranesi · Differential — stylesheet
   Voice: an engraved frontispiece. Parchment ground, ink text, the bronze of
   the canonical mark (#C39C72) as the single brand accent. EB Garamond carries
   the classical register; IBM Plex carries the data. Light and dark halls.
   =========================================================================== */

@font-face {
  font-family: "EB Garamond"; font-style: normal; font-weight: 400 700;
  font-display: swap; src: url("/assets/fonts/eb-garamond-latin-wght-normal.woff2") format("woff2");
}
@font-face {
  font-family: "EB Garamond"; font-style: italic; font-weight: 400 700;
  font-display: swap; src: url("/assets/fonts/eb-garamond-latin-wght-italic.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans"; font-style: normal; font-weight: 300 600;
  font-display: swap; src: url("/assets/fonts/ibm-plex-sans-latin-wght-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400;
  font-display: swap; src: url("/assets/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono"; font-style: normal; font-weight: 600;
  font-display: swap; src: url("/assets/fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2");
}

:root {
  color-scheme: light dark;
  --brand:       #c39c72;   /* the mark's bronze — fixed across schemes */
  --brand-deep:  #a47b4e;
  --brand-soft:  rgba(195, 156, 114, 0.16);

  --paper:       #f5efe2;
  --paper-deep:  #ebe2cd;
  --panel:       #fbf7ec;
  --ink:         #262014;
  --ink-soft:    #5d5340;
  --ink-faint:   #91836a;
  --line:        #d4c8a8;
  --line-soft:   #e3dabf;
  --green:       #3f6f37;
  --green-soft:  rgba(63, 111, 55, 0.12);
  --red:         #9b2c2c;
  --red-soft:    rgba(155, 44, 44, 0.10);
  --shadow:      rgba(46, 35, 16, 0.16);
  --grid:        rgba(120, 96, 48, 0.022);

  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --sans:  "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono:  "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #0e0f13;
    --paper-deep: #171922;
    --panel:      #14161d;
    --ink:        #ece3d0;
    --ink-soft:   #b3a88e;
    --ink-faint:  #7d7460;
    --line:       #2c2f3a;
    --line-soft:  #22242e;
    --green:      #6abd6a;
    --green-soft: rgba(106, 189, 106, 0.12);
    --red:        #f08c8c;
    --red-soft:   rgba(240, 140, 140, 0.10);
    --shadow:     rgba(0, 0, 0, 0.5);
    --grid:       rgba(195, 156, 114, 0.03);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* `hidden` must win over the display:flex class rules below (same specificity,
   so source order would otherwise keep flex elements visible when hidden). */
[hidden] { display: none !important; }

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  background-color: var(--paper);
  background-image:
    radial-gradient(110% 70% at 50% -8%, var(--panel), transparent 62%),
    repeating-linear-gradient(0deg, transparent 0 40px, var(--grid) 40px 41px),
    repeating-linear-gradient(90deg, transparent 0 40px, var(--grid) 40px 41px);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--brand); color: var(--paper); }

:is(button, input, textarea, a):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

.hall {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 44px 20px 132px;
}

/* ----------------------------------------------------------- console (hero) */
.console {
  width: 100%;
  max-width: 660px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: rise 0.55s ease both;
}

.emblem {
  width: 148px;
  filter: drop-shadow(0 10px 22px var(--shadow));
}
.emblem svg { width: 100%; height: auto; display: block; }

.wordmark {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.15rem, 5vw, 3.05rem);
  letter-spacing: 0.012em;
  margin: 20px 0 6px;
  line-height: 1.04;
}
.subwordmark {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.34em;
  text-indent: 0.34em; /* re-centers letterspaced text */
  color: var(--brand-deep);
  margin: 0 0 40px;
}

/* --------------------------------------------------------------- presentation */
.presentation { width: 100%; display: flex; flex-direction: column; gap: 24px; }

.field { text-align: left; }
.field-title {
  display: block;
  font-family: var(--sans);
  font-size: 1.22rem;
  font-weight: 600;
  margin: 0 0 9px 6px;
  letter-spacing: 0.01em;
}
.field-hint { font-size: 0.8rem; color: var(--ink-faint); margin: 8px 6px 0; }
.field-hint kbd {
  font-family: var(--mono); font-size: 0.72rem; background: var(--paper-deep);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px;
}

/* the search box — Google-homepage treatment */
.tagbox {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 12px 16px;
  box-shadow: 0 1px 3px var(--shadow);
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}
.tagbox:hover { box-shadow: 0 4px 14px var(--shadow); }
.tagbox:focus-within {
  border-color: var(--brand);
  box-shadow: 0 6px 22px var(--shadow), 0 0 0 4px var(--brand-soft);
}

.tag-chips { list-style: none; display: flex; flex-wrap: wrap; gap: 7px; margin: 0; padding: 0; }
.tag-chips:not(:empty) { margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--brand-soft);
  border: 1px solid var(--brand);
  border-radius: 999px;
  padding: 4px 6px 4px 13px;
  font-size: 0.92rem;
  animation: pop 0.16s ease both;
}
.chip button {
  border: none; background: transparent; cursor: pointer;
  width: 20px; height: 20px; border-radius: 50%;
  color: var(--ink-soft); font-size: 1.02rem; line-height: 1;
  display: grid; place-items: center; padding: 0;
}
.chip button:hover { background: var(--brand-deep); color: var(--paper); }

.entry { position: relative; }
.tag-input {
  width: 100%; border: none; outline: none; background: transparent;
  font-family: var(--sans); font-size: 1.05rem; color: var(--ink);
  padding: 5px 4px; caret-color: var(--brand-deep);
}
.tag-input::placeholder { color: var(--ink-faint); font-style: italic; }
.tag-input:focus-visible { outline: none; }

.tag-suggestions {
  position: absolute; left: -16px; right: -16px; top: calc(100% + 12px);
  z-index: 20; list-style: none; margin: 0; padding: 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 22px 48px -16px var(--shadow);
  max-height: 330px; overflow-y: auto;
}
.tag-suggestions li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 14px; border-radius: 11px; cursor: pointer;
}
.tag-suggestions li.active, .tag-suggestions li:hover { background: var(--brand-soft); }
.tag-suggestions .s-term { font-size: 0.98rem; }
.tag-suggestions .s-term mark { background: transparent; color: var(--brand-deep); font-weight: 600; }
.tag-suggestions .s-cat { margin-left: auto; flex-shrink: 0; font-size: 0.72rem; color: var(--ink-faint); font-family: var(--mono); }
.tag-suggestions .s-new { color: var(--brand-deep); font-weight: 500; }
.tag-suggestions .s-alias { font-style: italic; color: var(--ink-faint); font-size: 0.82rem; }

textarea#comments, .feedback-box textarea, .feedback-box input {
  width: 100%; font-family: var(--sans); font-size: 1rem; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 13px 16px; resize: vertical; outline: none;
  box-shadow: 0 1px 3px var(--shadow);
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}
textarea#comments::placeholder { color: var(--ink-faint); font-style: italic; }
textarea#comments:focus, .feedback-box textarea:focus, .feedback-box input:focus {
  border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft);
}

/* collapsible optional context fields (conditions / medications / vitals) */
.more-fields { display: flex; flex-direction: column; gap: 10px; }
.more-field {
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel);
  box-shadow: 0 1px 3px var(--shadow); overflow: visible;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.more-field > summary {
  cursor: pointer; list-style: none; padding: 12px 16px; user-select: none;
  font-family: var(--sans); font-size: 1rem; font-weight: 500; color: var(--ink-soft);
  display: flex; align-items: center; gap: 11px;
}
.more-field > summary::-webkit-details-marker { display: none; }
.more-field > summary::before {
  content: "\203A"; font-family: var(--mono); font-size: 1.15rem; line-height: 1;
  color: var(--brand-deep); transition: transform 0.15s ease;
}
.more-field[open] > summary::before { transform: rotate(90deg); }
.more-field[open] > summary { border-bottom: 1px solid var(--line-soft); }
.more-field .opt { margin-left: auto; font-size: 0.74rem; font-weight: 400;
  font-style: italic; color: var(--ink-faint); }
.more-field textarea {
  width: 100%; border: none; background: transparent; box-shadow: none;
  border-radius: 0; padding: 12px 16px; resize: vertical; outline: none;
  font-family: var(--sans); font-size: 1rem; color: var(--ink);
}
.more-field textarea::placeholder { color: var(--ink-faint); font-style: italic; }
.more-field:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

/* body inside an opened context field */
.more-body { padding: 13px 14px 14px; }
.more-hint { font-size: 0.78rem; color: var(--ink-faint); margin: 9px 4px 0; }
.more-hint kbd { font-family: var(--mono); font-size: 0.7rem; background: var(--paper-deep);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

/* the in-details tag boxes (conditions / medications) — lighter than the hero */
.tagbox.plain { border-radius: 12px; box-shadow: none; padding: 9px 12px; }
.tagbox.plain:focus-within { box-shadow: none; border-color: var(--brand); }
.tagbox.plain .tag-suggestions { left: -1px; right: -1px; }

/* vitals form — a grid of labelled measurement inputs */
.vitals-form {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
}
.vital { display: flex; flex-direction: column; gap: 5px; font-size: 0.86rem; color: var(--ink-soft); }
.vital-bp { grid-column: 1 / -1; }
.vital > span:first-child { padding-left: 2px; }
.vin {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 11px; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.vin:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.vin input {
  width: 100%; min-width: 0; border: none; outline: none; background: transparent;
  font-family: var(--mono); font-size: 1rem; color: var(--ink); padding: 2px 0;
  -moz-appearance: textfield;
}
.vin input::-webkit-outer-spin-button, .vin input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.vin input::placeholder { color: var(--ink-faint); }
.vin em { font-style: normal; font-family: var(--mono); font-size: 0.8rem; color: var(--ink-faint); white-space: nowrap; }
.vital-bp .vin input { text-align: center; }

.recap-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 9px; }
.recap-row-label { font-size: 0.82rem; font-weight: 600; color: var(--ink); margin-right: 4px; }
.recap-extra { margin: 9px 2px 0; font-size: 0.92rem; color: var(--ink-soft); line-height: 1.45; }
.recap-extra-label { font-weight: 600; color: var(--ink); }

.actions { display: flex; justify-content: center; align-items: center; gap: 18px; margin-top: 6px; flex-wrap: wrap; }

/* engage-LLM switch — the LLM is an opt-in overlay on the algorithmic flowchart */
.llm-toggle { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.llm-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.llm-switch {
  position: relative; width: 38px; height: 22px; border-radius: 999px; flex-shrink: 0;
  background: var(--paper-deep); border: 1px solid var(--line); transition: background 0.18s, border-color 0.18s;
}
.llm-switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink-faint); transition: transform 0.18s, background 0.18s;
}
.llm-toggle input:checked + .llm-switch { background: var(--brand-soft); border-color: var(--brand); }
.llm-toggle input:checked + .llm-switch::after { transform: translateX(16px); background: var(--brand-deep); }
.llm-toggle input:focus-visible + .llm-switch { outline: 2px solid var(--brand); outline-offset: 2px; }
.llm-text {
  font-size: 0.82rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft);
  transition: color 0.18s;
}
.llm-toggle input:checked ~ .llm-text { color: var(--brand-deep); font-weight: 600; }
.consult {
  font-family: var(--sans); font-size: 1.16rem; font-weight: 600;
  color: #fbf7ec; background: var(--brand-deep);
  border: 1px solid var(--brand-deep); border-radius: 999px;
  padding: 12px 36px; cursor: pointer; letter-spacing: 0.02em;
  box-shadow: 0 12px 28px -14px var(--brand-deep);
  transition: transform 0.12s, background 0.16s, box-shadow 0.16s;
}
.consult:hover { background: var(--brand); border-color: var(--brand); transform: translateY(-1px); }
.consult:active { transform: translateY(0); }
.consult:disabled { opacity: 0.45; cursor: progress; transform: none; }
.small-consult { font-size: 1rem; padding: 9px 24px; }

.ghost-btn {
  font-family: var(--sans); font-size: 0.92rem; color: var(--ink-soft);
  background: transparent; border: none; cursor: pointer; padding: 8px 10px;
  border-radius: 8px;
}
.ghost-btn:hover { color: var(--brand-deep); background: var(--brand-soft); }

/* ------------------------------------------------------------------- results */
.results { width: 100%; max-width: 740px; animation: rise 0.45s ease both; }
.results .ghost-btn { margin-bottom: 12px; margin-left: -10px; }

.recap {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--brand);
  border-radius: 14px; padding: 15px 19px; margin-bottom: 24px;
  box-shadow: 0 8px 26px -22px var(--shadow);
}
.recap h2 {
  font-family: var(--sans); font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.18em; color: var(--ink-faint); margin: 0 0 10px;
}
.recap .recap-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.recap .recap-tag { background: var(--brand-soft); border: 1px solid var(--brand);
  border-radius: 999px; padding: 2px 12px; font-size: 0.86rem; }
.recap .recap-comments { font-style: italic; color: var(--ink-soft); font-family: var(--sans);
  font-size: 1.06rem; margin: 10px 2px 2px; }

.deliberating { text-align: center; padding: 44px 0 36px; color: var(--ink-soft); }
.deliberating p { font-family: var(--sans); font-size: 1.14rem; font-style: italic; margin: 6px auto; max-width: 30em; }
.lantern {
  width: 36px; height: 36px; margin: 0 auto 20px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}

.dx-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline;
  margin-bottom: 18px; font-size: 0.85rem; color: var(--ink-soft); }
.dx-meta .badge { font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.06em; background: var(--paper-deep); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 9px; }
.dx-meta .badge.calibrated { color: var(--green); border-color: var(--green); background: var(--green-soft); }
.dx-meta .badge.mock { color: var(--red); border-color: var(--red); background: var(--red-soft); }

.section-title { font-family: var(--sans); font-size: 1.5rem; font-weight: 600; margin: 2px 0 14px; }

.dx { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 13px; }
.dx-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 19px; box-shadow: 0 10px 30px -24px var(--shadow);
  animation: rise 0.4s ease both;
}
.dx-card.top { border-color: var(--brand); border-left-width: 3px; }
.dx-head { display: flex; align-items: baseline; gap: 11px; flex-wrap: wrap; }
.dx-rank { font-family: var(--mono); font-size: 0.8rem; color: var(--brand-deep); }
.dx-name { font-family: var(--sans); font-size: 1.32rem; font-weight: 600; flex: 1; min-width: 10em; }
.dx-icd { font-family: var(--mono); font-size: 0.78rem; color: var(--ink-soft);
  background: var(--paper-deep); border-radius: 5px; padding: 1px 8px; white-space: nowrap; }
.dx-prob-row { display: flex; align-items: center; gap: 13px; margin: 11px 0 8px; }
.dx-bar { flex: 1; height: 8px; background: var(--paper-deep); border-radius: 999px; overflow: hidden; }
.dx-bar > span { display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--brand-deep)); }
.dx-prob { font-family: var(--mono); font-size: 0.95rem; font-weight: 600; min-width: 3.2em; text-align: right; }
.dx-reason { color: var(--ink-soft); margin: 7px 0 11px; font-size: 0.95rem; }
.dx-cites { display: flex; flex-wrap: wrap; gap: 6px; }
.cite {
  font-family: var(--mono); font-size: 0.73rem; text-decoration: none;
  border: 1px solid var(--green); color: var(--green); background: var(--green-soft);
  border-radius: 7px; padding: 2.5px 10px; display: inline-flex; gap: 5px; align-items: center;
}
.cite.unverified { border-color: var(--line); color: var(--ink-faint); background: transparent; }
.cite:hover { filter: brightness(1.08); }
.other-mass { font-size: 0.84rem; color: var(--ink-faint); font-family: var(--mono);
  text-align: right; margin: 11px 6px 0; }

.narrative-note { font-size: 0.86rem; color: var(--ink-soft); font-family: var(--sans);
  font-style: italic; margin: 10px 6px 0; padding-left: 10px;
  border-left: 2px solid var(--brand); }

.abstain-note { background: var(--paper-deep); border: 1px dashed var(--line); border-radius: 12px;
  padding: 14px 18px; color: var(--ink-soft); font-style: italic; font-family: var(--sans); font-size: 1.05rem; }

/* feedback */
.feedback { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line-soft); }
.feedback-q { font-family: var(--sans); font-size: 1.3rem; font-weight: 600; text-align: center; margin: 0 0 16px; }
.thumbs { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.thumb {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--sans); font-size: 1rem; cursor: pointer; color: var(--ink-soft);
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 999px; padding: 10px 26px;
  transition: transform 0.12s, border-color 0.15s, background 0.15s, color 0.15s;
  box-shadow: 0 2px 6px var(--shadow);
}
.thumb .ico { font-size: 1.25rem; }
.thumb:hover { transform: translateY(-1px); }
.thumb-up.sel, .thumb-up:hover { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.thumb-down.sel, .thumb-down:hover { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.thumb.sel { font-weight: 600; }

.feedback-box { margin-top: 20px; display: flex; flex-direction: column; gap: 14px;
  max-width: 540px; margin-left: auto; margin-right: auto; align-items: stretch; }
.feedback-box .small-consult { align-self: center; }
.verdict-hint { font-size: 0.85rem; color: var(--brand-deep); text-align: center; margin: 0; }
.detail-row { display: flex; flex-direction: column; gap: 5px; text-align: left; }
.detail-row > span { font-size: 0.88rem; color: var(--ink-soft); }
.detail-row em { color: var(--ink-faint); font-style: italic; }
.feedback-thanks { text-align: center; font-family: var(--sans); font-style: italic;
  font-size: 1.12rem; color: var(--green); margin-top: 18px; }

/* footer */
.disclaimer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-top: 1px solid var(--line-soft);
  padding: 11px 20px 13px; text-align: center;
}
.disclaimer p { max-width: 920px; margin: 0 auto; font-size: 0.72rem; line-height: 1.5; color: var(--ink-faint); }
.disclaimer strong { color: var(--ink-soft); letter-spacing: 0.04em; }

.muted { color: var(--ink-faint); }
.small { font-size: 0.85rem; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop  { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 560px) {
  .hall { padding: 26px 14px 158px; }
  .wordmark { font-size: 2.05rem; }
  .subwordmark { letter-spacing: 0.22em; text-indent: 0.22em; }
  .emblem { width: 116px; }
  .tag-suggestions { left: -10px; right: -10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
