/* Components. Each block is one component; class names follow .block / .block__part / .block--variant.
   The same list, with usage notes, is in README.md → "Design system". */

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.2) blur(10px); backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar__in { height: var(--topbar-h); display: flex; align-items: center; gap: var(--s-3); }
/* The thread between screens (app.js → routeThread): drawn along the bar's lower edge, then gone. */
.route-thread { position: absolute; left: 0; bottom: -5px; width: 100%; height: 10px; pointer-events: none; overflow: visible; }
.route-thread path { fill: none; stroke: var(--blood); stroke-width: 2; stroke-linecap: round; stroke-dasharray: 1; }
.topbar__nav { display: none; gap: var(--s-1); margin-left: var(--s-4); min-width: 0; flex: 1 1 auto; }
.topbar__end { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }
.topbar__nav a {
  display: inline-flex; align-items: center; flex: none; white-space: nowrap; min-height: var(--tap-min); padding: 0 var(--s-3);
  color: var(--ink-2); text-decoration: none; font-weight: 500; border-radius: var(--r-sm); position: relative;
}
.topbar__nav a:hover { color: var(--ink); background: var(--paper-2); }
.topbar__nav a[aria-current="page"] { color: var(--ink); }
.topbar__nav a[aria-current="page"]::after {
  content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: 6px; height: 2px;
  background: var(--blood); border-radius: 2px;
}
@media (min-width: 1080px) { .topbar__nav { display: flex; } }

.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); min-height: var(--tap-min); }
.brand__mark { width: 22px; height: 29px; color: var(--blood); }
.brand__word { font: 600 22px/1 var(--font-display); letter-spacing: -.01em; }

/* Language switch: three short buttons; each carries its own lang attribute. */
.lang { display: inline-flex; background: var(--paper-2); border-radius: var(--r-pill); padding: 3px; }
.lang button {
  min-width: 40px; min-height: 38px; padding: 0 8px; border-radius: var(--r-pill);
  font: 600 13px/1 var(--font-ui); letter-spacing: .04em; color: var(--ink-2);
}
.lang button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.lang button:hover { color: var(--ink); }
.theme { display: inline-flex; background: var(--paper-2); border-radius: var(--r-pill); padding: 3px; }
.theme button {
  display: grid; place-items: center; min-width: 40px; min-height: 36px; padding: 0;
  border-radius: var(--r-pill); color: var(--ink-2);
}
.theme button svg { width: 18px; height: 18px; }
.theme button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.theme button:hover { color: var(--ink); }
.theme button:focus-visible { outline: 2px solid var(--blood); outline-offset: 2px; }
/* The visible target is 38 px tall inside a 44 px row; the extra padding keeps the hit area ≥ 44 px. */
.lang button { position: relative; }
.lang button::after { content: ""; position: absolute; inset: -3px 0; }

/* ── Tab bar (phones, signed-in roles) ───────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 96%, transparent); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.tabbar__in { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; height: var(--tabbar-h); }
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 0; padding: 6px 2px 8px;
  font: 500 10px/1.1 var(--font-ui); color: var(--ink-2); text-decoration: none; text-align: center;
  min-height: var(--tabbar-h); -webkit-tap-highlight-color: transparent;
  transition: color var(--t-fast) ease, background var(--t-fast) ease;
}
.tabbar a span { display: block; max-width: 100%; white-space: normal; overflow-wrap: break-word; }
@media (max-width: 1079px) {
  :root { --tabbar-h: 78px; }
}
.tabbar a:active { background: var(--paper-2); }
.tabbar a .icon { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--blood-deep); font-weight: 600; }
.tabbar a[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; background: var(--blood); border-radius: 0 0 3px 3px;
}
.tabbar__badge {
  position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--blood); color: #fff; font: 700 11px/18px var(--font-ui); text-align: center;
}
@media (min-width: 1080px) { .tabbar { display: none; } body.has-tabbar #main { padding-bottom: var(--s-16); } }

/* ── Icons ───────────────────────────────────────────────── */
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon--fill { fill: currentColor; stroke: none; }
.icon--lg { width: 28px; height: 28px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0 var(--s-5); border-radius: var(--r-md);
  border: 1.5px solid transparent; font: 600 16px/1.2 var(--font-ui); text-decoration: none; text-align: center;
  transition: background var(--t-fast) ease, box-shadow var(--t-fast) ease, transform var(--t-fast) ease, border-color var(--t-fast) ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--blood); color: #fff; box-shadow: var(--shadow-cta); }
.btn--primary:hover { background: var(--blood-deep); }
.btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn--secondary:hover { background: var(--paper-2); }
.btn--ghost { background: transparent; color: var(--ink); }
.btn--ghost:hover { background: var(--paper-2); }
.btn--quiet { min-height: var(--tap-min); padding: 0 var(--s-2); color: var(--blood-deep); background: none; text-decoration: underline; text-underline-offset: 3px; }
/* Dark glass: over any picture, even a white light, the label keeps AA. */
.btn--on-dark { background: rgba(21, 14, 26, .66); color: #FBF6F1; border-color: rgba(251, 246, 241, .6); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.btn--on-dark:hover { background: rgba(58, 40, 54, .82); }
.btn--lg { min-height: 56px; font-size: 17px; padding: 0 var(--s-6); }
.btn--sm { min-height: var(--tap-min); padding: 0 var(--s-4); font-size: 15px; }
.btn--block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn .icon { width: 20px; height: 20px; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-3); }
.btn-stack { display: grid; gap: var(--s-3); }

.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: var(--tap-min); height: var(--tap-min);
  border-radius: 50%; color: var(--ink); text-decoration: none;
}
.icon-btn:hover { background: var(--paper-2); }
.icon-btn .icon { width: 22px; height: 22px; }
.icon-btn__dot {
  position: absolute; top: 6px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--blood); color: #fff; font: 700 11px/18px var(--font-ui); text-align: center; border: 2px solid var(--paper);
}
.avatar {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--blush); color: var(--blood-deep); font: 700 15px/1 var(--font-display);
}

/* ── Tags ────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: var(--r-pill);
  background: var(--paper-2); color: var(--ink-2); font: 600 13px/1.2 var(--font-ui); white-space: nowrap;
}
.tag .icon { width: 15px; height: 15px; stroke-width: 2.2; }
.tag--urgent { background: var(--blush); color: var(--blood-deep); }
.tag--ok { background: var(--sage-soft); color: var(--sage-ink); }
.tag--rank { background: var(--gold-soft); color: var(--gold-ink); }
.tag--line { background: transparent; border: 1px solid var(--line-strong); color: var(--ink-2); }

/* ── Cards ───────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); }
.card--sunken { background: var(--paper-2); border-color: transparent; }
.card--soft { background: var(--blush-2); border-color: transparent; }
.card--pad-lg { padding: var(--s-6); }
@media (min-width: 720px) { .card { padding: var(--s-6); } }
.card__title { font: 600 var(--fs-lg)/1.3 var(--font-ui); }
.card > .label + * { margin-top: var(--s-2); }

/* Notice: an inline message with an icon (privacy notes, doctor's-decision notes). */
.notice { display: flex; gap: var(--s-3); align-items: flex-start; font-size: var(--fs-sm); color: var(--ink-2); line-height: 1.5; }
.notice .icon { width: 20px; height: 20px; margin-top: 1px; color: var(--ink-2); }
.notice--blood .icon { color: var(--blood); }
.notice--ok .icon { color: var(--sage-ink); }

/* ── Blood group glyph ───────────────────────────────────── */
.group { font: 700 var(--fs-group)/.9 var(--font-display); color: var(--blood); letter-spacing: -.02em; white-space: nowrap; }
.group--md { font-size: 44px; }
.group--sm { font-size: 28px; }
.group__name { display: block; margin-top: 6px; font: 500 var(--fs-sm)/1.3 var(--font-ui); color: var(--ink-2); letter-spacing: 0; }

/* ── Response ring (from direction B) ────────────────────── */
.ring { position: relative; width: var(--ring, 84px); height: var(--ring, 84px); flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring__track { fill: none; stroke: var(--paper-2); stroke-width: 9; }
.ring__fill {
  fill: none; stroke: var(--blood); stroke-width: 9; stroke-linecap: round;
  transition: stroke-dasharray var(--t-slow) var(--ease-out);
  animation: ring-fill 1.1s .15s var(--ease-out) both;
}
.ring__fill--zero { stroke-linecap: butt; }
.ring__mid { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1; }
.ring__n { font: 700 calc(var(--ring, 84px) * .34)/1 var(--font-display); color: var(--ink); }
.ring__of { margin-top: 3px; font: 600 11px/1.1 var(--font-ui); color: var(--ink-2); letter-spacing: .02em; }
.ring--lg { --ring: 132px; }
.ring--lg .ring__of { font-size: 13px; }
/* 264 ≈ the ring's circumference (r = 42), so the dash grows from nothing without a repeat. */
@keyframes ring-fill { from { stroke-dasharray: 0 264; } }

/* ── The thread (direction A) ────────────────────────────── */
.thread { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.thread path { fill: none; stroke: var(--blood); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.thread--draw path { stroke-dasharray: 1; animation: thread-draw var(--t-thread) var(--ease-thread) both; }
.thread circle { fill: var(--blood); }
.thread--draw circle { animation: pop .45s calc(var(--t-thread) - 150ms) var(--ease-out) both; transform-box: fill-box; transform-origin: center; }
@keyframes thread-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes pop { from { transform: scale(0); } }

/* ── Rank medal with the felt ornament (direction C) ─────── */
.medal { position: relative; width: var(--medal, 132px); height: var(--medal, 132px); flex: none; }
.medal svg { width: 100%; height: 100%; overflow: visible; }
.medal__num { position: absolute; inset: 0; display: grid; place-items: center; font: 700 calc(var(--medal, 132px) * .3)/1 var(--font-display); color: var(--blood); }
.medal__seg { transform-origin: 105px 105px; }
.medal--assemble .medal__seg { animation: assemble .9s var(--ease-out) both; }
.medal--assemble .medal__seg:nth-child(2) { animation-delay: .12s; }
.medal--assemble .medal__seg:nth-child(3) { animation-delay: .24s; }
.medal--assemble .medal__seg:nth-child(4) { animation-delay: .36s; }
.medal--assemble .medal__num { animation: rise .6s .5s var(--ease-out) both; }
.medal--sm { --medal: 64px; }
.medal--lg { --medal: 188px; }
@keyframes assemble { from { transform: rotate(-80deg) scale(.5); opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }

.rank-bar { height: 8px; border-radius: 99px; background: var(--paper-2); overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--gold), #D6A65A); transform-origin: left; animation: grow 1.2s .3s var(--ease-out) both; }
@keyframes grow { from { transform: scaleX(0); } }

/* ── Forms ───────────────────────────────────────────────── */
.field { display: grid; gap: 6px; }
.field + .field, .field + .fieldset, .fieldset + .field, .fieldset + .fieldset { margin-top: var(--s-5); }
.field__label, .fieldset legend { font: 600 15px/1.35 var(--font-ui); color: var(--ink); padding: 0; }
.field__hint { font-size: var(--fs-xs); color: var(--ink-2); line-height: 1.45; }
.field__error { display: flex; gap: 6px; align-items: center; font: 500 var(--fs-xs)/1.4 var(--font-ui); color: var(--blood-deep); }
.field__error .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.input, .select {
  width: 100%; min-height: 52px; padding: 0 var(--s-4); border-radius: var(--r-md);
  background: var(--surface); border: 1.5px solid var(--line-strong); font-size: 16px; color: var(--ink);
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
.input::placeholder { color: #9A8983; }
.input:hover, .select:hover { border-color: var(--ink-2); }
.input:focus-visible, .select:focus-visible { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(42, 29, 27, .18); }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--blood); }
.select { appearance: none; -webkit-appearance: none; padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%236B5A55' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 20px; }
.fieldset { border: 0; padding: 0; min-width: 0; }
.fieldset legend { margin-bottom: var(--s-2); }

/* Choice tiles: real radio or checkbox inputs, styled as big tiles. */
.tiles { display: grid; grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr)); gap: var(--s-2); }
.tile { position: relative; display: block; }
.tile input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.tile__body {
  display: grid; place-items: center; gap: 2px; min-height: 56px; padding: var(--s-2);
  border-radius: var(--r-md); border: 1.5px solid var(--line-strong); background: var(--surface);
  font: 600 18px/1.1 var(--font-ui); text-align: center; transition: all var(--t-fast) ease;
}
.tile__body small { font: 500 12px/1.2 var(--font-ui); color: var(--ink-2); }
.tile--group .tile__body { font: 700 24px/1 var(--font-display); }
.tile input:hover + .tile__body { border-color: var(--ink-2); }
.tile input:checked + .tile__body { background: var(--blush); border-color: var(--blood); color: var(--blood-deep); box-shadow: inset 0 0 0 1px var(--blood); }
.tile input:checked + .tile__body small { color: var(--blood-deep); }
.tile input:focus-visible + .tile__body { outline: 3px solid var(--ink); outline-offset: 2px; }

/* Check row: a large checkbox with its label. */
.check { display: flex; gap: var(--s-3); align-items: flex-start; cursor: pointer; }
.check input { appearance: none; -webkit-appearance: none; flex: none; width: 26px; height: 26px; margin: 1px 0 0; border-radius: 8px; border: 1.5px solid var(--line-strong); background: var(--surface) center/16px no-repeat; cursor: pointer; }
.check input:checked { background-color: var(--blood); border-color: var(--blood); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.check input:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.check input[aria-invalid="true"] { border-color: var(--blood); }
.check span { font-size: 15px; line-height: 1.45; }

/* Switch: a button with role="switch". */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); min-height: var(--tap); }
.switch { position: relative; flex: none; width: 52px; height: 32px; border-radius: 16px; background: #BFB1A9; transition: background var(--t-fast) ease; }
.switch::before { content: ""; position: absolute; inset: -6px -2px; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform var(--t-fast) var(--ease-out); }
.switch[aria-checked="true"] { background: var(--sage-ink); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* ── Steps: progress along the thread ────────────────────── */
.steps { display: flex; align-items: center; gap: 0; margin: var(--s-2) 0 var(--s-6); }
.steps__node {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; flex: none;
  border: 2px solid var(--line-strong); background: var(--paper); font: 700 13px/1 var(--font-ui); color: var(--ink-2);
}
.steps__node.is-done { background: var(--blood); border-color: var(--blood); color: #fff; }
.steps__node.is-now { border-color: var(--blood); color: var(--blood-deep); box-shadow: 0 0 0 4px var(--blush); }
.steps__line { flex: 1; height: 2px; background: var(--line); position: relative; overflow: hidden; }
.steps__line i { position: absolute; inset: 0; background: var(--blood); transform-origin: left; transform: scaleX(0); }
.steps__line.is-done i { transform: scaleX(1); animation: grow .7s var(--ease-thread) both; }

/* ── Lists ───────────────────────────────────────────────── */
.list { list-style: none; padding: 0; }
.list > li { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list__icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--paper-2); color: var(--ink-2); flex: none; }
.list__icon .icon { width: 18px; height: 18px; }
.list__icon--blood { background: var(--blush); color: var(--blood-deep); }
.list__icon--ok { background: var(--sage-soft); color: var(--sage-ink); }
.list__icon--gold { background: var(--gold-soft); color: var(--gold-ink); }
.list__main { flex: 1; min-width: 0; }
.list__title { font-weight: 600; }
.list__meta { font-size: var(--fs-sm); color: var(--ink-2); }

/* Numbered path: steps joined by a vertical thread. */
.path { list-style: none; padding: 0; position: relative; }
.path > li { position: relative; padding: 0 0 var(--s-5) 48px; min-height: 34px; }
.path > li:last-child { padding-bottom: 0; }
.path > li::before {
  content: counter(path); counter-increment: path; position: absolute; left: 0; top: -2px;
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--blood); color: #fff; font: 700 14px/1 var(--font-ui);
}
.path > li:not(:last-child)::after { content: ""; position: absolute; left: 15px; top: 32px; bottom: 2px; width: 2px; background: var(--blush); }
.path { counter-reset: path; }
.path b { display: block; font-weight: 600; margin-bottom: 2px; }

/* ── Sheet (native <dialog>): bottom sheet on phones, centred on wide screens ── */
.sheet {
  width: 100%; max-width: 100%; max-height: min(92vh, 92dvh); margin: auto 0 0; padding: 0; border: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0; background: var(--paper); color: var(--ink); box-shadow: var(--shadow-2);
  overflow: hidden; overscroll-behavior: contain;
}
.sheet::backdrop { background: var(--scrim); }
.sheet[open] { animation: sheet-up var(--t-med) var(--ease-out) both; }
.sheet__in {
  padding: var(--s-4) max(var(--gutter), env(safe-area-inset-right, 0px)) calc(var(--s-6) + env(safe-area-inset-bottom, 0px)) max(var(--gutter), env(safe-area-inset-left, 0px));
  max-height: min(92vh, 92dvh); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.sheet__grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 0 auto var(--s-3); opacity: .6; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.sheet__head h2 { font-size: var(--fs-xl); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 720px) {
  .sheet { width: min(520px, calc(100% - 48px)); margin: auto; border-radius: var(--r-xl); max-height: min(88vh, 88dvh); }
  .sheet__grip { display: none; }
  .sheet__in { padding: var(--s-6) var(--s-8) var(--s-8); max-height: min(88vh, 88dvh); }
}

/* ── Toasts: in-app notifications ────────────────────────── */
.toasts {
  position: fixed; z-index: 60;
  top: calc(var(--topbar-offset) + 8px);
  left: max(var(--s-3), env(safe-area-inset-left, 0px));
  right: max(var(--s-3), env(safe-area-inset-right, 0px));
  display: grid; gap: var(--s-2); pointer-events: none;
}
/* Wide screens: bottom right, so a toast never covers the page's main button (top right). */
@media (min-width: 720px) {
  .toasts { left: auto; right: var(--s-6); width: 380px; top: auto; bottom: var(--s-6); }
  body.has-tabbar .toasts { bottom: calc(var(--tabbar-h) + var(--s-4) + env(safe-area-inset-bottom)); }
  .toast, .tg { animation-name: toast-up; }
}
@media (min-width: 1080px) { body.has-tabbar .toasts { bottom: var(--s-6); } }
.toast {
  pointer-events: auto; position: relative; display: flex; gap: var(--s-3); align-items: flex-start;
  background: var(--surface); border-radius: var(--r-lg); padding: var(--s-4) var(--s-4) var(--s-4) var(--s-5);
  box-shadow: var(--shadow-2); border: 1px solid var(--line); overflow: hidden;
  animation: toast-in var(--t-med) var(--ease-out) both;
  max-width: 100%;
}
.toast::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--sage); }
.toast--urgent::before { background: var(--blood); }
.toast__icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--sage-soft); color: var(--sage-ink); flex: none; }
.toast--urgent .toast__icon { background: var(--blush); color: var(--blood-deep); }
.toast__main { flex: 1; min-width: 0; }
.toast__title { font-weight: 600; line-height: 1.35; }
.toast__text { font-size: var(--fs-sm); color: var(--ink-2); margin-top: 2px; }
.toast__actions { display: flex; gap: var(--s-2); margin-top: var(--s-2); }
.toast__close { margin: -10px -10px 0 0; }
@keyframes toast-in { from { transform: translateY(-12px); opacity: 0; } }
@keyframes toast-up { from { transform: translateY(12px); opacity: 0; } }

/* Telegram message mock — clearly labelled as a simulation. */
.tg {
  pointer-events: auto; border-radius: var(--r-lg); background: #E7EEF4; padding: var(--s-3); box-shadow: var(--shadow-2);
  animation: toast-in var(--t-med) .5s var(--ease-out) both; border: 1px solid #D5E0E9;
}
.tg__label { display: flex; align-items: center; gap: 6px; font: 600 12px/1.2 var(--font-ui); color: #3B5569; margin: 0 2px var(--s-2); }
.tg__label .icon { width: 16px; height: 16px; }
.tg__bubble { background: #fff; border-radius: 14px 14px 14px 4px; padding: 10px 12px; font-size: 15px; line-height: 1.45; color: #1D2B36; }
.tg__from { font: 600 13px/1.2 var(--font-ui); color: #2E7AB8; margin-bottom: 3px; display: flex; gap: 6px; align-items: center; }
.tg__bot { font: 600 10px/1 var(--font-ui); letter-spacing: .06em; text-transform: uppercase; color: #5B7489; background: #EEF3F7; padding: 3px 5px; border-radius: 4px; }
.tg__btn { display: block; width: 100%; margin-top: 6px; min-height: var(--tap-min); border-radius: 10px; background: #F4F8FB; color: #2E7AB8; font: 600 14px/1.2 var(--font-ui); }
.tg__btn:hover { background: #E9F1F8; }

/* ── Offline banner ──────────────────────────────────────── */
.offline { background: var(--ink); color: #fff; font-size: var(--fs-sm); text-align: center; padding: 8px var(--gutter); }

/* ── Demo switcher: a small dashed button at the end of the top bar ─────
   It lives in the bar, not over the page, so it never covers a control. The dashed edge marks it as a
   tool of the prototype, not part of Kanapp. Phones: icon only (the word stays for screen readers). */
.demo-btn {
  position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: var(--tap-min); height: var(--tap-min); border-radius: var(--r-pill); border: 1px dashed var(--line-strong);
  color: var(--ink-2); font: 600 13px/1 var(--font-ui);
}
.demo-btn:hover { color: var(--ink); background: var(--paper-2); }
.demo-btn .icon { width: 18px; height: 18px; stroke-width: 2; }
.demo-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (min-width: 1080px) {
  .demo-btn { width: auto; padding: 0 14px 0 12px; }
  .demo-btn span { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
}
/* Room for it on phones: «Войти» becomes an icon under 440 px, the language buttons narrow a little,
   and under 370 px the wordmark steps aside for the drop (its name stays for screen readers). */
.topbar__login .icon { display: none; }
.topbar__admin { color: var(--ink-2); }
.topbar__admin .icon { width: 18px; height: 18px; }
@media (max-width: 439px) {
  .topbar__login { width: var(--tap-min); padding: 0; border-radius: 50%; }
  .topbar__login .icon { display: block; width: 20px; height: 20px; }
  .topbar__login span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .topbar__admin { width: var(--tap-min); padding: 0; border-radius: 50%; }
  .topbar__admin span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .lang button { min-width: 38px; padding: 0 6px; }
}
@media (max-width: 369px) {
  .brand__word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
.demo-panel .sheet__in { display: grid; gap: var(--s-5); }
.demo-panel h3 { font: 600 12px/1.2 var(--font-ui); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); margin-bottom: var(--s-2); }
.demo-roles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.demo-roles button, .demo-events button {
  display: flex; align-items: center; gap: var(--s-2); min-height: var(--tap); padding: 0 var(--s-3); text-align: left;
  border-radius: var(--r-md); background: var(--surface); border: 1.5px solid var(--line); font: 500 15px/1.25 var(--font-ui);
}
.demo-roles button[aria-pressed="true"] { border-color: var(--blood); background: var(--blush-2); color: var(--blood-deep); font-weight: 600; }
.demo-roles button:disabled { opacity: .45; cursor: not-allowed; }
.demo-events { display: grid; gap: var(--s-2); }
.demo-events button b { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--paper-2); font: 700 12px/1 var(--font-ui); }
.demo-events button:hover, .demo-roles button:hover:not(:disabled) { border-color: var(--line-strong); }

/* ── Counter ─────────────────────────────────────────────── */
.counter__n { font: 700 clamp(56px, 9vw, 96px)/1 var(--font-display); color: var(--blood); letter-spacing: -.02em; font-variant-numeric: lining-nums tabular-nums; }
.counter__l { font: 500 var(--fs-lg)/1.3 var(--font-display); margin-top: var(--s-2); }

/* ── Odometer: digits on wheels (K.ui.odometer) ─────────── */
/* One cell is 1.1em tall; the script moves the wheels in the same unit. */
.odo { display: inline-flex; height: 1.1em; line-height: 1.1em; overflow: hidden; vertical-align: top; }
.odo__w { display: block; height: 1.1em; overflow: hidden; }
.odo__s { display: block; }
.odo__s > span { display: block; height: 1.1em; }
.odo__sep { white-space: pre; }

/* ── QR code ─────────────────────────────────────────────── */
.qr { background: #fff; padding: 14px; border-radius: var(--r-lg); border: 1px solid var(--line); width: min(260px, 70vw); margin: 0 auto; }
.qr svg { width: 100%; height: auto; shape-rendering: crispEdges; }
.qr-code { font: 600 22px/1 var(--font-display); letter-spacing: .08em; text-align: center; margin-top: var(--s-3); }

/* ── Footer ──────────────────────────────────────────────── */
.footer { border-top: 1px solid var(--line); margin-top: var(--s-16); padding: var(--s-8) 0 calc(var(--s-16) + env(safe-area-inset-bottom)); color: var(--ink-2); font-size: var(--fs-sm); }
.footer__in { display: grid; gap: var(--s-4); }
.footer__brand { display: flex; align-items: baseline; gap: var(--s-3); color: var(--ink); }
.footer__links { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); }
.footer__links a { color: var(--ink-2); display: inline-flex; align-items: center; min-height: var(--tap-min); }
@media (min-width: 1080px) { .footer__in { grid-template-columns: 1fr auto; align-items: center; } }

/* Empty state */
.empty { text-align: center; padding: var(--s-10) var(--s-4); color: var(--ink-2); }
.empty .icon { width: 40px; height: 40px; margin: 0 auto var(--s-3); color: var(--line-strong); }

/* ── Link list: full-width rows that are links or buttons ── */
.link-list > li { padding: 0; }
.link-list a, .link-list button {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: var(--tap); padding: var(--s-2) 0;
  color: var(--ink); text-decoration: none; text-align: left; font-weight: 500;
}
.link-list a > span, .link-list button > span { flex: 1; }
.link-list .icon { color: var(--ink-2); }
.link-list .danger, .link-list .danger .icon { color: var(--blood-deep); }
.link-list a:hover > span, .link-list button:hover > span { text-decoration: underline; text-underline-offset: 3px; }

.group--word { font-size: 40px; letter-spacing: -.01em; }
.tabbar:empty { display: none; }

/* Wide-screen-only elements (e.g. the top-bar "Become a donor" button). */
.only-lg { display: none !important; }
@media (min-width: 1080px) { .only-lg { display: inline-flex !important; } }

/* ── FAQ assistant: opened from the top bar (nothing floats over the page) ── */
.assistant-root {
  position: fixed;
  top: calc(var(--topbar-offset) + var(--s-2));
  right: var(--assistant-right, max(var(--gutter), env(safe-area-inset-right, 0px)));
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
}
.assistant-root > * { pointer-events: auto; }
.topbar [data-act="assistant"][aria-expanded="true"] { background: var(--blush); color: var(--blood-deep); }

.assistant-panel {
  animation: sheet-up var(--t-med) var(--ease-out) both;
  width: min(360px, calc(100vw - 32px));
  max-height: min(480px, calc(100dvh - 100px), calc(100vh - 100px));
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.assistant-panel[hidden] { display: none !important; }

.assistant-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  padding-top: max(var(--s-3), env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: 0 0 auto;
}
.assistant-header strong { font-size: var(--fs-sm); color: var(--ink); font-weight: 600; }
.assistant-close {
  background: transparent; color: var(--ink-2); border: 0;
  padding: 6px 10px; font-size: var(--fs-sm);
  min-height: var(--tap-min); min-width: var(--tap-min);
  border-radius: var(--r-sm);
}
.assistant-close:hover { background: var(--paper-2); color: var(--ink); }

.assistant-messages {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; padding: var(--s-3);
  display: flex; flex-direction: column; gap: var(--s-2);
  background: var(--paper); min-height: 0;
}
.assistant-bubble {
  max-width: 92%; padding: 10px 12px; border-radius: var(--r-sm);
  font-size: var(--fs-sm); line-height: 1.4;
  white-space: pre-wrap; word-break: break-word;
}
.assistant-bubble--bot {
  align-self: flex-start; background: var(--surface);
  border: 1px solid var(--line); color: var(--ink);
}
.assistant-bubble--user {
  align-self: flex-end; background: var(--blood); color: #fff;
}
.assistant-bubble--err {
  align-self: flex-start; background: var(--blush-2);
  border: 1px solid var(--blush); color: var(--blood-deep);
}

.assistant-form {
  display: flex; gap: var(--s-2);
  padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex: 0 0 auto;
}
.assistant-form .input {
  flex: 1 1 auto; min-width: 0; font-size: 16px; min-height: var(--tap-min);
}
.assistant-form .btn {
  flex: 0 0 auto; min-height: var(--tap-min); padding: 8px 12px;
}
.assistant-form .btn:disabled { opacity: .6; cursor: not-allowed; }

body.assistant-open {
  position: fixed; left: 0; right: 0; width: 100%;
  overflow: hidden; touch-action: none;
}

/* Desktop: a tall, readable panel with a fixed height so a short chat doesn't collapse into a strip. */
@media (min-width: 761px) {
  .assistant-panel {
    width: min(460px, calc(100vw - 2 * var(--gutter)));
    height: min(680px, calc(100dvh - var(--topbar-offset) - var(--s-6)));
    max-height: none;
  }
  .assistant-header { padding: var(--s-4) var(--s-5); }
  .assistant-header strong { font-size: var(--fs-md); }
  .assistant-messages { padding: var(--s-4) var(--s-5); gap: var(--s-3); }
  .assistant-bubble { font-size: var(--fs-md); line-height: 1.5; padding: 12px 16px; max-width: 88%; }
  .assistant-form { padding: var(--s-3) var(--s-4); }
}
@media (min-width: 1080px) {
  .assistant-root.is-dock,
  .assistant-root.is-open {
    top: var(--topbar-offset);
    right: 0;
    bottom: 0;
    height: auto;
    align-items: stretch;
    pointer-events: none;
  }
  .assistant-root.is-open .assistant-panel,
  .assistant-root.is-dock .assistant-panel {
    width: var(--chat-w, min(560px, 42vw));
    height: 100%;
    max-height: none;
    border-radius: 0;
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: -16px 0 40px rgba(42, 29, 27, .08);
    animation: none;
    transform: translate3d(100%, 0, 0);
    transition: transform .52s cubic-bezier(.22, 1, .36, 1);
    will-change: transform;
  }
  .assistant-root.is-dock.is-open .assistant-panel {
    transform: translate3d(0, 0, 0);
  }
}
@keyframes chat-in { from { transform: translate3d(100%, 0, 0); } }
@keyframes chat-out { to { transform: translate3d(100%, 0, 0); } }

@media (max-width: 760px) {
  .assistant-root.is-open {
    inset: auto;
    top: var(--assistant-vv-offset, 0px);
    left: 0; right: 0; bottom: auto;
    width: 100%;
    height: var(--assistant-vv-height, 100dvh);
    max-height: var(--assistant-vv-height, 100dvh);
    padding: 0; gap: 0; align-items: stretch;
    z-index: 1200;
    background: var(--surface);
    pointer-events: auto;
  }
  .assistant-root.is-open .assistant-panel {
    width: 100%; height: 100%; max-height: none;
    border: 0; border-radius: 0; box-shadow: none;
  }
  .assistant-root.is-open .assistant-form {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
}

/* ── Ad rail: under the top bar ──────────────────────────── */
.ad-rail { padding: var(--s-4) 0 var(--s-4); }
.ad-rail__track {
  display: flex; gap: var(--s-3);
  overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scroll-padding-inline: 2px;
  scrollbar-width: none; padding: 2px 0 6px;
}
.ad-rail__track::-webkit-scrollbar { display: none; }
.ad-plate, .ad-shot {
  flex: 0 0 calc(100% - 28px); scroll-snap-align: start;
  position: relative; min-height: 168px; border-radius: var(--r-lg);
  overflow: hidden; text-decoration: none; color: inherit;
}
.ad-rail--single .ad-plate,
.ad-rail--single .ad-shot { flex-basis: 100%; }
.ad-plate { display: flex; align-items: center; padding: 20px 22px; }
.ad-plate__copy { position: relative; z-index: 1; display: grid; gap: 6px; max-width: 34ch; padding-right: 96px; }
.ad-plate__h { font: 600 20px/1.2 var(--font-display); letter-spacing: -.02em; }
.ad-plate__p { font-size: var(--fs-sm); line-height: 1.4; }
.ad-plate__go { margin-top: 6px; font: 600 14px/1.2 var(--font-ui); text-decoration: underline; text-underline-offset: 3px; }
.ad-plate:focus-visible, .ad-shot:focus-visible { outline: 3px solid var(--blood); outline-offset: -3px; }

.ad-plate--life {
  background:
    radial-gradient(140px 160px at 108% 120%, rgba(255, 255, 255, .18), transparent 68%),
    #8E0E24;
  color: #FFF6F2;
}
.ad-plate--life::before {
  content: ""; position: absolute; right: -36px; bottom: -52px; width: 168px; height: 168px;
  border-radius: 50%; background: rgba(255, 246, 242, .08); pointer-events: none;
}
.ad-plate--life .ad-plate__p { color: #FFE4DE; }
.ad-plate--life .ad-plate__go { color: #fff; }
.ad-plate--life:hover { background:
  radial-gradient(140px 160px at 108% 120%, rgba(255, 255, 255, .22), transparent 68%),
  #9B1229; }
.ad-plate--life:focus-visible { outline-color: #fff; }
.ad-plate__drop {
  position: absolute; right: 6px; bottom: -28px; width: 92px; height: 122px; z-index: 0;
  color: rgba(255, 246, 242, .55); pointer-events: none;
}

.ad-plate--stock {
  background: linear-gradient(180deg, var(--surface) 0%, var(--paper) 100%);
  color: var(--ink); border: 1px solid var(--line); justify-content: space-between; gap: 12px;
}
.ad-plate--stock .ad-plate__copy { padding-right: 0; }
.ad-plate--stock .ad-plate__p { color: var(--ink-2); }
.ad-plate--stock .ad-plate__go { color: var(--blood-deep); }
.ad-plate--stock:hover { border-color: var(--line-strong); }
.ad-plate__groups {
  display: grid; grid-template-columns: auto auto; gap: 8px 14px; flex: none;
  padding: 12px 14px; border-radius: 16px; background: var(--blush);
  font: 700 26px/1 var(--font-display); color: var(--blood-deep); letter-spacing: -.03em;
}
html[data-theme="dark"] .ad-plate__groups { color: #F6D5D0; background: #4a2c32; }

.ad-plate--place { background: #241816; color: #FBF6F1; }
.ad-plate--place .ad-plate__p { color: #E7D5CC; }
.ad-plate--place .ad-plate__go { color: #F6D2C8; }
.ad-plate--place:hover { background: #31211c; }
.ad-plate--place:focus-visible { outline-color: #FBF6F1; }
.ad-plate--place .ad-plate__copy { padding-right: 118px; }
.ad-plate__route {
  position: absolute; right: -4px; top: 8px; width: 40%; height: calc(100% - 16px);
  color: var(--blood); pointer-events: none;
}

.ad-shot { display: block; background: var(--paper-2); border: 1px solid var(--line); }
.ad-shot img { width: 100%; height: 148px; object-fit: cover; display: block; }
.ad-rail--single .ad-shot img { height: auto; max-height: 220px; object-fit: contain; background: var(--paper-2); }
.ad-shot__tag {
  position: absolute; top: 10px; left: 10px;
  font: 500 12px/1 var(--font-ui); color: var(--ink);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  border-radius: var(--r-pill); padding: 5px 8px;
}

@media (min-width: 900px) {
  .ad-rail__track { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; }
  .ad-rail--single .ad-rail__track { grid-template-columns: minmax(0, 1fr); }
  .ad-rail--pair .ad-rail__track { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ad-plate, .ad-shot { flex: none; min-width: 0; }
  .ad-plate__h { font-size: 22px; }
}
@media (max-width: 420px) {
  .ad-plate { padding: 16px; min-height: 156px; }
  .ad-plate__copy { padding-right: 68px; }
  .ad-plate__h { font-size: 18px; }
  .ad-plate__groups { font-size: 22px; gap: 4px 10px; }
}
