:root {
  --bg: #f6f5f1; --surface: #ffffff; --ink: #1b1c1e; --muted: #5f636a; --faint: #8a8e95;
  --line: #e3e1da; --chip: #eeede7; --accent: #1f5f8b; --accent-ink: #ffffff; --accent-soft: #e5eef5;
  --warn: #9b3a2c; --warn-soft: #fbeeea; --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 4px 16px rgba(20, 20, 20, .04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131416; --surface: #1b1d20; --ink: #eceae6; --muted: #a0a4ab; --faint: #7c8087;
    --line: #2b2e32; --chip: #25282c; --accent: #82b6dc; --accent-ink: #0f1a22; --accent-soft: #1b2a36;
    --warn: #f0a292; --warn-soft: #36211d; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131416; --surface: #1b1d20; --ink: #eceae6; --muted: #a0a4ab; --faint: #7c8087;
  --line: #2b2e32; --chip: #25282c; --accent: #82b6dc; --accent-ink: #0f1a22; --accent-soft: #1b2a36;
  --warn: #f0a292; --warn-soft: #36211d; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 48px; outline: none; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -.01em; color: var(--ink); text-decoration: none; font-size: 17px; }
.patient-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 600;
}
.patient-btn span { min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--chip); text-align: center; font-size: 13px; }
.patient-btn.has span { background: var(--accent); color: var(--accent-ink); }

.foot { max-width: 1080px; margin: 0 auto; padding: 16px 16px 32px; color: var(--faint); font-size: 13px; border-top: 1px solid var(--line); }

/* Home */
.intro h1 { font-size: clamp(24px, 4vw, 32px); line-height: 1.2; letter-spacing: -.02em; margin: 8px 0 6px; }
.intro p { margin: 0 0 18px; color: var(--muted); max-width: 62ch; }
.search {
  width: 100%; padding: 13px 16px; font-size: 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 6px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.fchip {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; cursor: pointer; white-space: nowrap;
}
.fchip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.meta-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; margin: 8px 0 14px; flex-wrap: wrap; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 14px 48px 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); text-decoration: none; color: var(--ink);
  transition: border-color .15s, transform .15s;
}
.tile:hover { border-color: var(--accent); }
.tile h3 { margin: 0; font-size: 16px; line-height: 1.3; }
.tile p { margin: 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sys { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.sys::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--faint)); }
.add {
  position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 18px; line-height: 1; display: grid; place-items: center; color: var(--muted);
}
.add[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.empty { padding: 32px 0; color: var(--muted); text-align: center; }

/* Card */
.back { display: inline-block; margin-bottom: 14px; font-size: 14px; text-decoration: none; }
.card-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.card-head h1 { font-size: clamp(26px, 4.4vw, 36px); line-height: 1.15; letter-spacing: -.02em; margin: 6px 0 4px; }
.aka { color: var(--muted); font-size: 14px; margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }
.tag { padding: 3px 10px; border-radius: 999px; background: var(--chip); font-size: 12.5px; color: var(--muted); }
.tag.draft { background: var(--warn-soft); color: var(--warn); }
.tag.reviewed { background: var(--accent-soft); color: var(--accent); }
.primary-btn {
  flex: none; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-ink); font-weight: 600; cursor: pointer;
}
.primary-btn[aria-pressed="true"] { background: transparent; color: var(--accent); }
.lead { font-size: 18px; line-height: 1.5; margin: 18px 0 22px; max-width: 70ch; }

.blocks { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 760px) { .blocks { grid-template-columns: 1.15fr 1fr; } .blocks .wide { grid-column: 1 / -1; } }
.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.block h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.block ul { margin: 0; padding-left: 18px; }
.block li { margin: 0 0 8px; }
.block li:last-child { margin-bottom: 0; }
.meds { display: grid; gap: 10px; }
@media (min-width: 760px) { .meds { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); } }
.med b { display: block; font-size: 15px; }
.med span { color: var(--muted); font-size: 14.5px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.link-chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-size: 14px; text-decoration: none; color: var(--ink); }
a.link-chip:hover { border-color: var(--accent); color: var(--accent); }
span.link-chip { color: var(--muted); }

details.bg { margin-top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
details.bg summary { cursor: pointer; padding: 14px 18px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
details.bg summary::-webkit-details-marker { display: none; }
details.bg summary::after { content: "+"; color: var(--muted); font-weight: 400; font-size: 20px; line-height: 1; }
details.bg[open] summary::after { content: "–"; }
details.bg summary small { color: var(--muted); font-weight: 400; }
.bg-body { padding: 0 18px 18px; display: grid; gap: 16px; }
.bg-body h3 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.bg-body p, .bg-body ul { margin: 0; }
.bg-body ul { padding-left: 18px; }
.bg-body li { margin-bottom: 6px; }
.red li::marker { color: var(--warn); }
.figure img { width: 100%; max-height: 320px; object-fit: contain; background: var(--chip); border-radius: 10px; }
.figure figcaption { font-size: 12px; color: var(--faint); margin-top: 4px; }

/* Patient */
.patient-head h1 { font-size: clamp(24px, 4vw, 32px); letter-spacing: -.02em; margin: 6px 0 6px; }
.patient-head p { color: var(--muted); margin: 0 0 14px; max-width: 62ch; }
.picker { position: relative; margin-bottom: 14px; }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 4; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 28px rgba(0, 0, 0, .12); overflow: hidden; max-height: 320px; overflow-y: auto;
}
.suggest button { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: none; cursor: pointer; }
.suggest button:hover, .suggest button:focus { background: var(--accent-soft); outline: none; }
.suggest small { color: var(--muted); margin-left: 6px; }
.selected { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.sel { display: inline-flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); font-size: 14px; }
.sel button { border: 0; background: none; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; color: var(--muted); }
.sel button:hover { background: var(--surface); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 18px; }
.ghost-btn { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 14px; }
.together { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; font-size: 14.5px; color: var(--muted); }
.together b { color: var(--ink); font-weight: 600; }
.stack { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 760px) { .stack { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); } }
.stack .block h3 { margin: 4px 0 2px; font-size: 18px; letter-spacing: -.01em; }
.stack .block h3 a { color: var(--ink); text-decoration: none; }
.stack .block h3 a:hover { color: var(--accent); }
.stack .block > p { margin: 0 0 12px; color: var(--muted); font-size: 14.5px; }
.stack .block h4 { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 12px 0 6px; }
.stack .block ul { font-size: 15px; }

@media (max-width: 480px) {
  .tile { padding-right: 46px; }
  .lead { font-size: 17px; }
  .block { padding: 14px 16px; }
}

/* Review state */
.muted { color: var(--muted); }
.tag.edits { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.sys .rv { margin-left: auto; font-style: normal; text-transform: none; letter-spacing: 0; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; }
.tile .sys { width: 100%; }
.rv.reviewed { background: var(--accent-soft); color: var(--accent); }
.rv.edits { background: var(--warn-soft); color: var(--warn); }
.has-proc { color: var(--accent); font-size: 12.5px; font-weight: 600; }

/* Procedures */
.procs, .anat { margin-top: 12px; }
.proc { padding: 14px 0; border-top: 1px solid var(--line); }
.proc:first-of-type { border-top: 0; padding-top: 2px; }
.proc h3 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.proc .by { margin: 2px 0 8px; color: var(--muted); font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.proc p { margin: 0 0 8px; }
.proc h4, .anat h4 { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 12px 0 6px; }
.cites { display: inline-flex; gap: 4px; }
.cite { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 6px; background: var(--chip); font-size: 11.5px; text-decoration: none; color: var(--muted); }
.cite:hover { background: var(--accent-soft); color: var(--accent); }
.srcs { margin-top: 10px; font-size: 13.5px; }
.srcs summary { cursor: pointer; color: var(--muted); }
.srcs ol { margin: 8px 0 0; padding-left: 22px; }
.srcs li { margin-bottom: 4px; word-break: break-word; }

/* Anatomy */
.anat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.anat-head h2 { margin: 0; }
.sarco-btn { padding: 7px 12px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); text-decoration: none; font-size: 14px; font-weight: 600; }
.muscles { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .muscles { grid-template-columns: repeat(2, 1fr); } }
.muscle { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); text-decoration: none; color: var(--ink); }
.muscle:hover { border-color: var(--accent); }
.muscle b { font-size: 15px; }
.muscle .why { font-size: 14px; }
.muscle .oian { font-size: 12.5px; color: var(--muted); }

/* Review */
.review { margin-top: 12px; }
.review p { margin: 0 0 10px; }
.rv-row { display: flex; gap: 8px; flex-wrap: wrap; }
.rv-name { flex: 1 1 160px; min-width: 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; }
.rv-btn { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-weight: 600; }
.rv-btn.yes:hover { border-color: var(--accent); color: var(--accent); }
.rv-btn.no:hover { border-color: var(--warn); color: var(--warn); }
.rv-note { display: grid; gap: 8px; margin-top: 10px; }
.rv-note textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; resize: vertical; }
.rv-note .primary-btn { justify-self: start; }
.rv-msg { min-height: 1.2em; color: var(--muted); font-size: 14px; margin: 8px 0 0 !important; }
.rv-count { font-weight: 600; margin-top: 6px !important; }
.rv-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rv-list li { padding: 8px 10px; border-radius: 8px; background: var(--bg); font-size: 14px; }
.rv-list span { color: var(--faint); font-size: 12.5px; }

/* Comparison */
.cmp { margin-bottom: 14px; }
.cmp-row { border-top: 1px solid var(--line); }
.cmp-row summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; }
.cmp-row summary::-webkit-details-marker { display: none; }
.cmp-label { font-weight: 600; }
.cmp-n { font-size: 12.5px; color: var(--accent); background: var(--accent-soft); padding: 1px 8px; border-radius: 999px; align-self: start; }
.cmp-names { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.cmp-card { padding: 0 0 10px 12px; border-left: 2px solid var(--line); margin: 0 0 10px; }
.cmp-card b { display: block; margin-bottom: 4px; font-size: 14.5px; }
.cmp-card ul { margin: 0; padding-left: 18px; font-size: 14.5px; }
.proc summary { cursor: pointer; list-style: none; position: relative; padding-right: 28px; }
.proc summary::-webkit-details-marker { display: none; }
.proc summary::after { content: "+"; position: absolute; right: 0; top: 0; color: var(--muted); font-size: 20px; line-height: 1; }
.proc[open] summary::after { content: "–"; }
.proc summary p:last-child { margin-bottom: 0; }
.proc[open] summary { margin-bottom: 4px; }
