/* Tokens: clinical cool paper, oxblood for red cells, straw for plasma */
:root {
  --paper: #F5F6F8;
  --surface: #FFFFFF;
  --ink: #1D1B22;
  --muted: #625F6B;
  --line: #DEDCE3;
  --blood: #B0152F;
  --plasma: #C9922A;
  --ok: #1E7048;
  --accent: var(--blood);
  --on-accent: #FFFFFF;
  --radius-s: 6px;
  --radius-l: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151318;
    --surface: #211E26;
    --ink: #F1EFF4;
    --muted: #A9A5B1;
    --line: #37333E;
    --blood: #E24A62;
    --plasma: #E8BC5A;
    --ok: #5CC592;
    --on-accent: #151318;
  }
}

body[data-product="plasma"] { --accent: var(--plasma); }

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, "Roboto", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header */
.top {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  row-gap: 8px;
  column-gap: 12px;
  padding: 12px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.top h1 {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 1.05rem; font-weight: 700; margin: 0;
}
.top .seg { grid-column: 1; justify-self: start; }
.about-btn {
  grid-column: 2;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
body[data-tab="learn"] .seg { visibility: hidden; }

.lang-select {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 6px 10px;
  font-size: 0.8rem;
  width: auto;
  cursor: pointer;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  background: var(--surface);
}
.seg button {
  white-space: nowrap;
  border: 0;
  background: none;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.875rem;
  cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }

.lead { margin: 4px 0 14px; color: var(--muted); }
h2 { font-size: 1.1rem; margin: 28px 0 10px; }
.small { font-size: 0.85rem; color: var(--muted); }
.muted { color: var(--muted); }

/* First-launch language picker */
.lang-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding: calc(24px + env(safe-area-inset-top, 0px)) 16px calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  overflow-y: auto;
}
.lang-gate[hidden] { display: none; }
body:has(.lang-gate:not([hidden])) { overflow: hidden; }
.lang-gate > * { width: 100%; max-width: 420px; margin-inline: auto; }
.lang-gate-title {
  display: grid; gap: 2px; margin: 0;
  font-size: 1.15rem; font-weight: 700;
}
.lang-gate-title span + span { font-size: 0.95rem; font-weight: 600; color: var(--muted); }
.lang-gate-options { display: grid; gap: 10px; }
.lang-gate-options button {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px;
  border: 1.5px solid var(--line);
  border-top: 4px solid var(--blood);
  border-radius: var(--radius-s);
  background: var(--surface);
  font-size: 1.2rem; font-weight: 650;
  text-align: left;
  cursor: pointer;
}
.lang-gate-options .muted { font-size: 0.85rem; font-weight: 500; }
.lang-gate .small { margin: 0; }

/* First-run intro */
.intro {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--blood);
  border-radius: var(--radius-s);
  padding: 4px 16px 16px;
  margin-bottom: 20px;
}
.intro h2 { margin: 12px 0 8px; }
.intro p { margin: 0 0 10px; }

/* Group picker */
.groups {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.group {
  aspect-ratio: 1.25;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  cursor: pointer;
}
.group[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* The blood bag label: the one memorable element */
.label {
  display: flex;
  flex-wrap: wrap;
  margin-top: 18px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius-l);
  overflow: hidden;
}
.label[hidden] { display: none; }
.label-band { width: 14px; background: var(--accent); flex: 0 0 14px; }
.label-body { flex: 1; padding: 14px 16px 16px; min-width: 0; }
.label-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 8px;
}
.big {
  font-size: 4.5rem;
  line-height: 0.9;
  font-weight: 850;
  letter-spacing: -0.04em;
}
.label-meta { text-align: right; font-weight: 600; font-size: 0.95rem; }
.label h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 12px 0 6px;
  display: flex;
  justify-content: space-between;
}
.count { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.label-foot {
  flex-basis: 100%;
  margin: 0;
  padding: 10px 16px 12px 30px;
  border-top: 1px dashed var(--line);
  font-size: 0.9rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 10px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  font-weight: 700;
  min-width: 3.1em;
  text-align: center;
}
.chip.mine { border-color: var(--accent); }

/* Donor/recipient diagram */
.diagram { margin-top: 16px; }
.diagram svg { width: 100%; height: auto; display: block; }
.diagram-title { font: 700 13px system-ui, sans-serif; fill: var(--ink); }
.diagram-note { font: 12px system-ui, sans-serif; fill: var(--muted); }
.diagram-box { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.diagram-box-text { font: 700 14px system-ui, sans-serif; fill: var(--ink); }
.diagram-big { fill: var(--accent); }
.diagram-big-text { font: 800 16px system-ui, sans-serif; fill: var(--on-accent); }
.diagram-arrow { stroke: var(--muted); stroke-width: 2; }
.diagram-arrowhead { fill: var(--muted); }

/* Pair test */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; font-weight: 600; }
select, input, textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
  font-weight: 400;
  font-size: 1rem;
  width: 100%;
}
/* Date field: the native picker sits invisibly on top of a dd/mm/yyyy display,
   since type="date" always shows the device locale's format. */
.date-field { position: relative; display: block; }
.date-display {
  display: block;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
  font-weight: 400;
  font-size: 1rem;
}
.date-display.empty { color: var(--muted); }
.date-field input {
  position: absolute; inset: 0;
  opacity: 0;
  cursor: pointer;
}
.date-field:focus-within .date-display { outline: 3px solid var(--accent); outline-offset: 2px; }

.verdict {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-s);
  border-left: 5px solid var(--muted);
  background: var(--surface);
  font-weight: 600;
}
.verdict.yes { border-left-color: var(--ok); }
.verdict.no { border-left-color: var(--blood); }

/* Chart */
.table-wrap { overflow-x: auto; }
.chart {
  border-collapse: collapse;
  width: 100%;
  min-width: 340px;
  background: var(--surface);
  font-size: 0.9rem;
}
.chart th, .chart td {
  border: 1px solid var(--line);
  padding: 8px 4px;
  text-align: center;
}
.chart th { font-weight: 700; }
.chart tr.mine th, .chart th.mine { color: var(--accent); }
.chart tr.mine td, .chart td.mine { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(135deg);
  background: var(--accent);
}

/* Learn */
details {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  margin-bottom: 8px;
  padding: 0 14px;
}
summary { padding: 14px 0; font-weight: 650; cursor: pointer; }
details p { margin: 0 0 12px; max-width: 70ch; }

/* Me */
.form { display: grid; gap: 16px; margin-top: 20px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.primary, .ghost {
  padding: 11px 18px;
  border-radius: var(--radius-s);
  font-weight: 650;
  cursor: pointer;
}
.primary { background: var(--blood); color: #fff; border: 0; }
.ghost { background: none; border: 1.5px solid var(--line); }
.status { margin: 0; min-height: 1.5em; color: var(--muted); }
.privacy {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--muted);
}

/* Bottom navigation */
nav.bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
nav.bottom button {
  border: 0;
  background: none;
  height: 60px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}
nav.bottom button[aria-selected="true"] { color: var(--ink); }
nav.bottom button[aria-selected="true"]::before {
  content: "";
  position: absolute;
  top: 0; left: 30%; right: 30%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--blood);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
