:root {
  color-scheme: dark;
  --bg: #141518;
  --panel: #1a1b20;
  --input: #1c1d22;
  --line: #3b3c44;
  --text: #f3f0ea;
  --muted: #b2afb9;
  --blue: #84b8fc;
  --accent: var(--blue);
  --amber: #f4c66e;
  --red: #ff8992;
  --blood-red: #e51b23;
  --gray: #aaa9b6;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  isolation: isolate;
  background: var(--bg);
  color: var(--text);
  font-family: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(135deg, rgb(9 11 16 / .12), rgb(9 11 16 / .5)),
    url("../assets/mars-horizon.webp") right bottom / cover no-repeat;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.14; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.skip {
  position: fixed;
  inset: 12px auto auto 12px;
  z-index: 4;
  transform: translateY(-150%);
  background: var(--accent);
  color: var(--bg);
  padding: 8px 12px;
}
.skip:focus { transform: none; }

.shell {
  width: min(1280px, calc(100% - 80px));
  margin: 0 auto;
  padding: 0 0 48px;
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.gate-card { width: min(660px, 100%); padding: clamp(18px, 5vw, 40px); border-top: 1px solid var(--accent); }
.gate-card h1 { margin: 24px 0 8px; font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -.045em; }

.top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: clamp(16px, 3vw, 40px);
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.shell:has(#view-today:not([hidden]), #view-log:not([hidden])) .top { border-bottom: 0; }
.brand { display: flex; gap: 9px; align-items: center; min-width: 0; }
.mark { flex: none; width: 38px; height: 38px; }
.word { margin: 0; font-size: 1.45rem; font-weight: 700; letter-spacing: -.035em; }
.tag, .lede, .meta { color: var(--muted); }
.tag { margin: 0; font-size: .76rem; }
.meta { font-size: .84rem; }

.portrait {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  color: var(--accent);
  background: var(--panel);
  border: 1px solid var(--line);
  font: .76rem var(--mono);
  overflow: hidden;
}
.portrait-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.portrait-image:not([data-ready]) { opacity: 0; }
.portrait:has(> .portrait-image[data-ready]) > span { visibility: hidden; }
.generated-credit { color: var(--muted); font-size: .5625rem; line-height: 1.3; }
.portrait-credit { display: none; }
.portrait:has(> .portrait-image[data-ready]) + .portrait-credit { display: block; margin-top: 3px; }
.profile-preview { width: 80px; height: 80px; font-size: 1.15rem; }
.you-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 4px 0;
  border: 0;
  background: none;
  text-align: left;
}
.you-chip strong { display: block; max-width: 15ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.you-chip .meta { display: block; font-size: .73rem; }

.nav { display: flex; gap: clamp(8px, 2vw, 28px); align-self: stretch; }
.nav-btn {
  min-height: 56px;
  padding: 10px 2px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  white-space: nowrap;
}
.nav-btn[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.nav-btn:hover { color: var(--text); }
.nav-btn:is([data-view="log"], [data-view="actions"]) { color: var(--text); }

.today-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px 32px;
  align-items: end;
  padding: clamp(22px, 3vw, 40px) 0 24px;
}
.mission-line {
  margin-bottom: 8px;
  color: var(--muted);
  font: .82rem var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.today-intro h1 {
  margin-bottom: 8px;
  font-size: clamp(2.8rem, 6vw, 4.75rem);
  line-height: .98;
  letter-spacing: -.065em;
}
#today-summary { max-width: 66ch; margin: 0; font-size: clamp(1rem, 1.5vw, 1.2rem); }
.today-controls { display: grid; justify-items: end; gap: 12px; }

.body-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  padding: 24px 0 28px;
}
.map-section { min-width: 0; display: grid; align-content: start; }
.map-section h2, .detail-heading h2, .panel h2 {
  margin: 0;
  font-size: clamp(1.5rem, 2.8vw, 2.4rem);
  letter-spacing: -.042em;
}
.body-stage {
  position: relative;
  isolation: isolate;
  width: min(100%, 310px);
  aspect-ratio: 2 / 3;
  margin: 0 auto;
}
.anatomy, .body-overlays { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.body-overlays { pointer-events: none; }
.organ-shape {
  fill: var(--level);
  fill-opacity: .28;
  stroke: var(--level);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: fill .2s ease, stroke .2s ease;
}
.organ-shape[data-level="watch"], .organ-shape[data-level="act"] { fill-opacity: .76; }
.organ-shape[data-level="incomplete"] { fill-opacity: .38; }
.organ-detail { fill: none; stroke: var(--bg); stroke-opacity: .75; stroke-width: 3.5; }

.body-hotspot {
  position: absolute;
  z-index: 1;
  top: var(--y);
  left: var(--x);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  transform: translate(-50%, -50%);
  background: transparent;
  border: 0;
  border-radius: 50%;
}
.heart-pin { --x: 50.3%; --y: 24.4%; }
.sleep-pin { --x: 50%; --y: 4.4%; }
.breathing-pin { --x: 60.7%; --y: 23.9%; }
.digestion-pin { --x: 53%; --y: 36.2%; }
.period-pin { --x: 50%; --y: 43.5%; }
.exercise-pin { --x: 57%; --y: 61%; }
.exercise-pin::before, .period-pin::before {
  content: "";
  width: 9px;
  height: 9px;
  background: var(--level);
  border: 1px solid var(--bg);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--level);
}
.body-hotspot:hover, .body-hotspot:focus-visible { z-index: 2; }
.hotspot-preview {
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  width: max-content;
  max-width: 152px;
  padding: 5px 8px;
  transform: translateY(-50%);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: .76rem;
  text-align: left;
  line-height: 1.3;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.body-hotspot:focus-visible .hotspot-preview { opacity: 1; visibility: visible; }
@media (hover: hover) {
  .body-hotspot:hover .hotspot-preview { opacity: 1; visibility: visible; }
}

.map-key {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 0 10px 0 0;
  margin: 10px 0 0;
  list-style: none;
  color: var(--muted);
  font-size: .78rem;
}
.map-key li { display: flex; align-items: center; gap: 6px; }
.map-key li::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--level);
}

.detail-column { min-width: 0; padding: 0 0 0 clamp(22px, 4vw, 56px); }
.detail-heading { display: flex; gap: 10px 14px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
#body-detail p { margin: 0 0 8px; }
.heart-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; }
.followup-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}
.followup-dialog::backdrop { background: rgb(0 0 0 / .65); }
.followup-dialog h2 { margin: 0 0 8px; }
.followup-dialog input { margin-top: 6px; }
.followup-dialog .row-actions { margin-top: 16px; }
.trend-followups { margin-top: 4px; font-size: .76rem; color: var(--muted); }
.trend-followups summary { cursor: pointer; }
.trend-followups ul { padding-left: 18px; }
.heart-readings {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin: 4px 0 18px;
}
.heart-readings > div {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  min-width: 0;
}
.heart-readings > div + div { padding-left: clamp(12px, 2.4vw, 32px); }
.heart-readings dt { color: var(--muted); font-size: .87rem; margin-top: 4px; }
.heart-readings dd {
  margin: 0;
  font: 600 clamp(1.8rem, 4.3vw, 3.65rem)/1.1 var(--mono);
  letter-spacing: -.08em;
  white-space: nowrap;
}
.heart-readings > div + div dd { font-weight: 400; }
.heart-readings dd span { font-size: .5em; letter-spacing: 0; }
.detail-action { margin-top: 16px !important; }
.text-link { background: transparent; border: 0; padding: 8px 0; color: var(--accent); text-align: left; }
.text-link:hover { text-decoration: underline; text-underline-offset: 4px; }

.domain-list { margin-top: 24px; }
.domain-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 45px;
  padding: 8px 0 8px 10px;
  border: 0;
  background: none;
  text-align: left;
}
.domain-option:hover { background: var(--panel); }
.domain-option[aria-pressed="true"] { box-shadow: inset 2px 0 var(--accent); }
.domain-status { color: var(--level); font-size: .78rem; text-align: right; }

.level-stable, [data-level="stable"] { --level: var(--blue); }
.level-watch, [data-level="watch"] { --level: var(--amber); }
.level-act, [data-level="act"] { --level: var(--blood-red); }
.level-incomplete, [data-level="incomplete"] { --level: var(--gray); }
.pill {
  display: inline-block;
  width: fit-content;
  padding: 3px 8px;
  border: 1px solid var(--level, var(--line));
  color: var(--level, var(--text));
  font-weight: 600;
  font-size: .78rem;
  line-height: 1.4;
}
.detail-heading .level-watch { background: var(--level); color: #211a17; }
.pill.level-act, .level-act .pill, .domain-option[data-level="act"] .domain-status {
  background: var(--level);
  color: #fff;
}
.domain-option[data-level="act"] .domain-status { padding: 2px 6px; }

.crew-log summary { padding: 14px 0; cursor: pointer; font-size: 1.05rem; font-weight: 650; }
.crew-log summary .meta { margin-left: 14px; font-family: var(--mono); font-weight: 400; }
.crew {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px 20px;
  margin: 0 0 16px;
}
.person { min-width: 0; border-top: 2px solid var(--level); padding: 10px 0; }
.person h3 { margin: 6px 0 2px; font-size: .98rem; overflow-wrap: anywhere; }
.person .role, .lock { color: var(--muted); font-size: .76rem; }
.lock { margin: 8px 0 0; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0 0; }
.stats dt { color: var(--muted); font-size: .72rem; }
.stats dd { margin: 0; font: .82rem var(--mono); }

.panel { max-width: 920px; margin: 0 auto; padding: 30px 0; }
.panel h2 + .lede { margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }
.form-grid > * { align-self: end; }
.gate-card .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: 6px; font-size: .92rem; color: var(--muted); }
.checkin-field { display: grid; gap: 6px; color: var(--muted); font-size: .92rem; }
input[type="text"], input[type="number"], input[type="date"], textarea, select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--text);
}
input::placeholder { color: var(--muted); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
textarea { resize: vertical; }
fieldset { min-width: 0; border: 0; border-top: 1px solid var(--line); margin: 22px 0 0; padding: 10px 0 2px; }
#checkin-form > fieldset { border-top: 0; }
legend { padding: 0 8px 0 0; color: var(--text); font-weight: 600; }
.scale, .row-actions, .split { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.scale label { flex: 1 1 100px; position: relative; }
.scale input { position: absolute; opacity: 0; }
.scale span {
  display: block;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--input);
  text-align: center;
  cursor: pointer;
}
.scale input:checked + span { border-color: var(--accent); color: var(--accent); }
.scale input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.checks { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 14px; }
.symptom { display: flex; align-items: center; gap: 6px; min-width: 0; }
.symptom input { width: 1.15rem; height: 1.15rem; flex: none; margin: 0; cursor: pointer; }
.term { position: relative; display: inline-block; min-width: 0; max-width: 100%; }
.term-trigger {
  min-height: 44px;
  padding: 3px;
  border: 0;
  background: transparent;
  text-align: left;
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 4px;
}
.term-trigger:hover, .term-trigger:focus-visible { color: var(--accent); }
.checkin-field .term-trigger, legend .term-trigger { min-height: 32px; padding: 0; }
.term-tooltip {
  display: block;
  visibility: hidden;
  position: absolute;
  bottom: calc(100% - 2px);
  left: -10px;
  z-index: 3;
  width: min(210px, 72vw);
  border: 1px solid var(--line);
  background: #2b2b34;
  color: var(--text);
  padding: 8px 10px;
  font-size: .84rem;
  line-height: 1.4;
}
.symptom:nth-child(4n) .term-tooltip { right: 0; left: auto; }
.checkin-field .term-tooltip, legend .term-tooltip { left: 0; }
.term.is-open .term-tooltip, .term:has(.term-trigger:focus-visible) .term-tooltip { visibility: visible; }
@media (hover: hover) {
  .term:hover .term-tooltip { visibility: visible; }
}
.term.is-dismissed .term-tooltip { visibility: hidden; }

.note-label { margin-top: 18px; }
.primary, .ghost { min-height: 44px; border: 1px solid var(--line); border-radius: 2px; padding: 9px 14px; }
.primary { background: var(--accent); border-color: var(--accent); color: #111722; font-weight: 650; }
.primary:hover { background: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ghost { background: transparent; color: var(--text); }
.ghost:hover { border-color: var(--accent); }
.ghost.danger, .form-message.bad { color: var(--red); }
.form-message { margin: 12px 0; }
.form-message:empty { margin: 0; }
.form-message.ok { color: var(--accent); }

.split { justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.inline { min-width: min(220px, 100%); }
#chart svg { width: 100%; height: auto; display: block; }
#chart .grid { stroke: var(--line); stroke-width: 1; }
#chart .series { fill: none; stroke: var(--blood-red); stroke-width: 2.5; }
#chart .guide { stroke: var(--amber); stroke-dasharray: 4 4; }
#chart circle { fill: var(--blood-red); }
#chart text { fill: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; }

.action { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 12px 0; border-top: 1px solid var(--line); }
.action input { width: 1.1rem; height: 1.1rem; margin-top: 4px; }
.action p { margin: 4px 0 0; }
.empty { color: var(--muted); }

@media (max-width: 930px) {
  .shell { width: calc(100% - 48px); }
  .top { gap: 14px; }
  .you-chip > span:last-child { display: none; }
  .crew { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 690px) {
  body::before {
    background-image: linear-gradient(rgb(9 11 16 / .28), rgb(9 11 16 / .64)), url("../assets/mars-horizon.webp");
  }
  .shell { width: calc(100% - 32px); }
  .top { grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; }
  .top .brand { padding: 8px 0; }
  .nav { grid-row: 2; grid-column: 1 / -1; gap: 0; justify-content: space-between; }
  .nav-btn { min-height: 44px; padding: 8px 2px; font-size: .84rem; }
  .today-intro { grid-template-columns: minmax(0, 1fr); }
  .today-controls { justify-items: start; }
  .body-layout { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .body-stage { width: min(100%, 256px); }
  .detail-column { padding: 18px 0 0; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .checks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .checkin-field .term-tooltip { width: min(210px, calc((100vw - 48px) / 2)); }
  .symptom:nth-child(2n) .term-tooltip { right: -8px; left: auto; }
}

@media (max-width: 420px) {
  .gate-card { padding-inline: 0; }
  .gate-card .form-grid { grid-template-columns: minmax(0, 1fr); }
  .crew { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hotspot-preview { max-width: 104px; }
  .symptom:nth-child(2n) .term-tooltip { right: auto; left: -22px; width: min(160px, 46vw); }
}

@media (prefers-reduced-motion: reduce) {
  .organ-shape { transition: none; }
}

.assistant-link { display: flex; align-items: center; gap: 5px; padding: 0; font-size: .84rem; color: var(--text); }
.assistant-link img, .astro-dialog-title img { display: block; flex: none; object-fit: contain; }
/* Hide the rover artwork's embedded caption at avatar sizes. */
.assistant-link img, #astra-title img { clip-path: polygon(0 0, 100% 0, 100% 89%, 82% 89%, 82% 100%, 0 100%); }
.astro-dialog-title { display: flex; align-items: center; gap: 10px; }
.astra-credit { display: block; margin: -10px 0 0 58px; }
.check-panel { display: grid; gap: 12px; }
.check-line, .check-toggle { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.check-toggle input { margin: 0; }
.astro-dialog { width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); }
.astro-dialog fieldset { margin-block: 12px; }
.guide-art { margin: 14px 0 16px; }
.guide-art img { display: block; width: 100%; height: auto; }
.reaction-stimulus img { display: block; max-width: 100%; max-height: 160px; margin: auto; }
.reaction-stimulus { display: grid; place-items: center; height: 150px; border: 1px solid var(--line); font: 700 5rem var(--mono); color: var(--text); }
.vision-plate { display: block; width: min(250px, 100%); margin: 12px auto; }
.vision-symbols { display: block; text-align: center; letter-spacing: .25em; font-family: var(--mono); padding: 12px 0; }
.meal-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.35fr) auto; gap: 8px; align-items: end; margin-bottom: 10px; }
.pain-label { margin: 0; }
.pulse-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 14px 0; }
.pulse-readout { display: grid; gap: 5px; min-width: 0; font-size: .83rem; color: var(--muted); }
.pulse-wave { display: block; width: 100%; height: auto; overflow: hidden; background: #000; }
.pulse-wave path { fill: none; stroke: var(--blood-red); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pulse-trace { transform-box: view-box; animation: logged-pulse var(--beat) linear infinite; }
.pulse-caption { grid-column: 1 / -1; margin: 0; }
@keyframes logged-pulse { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .pulse-trace { animation: none; } }
@media (max-width: 580px) { .meal-row { grid-template-columns: 1fr 1fr; } }

.astra-chat[open] {
  display: grid;
  gap: 12px;
  width: min(620px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
}
.astra-chat-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.astra-chat-header h2, .astra-chat > p { margin: 0; }
.astra-chat-log {
  min-height: 100px;
  height: min(34dvh, 320px);
  overflow-y: auto;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--input);
}
.astra-message { margin: 0 0 12px; overflow-wrap: anywhere; }
.astra-message span { display: block; white-space: pre-wrap; }
.astra-message-user strong { color: var(--blue); }
.astra-starters:not([hidden]) { display: flex; flex-wrap: wrap; gap: 8px; }
#astra-form textarea { display: block; width: 100%; resize: vertical; }
#astra-form .row-actions { margin-top: 8px; }
#astra-send:disabled { opacity: .65; }
