/* ==========================================================================
   ReflexBuddy UI kit — Phase 2 design system
   Reusable, theme-aware components. Every class is prefixed .rb- so nothing
   here changes existing pages until they opt in (homepage/games: Phases 3–6).
   The "Site chrome" section at the end upgrades the shared header only.
   Depends on tokens.css.
   ========================================================================== */

/* ---------- 1. Accessibility primitives ---------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--rb-focus-ring);
    outline-offset: 2px;
}
.rb-visually-hidden {
    position: absolute !important; width: 1px !important; height: 1px !important;
    padding: 0 !important; margin: -1px !important; overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important;
}
.rb-touch { min-width: var(--rb-touch-min); min-height: var(--rb-touch-min); }
.rb-num { font-variant-numeric: tabular-nums; }

/* ---------- 2. Typography ---------- */
.rb-display, .rb-h1, .rb-h2, .rb-h3, .rb-h4 {
    margin: 0 0 var(--rb-space-3);
    color: var(--rb-text);
    font-family: var(--rb-font-heading);
    font-weight: var(--rb-fw-extrabold);
    letter-spacing: var(--rb-tracking-tight);
    text-wrap: balance;
}
.rb-display { font-size: var(--rb-fs-3xl); line-height: var(--rb-lh-tight); letter-spacing: var(--rb-tracking-tighter); }
.rb-h1 { font-size: var(--rb-fs-2xl); line-height: 1.12; letter-spacing: var(--rb-tracking-tighter); }
.rb-h2 { font-size: var(--rb-fs-xl); line-height: 1.18; }
.rb-h3 { font-size: var(--rb-fs-lg); line-height: var(--rb-lh-snug); font-weight: var(--rb-fw-bold); }
.rb-h4 { font-size: var(--rb-fs-md); line-height: var(--rb-lh-snug); font-weight: var(--rb-fw-bold); letter-spacing: -.015em; }
.rb-lead { margin: 0 0 var(--rb-space-4); color: var(--rb-text-muted); font-size: var(--rb-fs-md); line-height: var(--rb-lh-relaxed); max-width: var(--rb-measure); }
.rb-body { color: var(--rb-text); font-size: var(--rb-fs-base); line-height: var(--rb-lh-normal); }
.rb-small { color: var(--rb-text-muted); font-size: var(--rb-fs-sm); line-height: 1.55; }
.rb-muted { color: var(--rb-text-muted); }
.rb-eyebrow {
    display: inline-flex; align-items: center; gap: var(--rb-space-2);
    margin: 0 0 var(--rb-space-3);
    color: var(--rb-primary);
    font-size: var(--rb-fs-xs); font-weight: var(--rb-fw-extrabold);
    letter-spacing: var(--rb-tracking-caps); line-height: 1.4; text-transform: uppercase;
}
.rb-text-gradient { background: var(--rb-brand-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
:root[data-theme="dark"] .rb-text-gradient { background-image: linear-gradient(110deg, #c7d2fe 0%, #c4b5fd 60%, #67e8f9 100%); }

.rb-prose { max-width: var(--rb-measure); color: var(--rb-text-muted); font-size: var(--rb-fs-base); line-height: var(--rb-lh-relaxed); }
.rb-prose > * + * { margin-top: var(--rb-space-4); }
.rb-prose h2, .rb-prose h3, .rb-prose h4 { margin: var(--rb-space-8) 0 var(--rb-space-3); color: var(--rb-text); font-weight: var(--rb-fw-bold); letter-spacing: var(--rb-tracking-tight); line-height: var(--rb-lh-snug); }
.rb-prose h2 { font-size: var(--rb-fs-xl); }
.rb-prose h3 { font-size: var(--rb-fs-lg); }
.rb-prose p, .rb-prose ul, .rb-prose ol { margin-bottom: 0; }
.rb-prose strong { color: var(--rb-text); font-weight: var(--rb-fw-bold); }
.rb-prose a { color: var(--rb-primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.rb-prose a:hover { text-decoration-thickness: 2px; }
.rb-prose li + li { margin-top: var(--rb-space-2); }

/* ---------- 3. Layout: container, section, stack, cluster, grid ---------- */
.rb-container { width: min(100% - 2 * var(--rb-gutter), var(--rb-container)); margin-inline: auto; }
.rb-container--narrow { width: min(100% - 2 * var(--rb-gutter), var(--rb-container-narrow)); }
.rb-container--wide { width: min(100% - 2 * var(--rb-gutter), var(--rb-container-wide)); }
.rb-section { padding-block: var(--rb-section-y); }
.rb-section--surface { background: var(--rb-surface); }
.rb-stack { display: flex; flex-direction: column; gap: var(--rb-stack-gap, var(--rb-space-4)); }
.rb-stack > * { margin-block: 0; }
.rb-stack--sm { --rb-stack-gap: var(--rb-space-2); }
.rb-stack--lg { --rb-stack-gap: var(--rb-space-8); }
.rb-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--rb-cluster-gap, var(--rb-space-3)); }
.rb-cluster--between { justify-content: space-between; }
.rb-cluster--center { justify-content: center; }
.rb-grid { display: grid; gap: var(--rb-grid-gap, var(--rb-space-6)); grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--rb-grid-min, 260px)), 1fr)); }
.rb-grid--2, .rb-grid--3, .rb-grid--4 { grid-template-columns: 1fr; }
@media (min-width: 576px) { .rb-grid--2, .rb-grid--3, .rb-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 992px) { .rb-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .rb-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.rb-center { display: grid; place-items: center; text-align: center; }

/* ---------- 4. Buttons ---------- */
.rb-btn {
    --rb-btn-bg: var(--rb-surface);
    --rb-btn-fg: var(--rb-text);
    --rb-btn-border: var(--rb-border-strong);
    --rb-btn-bg-hover: var(--rb-surface-soft);
    --rb-btn-shadow: none;
    position: relative;
    display: inline-flex; align-items: center; justify-content: center; gap: var(--rb-space-2);
    min-height: var(--rb-touch); min-width: var(--rb-touch);
    padding: 0 var(--rb-space-5);
    border: 1px solid var(--rb-btn-border);
    border-radius: 14px;
    background: var(--rb-btn-bg);
    color: var(--rb-btn-fg);
    box-shadow: var(--rb-btn-shadow);
    font-family: inherit; font-size: .9375rem; font-weight: var(--rb-fw-bold); line-height: 1.2; letter-spacing: -.01em;
    text-align: center; text-decoration: none; white-space: nowrap;
    cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
    transition: background-color var(--rb-duration) var(--rb-ease), border-color var(--rb-duration) var(--rb-ease), color var(--rb-duration) var(--rb-ease), box-shadow var(--rb-duration) var(--rb-ease), transform var(--rb-duration-fast) var(--rb-ease);
}
.rb-btn:hover { background: var(--rb-btn-bg-hover); color: var(--rb-btn-fg); }
.rb-btn:active { transform: translateY(1px) scale(.99); }
.rb-btn:focus-visible { outline: 3px solid var(--rb-focus-ring); outline-offset: 3px; }
.rb-btn svg { width: 1.15em; height: 1.15em; flex: 0 0 auto; }

.rb-btn--primary { --rb-btn-bg: var(--rb-primary); --rb-btn-fg: var(--rb-on-primary); --rb-btn-border: var(--rb-primary); --rb-btn-bg-hover: var(--rb-primary-strong); --rb-btn-shadow: var(--rb-shadow-primary); }
.rb-btn--primary:hover { border-color: var(--rb-primary-strong); }
.rb-btn--brand { --rb-btn-bg: var(--rb-brand-gradient); --rb-btn-fg: #fff; --rb-btn-border: transparent; --rb-btn-bg-hover: var(--rb-brand-gradient); --rb-btn-shadow: 0 10px 24px rgba(91, 33, 182, .28); }
.rb-btn--brand:hover { filter: none; box-shadow: 0 14px 30px rgba(91, 33, 182, .36); }
.rb-btn--secondary { --rb-btn-fg: var(--rb-primary); --rb-btn-bg-hover: var(--rb-primary-soft); }
.rb-btn--secondary:hover { border-color: var(--rb-primary); }
.rb-btn--ghost { --rb-btn-bg: transparent; --rb-btn-border: transparent; --rb-btn-fg: var(--rb-text); --rb-btn-bg-hover: var(--rb-surface-soft); }
.rb-btn--danger { --rb-btn-bg: var(--rb-danger-bg); --rb-btn-fg: var(--rb-danger); --rb-btn-border: var(--rb-danger-border); --rb-btn-bg-hover: var(--rb-danger-bg); }
.rb-btn--danger:hover { border-color: var(--rb-danger); }

.rb-btn--sm { min-height: var(--rb-touch-min); min-width: var(--rb-touch-min); padding: 0 var(--rb-space-4); border-radius: var(--rb-radius-sm); font-size: var(--rb-fs-sm); }
.rb-btn--lg { min-height: 56px; padding: 0 var(--rb-space-8); border-radius: var(--rb-radius-md); font-size: 1.0625rem; }
.rb-btn--block { display: flex; width: 100%; }
.rb-btn--icon { padding: 0; width: var(--rb-touch); }
.rb-btn--icon.rb-btn--sm { width: var(--rb-touch-min); }

.rb-btn[aria-pressed="true"] { --rb-btn-bg: var(--rb-primary-soft); --rb-btn-border: var(--rb-primary); --rb-btn-fg: var(--rb-primary); }
.rb-btn:disabled, .rb-btn[aria-disabled="true"] { cursor: not-allowed; opacity: .55; box-shadow: none; transform: none; }
.rb-btn:disabled:hover, .rb-btn[aria-disabled="true"]:hover { background: var(--rb-btn-bg); }
.rb-btn.is-loading { color: transparent !important; pointer-events: none; }
.rb-btn.is-loading::after {
    position: absolute; inset: 0; margin: auto; width: 1.2em; height: 1.2em;
    border: 2.5px solid var(--rb-btn-fg); border-right-color: transparent; border-radius: 50%;
    animation: rb-spin .7s linear infinite; content: "";
}

/* ---------- 5. Form controls ---------- */
.rb-field { display: flex; flex-direction: column; gap: var(--rb-space-2); }
.rb-label { color: var(--rb-text); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-semibold); line-height: 1.4; }
.rb-label__optional { color: var(--rb-text-muted); font-weight: var(--rb-fw-regular); }
.rb-help { margin: 0; color: var(--rb-text-muted); font-size: var(--rb-fs-sm); line-height: 1.5; }
.rb-field-error { display: flex; gap: var(--rb-space-2); margin: 0; color: var(--rb-danger); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-semibold); line-height: 1.5; }

.rb-input, .rb-select, .rb-textarea {
    display: block; width: 100%;
    min-height: var(--rb-touch);
    padding: .75rem 1rem;
    border: 1px solid var(--rb-border-strong);
    border-radius: var(--rb-radius-sm);
    background-color: var(--rb-surface);
    color: var(--rb-text);
    font: inherit; font-size: 1rem; /* 16px prevents iOS zoom on focus */
    line-height: 1.4;
    transition: border-color var(--rb-duration) ease, box-shadow var(--rb-duration) ease, background-color var(--rb-duration) ease;
    appearance: none;
}
:root[data-theme="dark"] :is(.rb-input, .rb-select, .rb-textarea) { background-color: var(--rb-surface-soft); }
.rb-input::placeholder, .rb-textarea::placeholder { color: var(--rb-text-subtle); opacity: 1; }
:is(.rb-input, .rb-select, .rb-textarea):hover { border-color: var(--rb-text-subtle); }
:is(.rb-input, .rb-select, .rb-textarea):focus-visible { border-color: var(--rb-focus-ring); outline: 3px solid var(--rb-focus); outline-offset: 0; }
:is(.rb-input, .rb-select, .rb-textarea)[aria-invalid="true"] { border-color: var(--rb-danger); }
:is(.rb-input, .rb-select, .rb-textarea)[aria-invalid="true"]:focus-visible { outline-color: color-mix(in srgb, var(--rb-danger) 35%, transparent); }
:is(.rb-input, .rb-select, .rb-textarea).is-valid { border-color: var(--rb-success); }
:is(.rb-input, .rb-select, .rb-textarea):disabled { cursor: not-allowed; opacity: .6; background-color: var(--rb-surface-soft); }
.rb-input[readonly] { background-color: var(--rb-surface-soft); }
.rb-textarea { min-height: 128px; resize: vertical; }
.rb-select {
    padding-right: 2.75rem;
    background-image: linear-gradient(45deg, transparent 50%, var(--rb-text-muted) 50%), linear-gradient(135deg, var(--rb-text-muted) 50%, transparent 50%);
    background-position: calc(100% - 22px) 52%, calc(100% - 16px) 52%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    cursor: pointer;
}
:root[data-theme="dark"] .rb-select option { background: var(--rb-surface); color: var(--rb-text); }

/* Checkbox / radio: native control (keeps semantics), branded colour, 44px row. */
.rb-check { display: flex; align-items: center; gap: var(--rb-space-3); min-height: var(--rb-touch-min); color: var(--rb-text); font-size: var(--rb-fs-base); cursor: pointer; }
.rb-check input { flex: 0 0 auto; width: 22px; height: 22px; margin: 0; accent-color: var(--rb-primary); cursor: pointer; }
.rb-check:has(input:disabled) { cursor: not-allowed; opacity: .6; }

/* Switch: <input type="checkbox" role="switch">. */
.rb-switch { display: inline-flex; align-items: center; gap: var(--rb-space-3); min-height: var(--rb-touch-min); color: var(--rb-text); cursor: pointer; }
.rb-switch input {
    position: relative; flex: 0 0 auto; width: 48px; height: 28px; margin: 0;
    border: 1px solid var(--rb-border-strong); border-radius: var(--rb-radius-pill);
    background: var(--rb-surface-soft); appearance: none; cursor: pointer;
    transition: background-color var(--rb-duration) ease, border-color var(--rb-duration) ease;
}
.rb-switch input::before {
    position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
    background: var(--rb-surface); box-shadow: 0 1px 3px rgba(15, 23, 42, .3); content: "";
    transition: transform var(--rb-duration) var(--rb-ease);
}
:root[data-theme="dark"] .rb-switch input::before { background: var(--rb-text-muted); }
.rb-switch input:checked { border-color: var(--rb-primary); background: var(--rb-primary); }
.rb-switch input:checked::before { transform: translateX(20px); background: var(--rb-on-primary); }
:root[data-theme="dark"] .rb-switch input:checked::before { background: var(--rb-on-primary); }
.rb-switch input:disabled { cursor: not-allowed; opacity: .55; }

.rb-range { width: 100%; min-height: var(--rb-touch-min); accent-color: var(--rb-primary); cursor: pointer; }

/* ---------- 6. Cards ---------- */
.rb-card {
    position: relative;
    display: flex; flex-direction: column; gap: var(--rb-space-3);
    padding: var(--rb-card-padding, clamp(1.125rem, .9rem + 1vw, 1.5rem));
    border: 1px solid var(--rb-border);
    border-radius: var(--rb-radius-lg);
    background: var(--rb-surface);
    box-shadow: var(--rb-shadow-sm);
    color: var(--rb-text);
}
.rb-card--flat { box-shadow: none; }
.rb-card--soft { background: var(--rb-surface-soft); border-color: transparent; box-shadow: none; }
.rb-card--soft .rb-card__text, .rb-card--soft .rb-small { color: var(--rb-text-secondary); }
.rb-card--elevated { box-shadow: var(--rb-shadow-card); }
.rb-card--interactive { transition: transform var(--rb-duration) var(--rb-ease), box-shadow var(--rb-duration) var(--rb-ease), border-color var(--rb-duration) var(--rb-ease); }
.rb-card--interactive:hover { transform: translateY(-3px); border-color: var(--rb-border-strong); box-shadow: var(--rb-shadow-card); }
.rb-card--interactive:focus-within { border-color: var(--rb-focus-ring); }
.rb-card__title { margin: 0; color: var(--rb-text); font-size: var(--rb-fs-md); font-weight: var(--rb-fw-bold); letter-spacing: -.02em; line-height: var(--rb-lh-snug); }
.rb-card__text { margin: 0; color: var(--rb-text-muted); font-size: var(--rb-fs-sm); line-height: 1.6; }
.rb-card__footer { display: flex; flex-wrap: wrap; align-items: center; gap: var(--rb-space-3); margin-top: auto; padding-top: var(--rb-space-2); }
/* Whole-card link: put .rb-card__link on the one real <a>; its ::after covers the card. */
.rb-card__link { color: inherit; text-decoration: none; }
.rb-card__link::after { position: absolute; inset: 0; border-radius: inherit; content: ""; }
.rb-card__link:focus-visible { outline: none; }
.rb-card__link:focus-visible::after { outline: 3px solid var(--rb-focus-ring); outline-offset: 2px; }

/* Stat card (scores, personal bests). */
.rb-stat { display: flex; flex-direction: column; gap: var(--rb-space-1); }
.rb-stat__label { color: var(--rb-text-muted); font-size: var(--rb-fs-xs); font-weight: var(--rb-fw-bold); letter-spacing: .08em; text-transform: uppercase; }
.rb-stat__value { color: var(--rb-text); font-size: var(--rb-fs-xl); font-weight: var(--rb-fw-extrabold); letter-spacing: var(--rb-tracking-tight); line-height: 1.1; font-variant-numeric: tabular-nums; }
.rb-stat__unit { margin-left: .2em; color: var(--rb-text-muted); font-size: .55em; font-weight: var(--rb-fw-bold); letter-spacing: 0; }

/* Game card: tone set with data-tone (indigo | violet | cyan | amber | mint | rose | sky). */
.rb-game-card {
    --rb-tone: var(--rb-brand-indigo);
    --rb-tone-soft: color-mix(in srgb, var(--rb-tone) 12%, var(--rb-surface));
    min-height: 220px;
    padding: clamp(1.125rem, .95rem + .8vw, 1.5rem);
    border-radius: 20px;
    overflow: hidden;
    transition: transform var(--rb-duration) var(--rb-ease), box-shadow var(--rb-duration) var(--rb-ease), border-color var(--rb-duration) var(--rb-ease);
}
.rb-game-card[data-tone="violet"] { --rb-tone: #7c3aed; }
.rb-game-card[data-tone="cyan"], .rb-game-card[data-tone="sky"] { --rb-tone: #0e7490; }
.rb-game-card[data-tone="amber"] { --rb-tone: #b45309; }
.rb-game-card[data-tone="mint"] { --rb-tone: #047857; }
.rb-game-card[data-tone="rose"] { --rb-tone: #be123c; }
:root[data-theme="dark"] .rb-game-card { --rb-tone: #a5b4fc; --rb-tone-soft: color-mix(in srgb, var(--rb-tone) 16%, var(--rb-surface)); }
:root[data-theme="dark"] .rb-game-card[data-tone="violet"] { --rb-tone: #c4b5fd; }
:root[data-theme="dark"] .rb-game-card:is([data-tone="cyan"], [data-tone="sky"]) { --rb-tone: #67e8f9; }
:root[data-theme="dark"] .rb-game-card[data-tone="amber"] { --rb-tone: #fcd34d; }
:root[data-theme="dark"] .rb-game-card[data-tone="mint"] { --rb-tone: #6ee7b7; }
:root[data-theme="dark"] .rb-game-card[data-tone="rose"] { --rb-tone: #fda4af; }
.rb-game-card::before { position: absolute; top: -60px; right: -60px; width: 160px; height: 160px; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--rb-tone) 16%, transparent), transparent 70%); content: ""; pointer-events: none; transition: transform var(--rb-duration-slow) var(--rb-ease); }
.rb-game-card:hover { transform: translateY(-4px); border-color: color-mix(in srgb, var(--rb-tone) 40%, var(--rb-border)); box-shadow: var(--rb-shadow-card); }
.rb-game-card:hover::before { transform: scale(1.15); }
.rb-game-card__icon {
    display: grid; place-items: center; width: 52px; height: 52px; flex: 0 0 auto;
    border-radius: var(--rb-radius-md);
    background: var(--rb-tone-soft); color: var(--rb-tone);
    font-size: 1.35rem; font-weight: var(--rb-fw-extrabold); line-height: 1;
}
.rb-game-card__icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.rb-game-card__title { margin: var(--rb-space-2) 0 0; font-size: 1.1875rem; font-weight: var(--rb-fw-extrabold); letter-spacing: -.03em; line-height: 1.2; }
.rb-game-card__meta { display: flex; flex-wrap: wrap; gap: var(--rb-space-2); }
.rb-game-card__cta { display: inline-flex; align-items: center; gap: var(--rb-space-2); min-height: var(--rb-touch-min); color: var(--rb-tone); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-bold); }
.rb-game-card__cta svg { width: 18px; height: 18px; transition: transform var(--rb-duration) var(--rb-ease); }
.rb-game-card:hover .rb-game-card__cta svg, .rb-game-card:focus-within .rb-game-card__cta svg { transform: translateX(4px); }

/* ---------- 7. Badges ---------- */
.rb-badge {
    --rb-badge-fg: var(--rb-text-secondary);
    --rb-badge-bg: var(--rb-surface-soft);
    display: inline-flex; align-items: center; gap: .375rem;
    min-height: 26px; padding: .2rem .65rem;
    border: 1px solid color-mix(in srgb, var(--rb-badge-fg) 18%, transparent);
    border-radius: var(--rb-radius-pill);
    background: var(--rb-badge-bg); color: var(--rb-badge-fg);
    font-size: var(--rb-fs-xs); font-weight: var(--rb-fw-bold); letter-spacing: .01em; line-height: 1.2; white-space: nowrap;
}
.rb-badge--primary { --rb-badge-fg: var(--rb-primary); --rb-badge-bg: var(--rb-primary-soft); }
.rb-badge--violet { --rb-badge-fg: var(--rb-violet); --rb-badge-bg: var(--rb-violet-soft); }
.rb-badge--cyan { --rb-badge-fg: var(--rb-cyan-strong); --rb-badge-bg: var(--rb-cyan-soft); }
.rb-badge--success { --rb-badge-fg: var(--rb-success); --rb-badge-bg: var(--rb-success-bg); }
.rb-badge--warning { --rb-badge-fg: var(--rb-warning); --rb-badge-bg: var(--rb-warning-bg); }
.rb-badge--danger { --rb-badge-fg: var(--rb-danger); --rb-badge-bg: var(--rb-danger-bg); }
.rb-badge--solid { --rb-badge-bg: var(--rb-primary); --rb-badge-fg: var(--rb-on-primary); border-color: transparent; }
.rb-badge__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- 8. Alerts ---------- */
.rb-alert {
    --rb-alert-fg: var(--rb-info);
    --rb-alert-bg: var(--rb-info-bg);
    --rb-alert-border: var(--rb-info-border);
    display: grid; grid-template-columns: auto 1fr; gap: var(--rb-space-3);
    padding: var(--rb-space-4);
    border: 1px solid var(--rb-alert-border);
    border-radius: var(--rb-radius-md);
    background: var(--rb-alert-bg);
    color: var(--rb-text);
    font-size: var(--rb-fs-sm); line-height: 1.55;
}
.rb-alert__icon { display: grid; place-items: center; width: 24px; height: 24px; color: var(--rb-alert-fg); }
.rb-alert__icon svg { width: 22px; height: 22px; }
.rb-alert__title { margin: 0 0 2px; color: var(--rb-text); font-size: var(--rb-fs-base); font-weight: var(--rb-fw-bold); line-height: 1.4; }
.rb-alert__body { margin: 0; color: var(--rb-text-secondary); }
.rb-alert--success { --rb-alert-fg: var(--rb-success); --rb-alert-bg: var(--rb-success-bg); --rb-alert-border: var(--rb-success-border); }
.rb-alert--warning { --rb-alert-fg: var(--rb-warning); --rb-alert-bg: var(--rb-warning-bg); --rb-alert-border: var(--rb-warning-border); }
.rb-alert--danger { --rb-alert-fg: var(--rb-danger); --rb-alert-bg: var(--rb-danger-bg); --rb-alert-border: var(--rb-danger-border); }

/* ---------- 9. Tooltips (hover + keyboard focus; Escape dismisses via site.js) ---------- */
.rb-tooltip { position: relative; display: inline-flex; }
.rb-tooltip__bubble {
    position: absolute; z-index: var(--rb-z-tooltip);
    bottom: calc(100% + 10px); left: 50%;
    width: max-content; max-width: min(260px, 80vw);
    padding: .5rem .75rem;
    border-radius: var(--rb-radius-xs);
    background: var(--rb-brand-navy); color: #f8fafc;
    box-shadow: var(--rb-shadow-pop);
    font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-semibold); line-height: 1.45; text-align: center;
    opacity: 0; visibility: hidden; transform: translate(calc(-50% + var(--rb-tip-x, 0px)), 4px);
    transition: opacity var(--rb-duration) ease, transform var(--rb-duration) ease, visibility var(--rb-duration) ease;
}
:root[data-theme="dark"] .rb-tooltip__bubble { background: #f8fafc; color: #111827; }
.rb-tooltip__bubble::after { position: absolute; top: 100%; left: calc(50% - var(--rb-tip-x, 0px)); border: 6px solid transparent; content: ""; transform: translateX(-50%); }
.rb-tooltip__bubble::after { border-top-color: var(--rb-brand-navy); }
:root[data-theme="dark"] .rb-tooltip__bubble::after { border-top-color: #f8fafc; }
.rb-tooltip:is(:hover, :focus-within):not(.is-dismissed) .rb-tooltip__bubble { opacity: 1; visibility: visible; transform: translate(calc(-50% + var(--rb-tip-x, 0px)), 0); }
.rb-tooltip--bottom .rb-tooltip__bubble { top: calc(100% + 10px); bottom: auto; }
.rb-tooltip--bottom .rb-tooltip__bubble::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--rb-brand-navy); }
:root[data-theme="dark"] .rb-tooltip--bottom .rb-tooltip__bubble::after { border-top-color: transparent; border-bottom-color: #f8fafc; }

/* ---------- 10. Progress indicators ---------- */
.rb-progress {
    display: block; width: 100%; height: 10px;
    border: 0; border-radius: var(--rb-radius-pill);
    background: var(--rb-surface-soft); color: var(--rb-primary);
    overflow: hidden; appearance: none;
}
.rb-progress::-webkit-progress-bar { border-radius: inherit; background: var(--rb-surface-soft); }
.rb-progress::-webkit-progress-value { border-radius: inherit; background: var(--rb-brand-gradient); transition: width var(--rb-duration-slow) var(--rb-ease); }
.rb-progress::-moz-progress-bar { border-radius: inherit; background: var(--rb-brand-gradient); }
:root[data-theme="dark"] .rb-progress::-webkit-progress-value { background: var(--rb-brand-gradient-cool); }
:root[data-theme="dark"] .rb-progress::-moz-progress-bar { background: var(--rb-brand-gradient-cool); }
.rb-progress--sm { height: 6px; }
.rb-progress-label { display: flex; justify-content: space-between; gap: var(--rb-space-3); margin-bottom: var(--rb-space-2); color: var(--rb-text-muted); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-semibold); font-variant-numeric: tabular-nums; }

/* Step dots for rounds / levels. */
.rb-steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.rb-steps__item { width: 10px; height: 10px; border-radius: 50%; background: var(--rb-border-strong); }
.rb-steps__item.is-done { background: var(--rb-primary); }
.rb-steps__item.is-current { background: var(--rb-violet); box-shadow: 0 0 0 4px color-mix(in srgb, var(--rb-violet) 22%, transparent); }

.rb-spinner { display: inline-block; width: 28px; height: 28px; border: 3px solid var(--rb-surface-soft); border-top-color: var(--rb-primary); border-radius: 50%; animation: rb-spin .8s linear infinite; }
.rb-spinner--sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes rb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .rb-spinner, .rb-btn.is-loading::after { animation: rb-pulse 1.6s ease-in-out infinite !important; animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
}
@keyframes rb-pulse { 50% { opacity: .45; } }

/* ---------- 11. Loading, empty and error states ---------- */
.rb-skeleton {
    display: block; min-height: 1em;
    border-radius: var(--rb-radius-xs);
    background: linear-gradient(90deg, var(--rb-skeleton) 25%, var(--rb-skeleton-shine) 37%, var(--rb-skeleton) 63%);
    background-size: 400% 100%;
    animation: rb-shimmer 1.4s ease infinite;
}
.rb-skeleton--text { height: .9em; margin: .35em 0; }
.rb-skeleton--title { height: 1.6em; width: 60%; }
.rb-skeleton--circle { width: 52px; height: 52px; border-radius: var(--rb-radius-md); }
@keyframes rb-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .rb-skeleton { animation: none !important; } }

.rb-state {
    display: flex; flex-direction: column; align-items: center; gap: var(--rb-space-3);
    padding: clamp(2rem, 1.5rem + 3vw, 3.5rem) var(--rb-space-6);
    border: 1px dashed var(--rb-border-strong);
    border-radius: var(--rb-radius-lg);
    background: var(--rb-surface);
    text-align: center;
}
.rb-state__icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 20px; background: var(--rb-primary-soft); color: var(--rb-primary); }
.rb-state__icon svg { width: 30px; height: 30px; }
.rb-state__title { margin: var(--rb-space-2) 0 0; color: var(--rb-text); font-size: var(--rb-fs-lg); font-weight: var(--rb-fw-bold); letter-spacing: -.02em; }
.rb-state__text { max-width: 42ch; margin: 0; color: var(--rb-text-secondary); font-size: var(--rb-fs-sm); line-height: 1.6; }
.rb-state__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--rb-space-3); margin-top: var(--rb-space-2); }
.rb-state--error { border-style: solid; border-color: var(--rb-danger-border); background: var(--rb-danger-bg); }
.rb-state--error .rb-state__icon { background: var(--rb-surface); color: var(--rb-danger); }
.rb-state--loading { border-style: solid; }

/* ---------- 12. Divider & key hint ---------- */
.rb-divider { height: 1px; margin: var(--rb-space-6) 0; border: 0; background: var(--rb-border); }
.rb-kbd { display: inline-block; min-width: 1.75em; padding: .1em .45em; border: 1px solid var(--rb-border-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--rb-surface); color: var(--rb-text); font-family: var(--rb-font-mono); font-size: .8125em; text-align: center; }

/* ==========================================================================
   Site chrome — shared header, brand logo, theme switcher, mobile navigation
   ========================================================================== */

/* Logo: two real image assets; the inactive one is hidden with display:none (never filtered). */
.brand__image--on-dark { display: none; }
:root[data-theme="dark"] .brand__image--on-light.has-dark-variant { display: none; }
:root[data-theme="dark"] .brand__image--on-dark { display: block; }

/* Theme switcher. */
.theme-switch {
    display: inline-flex; align-items: center; gap: var(--rb-space-3);
    min-height: var(--rb-touch-min);
    padding: 4px 14px 4px 4px;
    border: 1px solid var(--rb-border);
    border-radius: var(--rb-radius-pill);
    background: var(--rb-surface);
    color: var(--rb-text-muted);
    font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-semibold);
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: border-color var(--rb-duration) ease, color var(--rb-duration) ease, background-color var(--rb-duration) ease;
}
.theme-switch:hover { border-color: var(--rb-border-strong); color: var(--rb-text); }
.theme-switch:focus-visible { outline: 3px solid var(--rb-focus-ring); outline-offset: 2px; }
.theme-switch__track { position: relative; display: inline-flex; align-items: center; justify-content: space-between; width: 64px; height: 34px; padding: 0 8px; border-radius: var(--rb-radius-pill); background: var(--rb-surface-soft); }
.theme-switch__thumb { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: var(--rb-surface); box-shadow: 0 1px 4px rgba(15, 23, 42, .18); transition: transform var(--rb-duration-slow) var(--rb-ease), background-color var(--rb-duration) ease; }
.theme-switch__icon { position: relative; z-index: 1; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: color var(--rb-duration) ease, opacity var(--rb-duration) ease; }
.theme-switch__icon--sun { color: #b45309; }
.theme-switch__icon--moon { color: var(--rb-text-subtle); }
:root[data-theme="dark"] .theme-switch__thumb { transform: translateX(30px); background: #312e81; }
:root[data-theme="dark"] .theme-switch__icon--sun { color: var(--rb-text-subtle); }
:root[data-theme="dark"] .theme-switch__icon--moon { color: #e0e7ff; }
.theme-switch__label { white-space: nowrap; }

/* Navigation links: 44px targets, clear active and focus states. */
.site-nav__link:focus-visible { outline: 3px solid var(--rb-focus-ring); outline-offset: 2px; border-radius: 6px; }
.site-nav__link[aria-current="page"] { color: var(--rb-text); }
.site-nav__link { min-width: var(--rb-touch-min); justify-content: center; }
.site-header .brand { min-height: var(--rb-touch-min); }

@media (max-width: 767.98px) {
    .theme-switch--desktop { display: none; }
    .site-nav { padding: var(--rb-space-2) var(--rb-gutter) var(--rb-space-5); border-radius: 0 0 var(--rb-radius-lg) var(--rb-radius-lg); }
    .site-nav__link { min-height: var(--rb-touch); justify-content: flex-start; padding-inline: var(--rb-space-2); font-size: var(--rb-fs-base); }
    .site-nav__link.is-active { color: var(--rb-primary); }
    .site-nav__mobile-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--rb-space-3); padding-top: var(--rb-space-4); }
    .site-nav__mobile-actions .theme-switch { width: 100%; justify-content: flex-start; }
    .nav-toggle { margin-left: auto; }
    body.nav-is-open::after { position: fixed; inset: var(--rb-header-height) 0 0; z-index: calc(var(--rb-z-header) - 1); background: var(--rb-overlay); content: ""; }
}
@media (min-width: 768px) {
    .site-nav__mobile-actions { display: none; }
}

/* Footer (Phase 3). */
.rb-footer { padding-block: var(--rb-space-12) var(--rb-space-6); border-top: 1px solid var(--rb-border); background: var(--rb-footer); color: var(--rb-text-muted); }
.rb-footer__grid { display: grid; gap: var(--rb-space-8); grid-template-columns: 1fr 1fr; }
.rb-footer__brand { grid-column: 1 / -1; }
.rb-footer__brand .brand { display: inline-flex; align-items: center; min-height: var(--rb-touch-min); }
.rb-footer__brand p { max-width: 34ch; margin: var(--rb-space-3) 0 0; color: var(--rb-text-secondary); font-size: var(--rb-fs-sm); line-height: 1.6; }
.rb-footer__col--tests { grid-column: 1 / -1; }
.rb-footer__label { margin: 0 0 var(--rb-space-2); color: var(--rb-text); font-size: var(--rb-fs-xs); font-weight: var(--rb-fw-extrabold); letter-spacing: .1em; text-transform: uppercase; }
.rb-footer ul { display: grid; margin: 0; padding: 0; list-style: none; }
.rb-footer__col--tests ul { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--rb-space-4); }
.rb-footer a { display: inline-flex; align-items: center; min-height: var(--rb-touch-min); min-width: var(--rb-touch-min); color: var(--rb-text-secondary); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-semibold); overflow-wrap: break-word; }
.rb-footer a:hover { color: var(--rb-primary); text-decoration: underline; text-underline-offset: 3px; }
.rb-footer__bottom { display: flex; flex-direction: column; gap: var(--rb-space-2); margin-top: var(--rb-space-10); padding-top: var(--rb-space-6); border-top: 1px solid var(--rb-border); color: var(--rb-text-secondary); font-size: var(--rb-fs-xs); }
@media (min-width: 768px) {
    .rb-footer__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .rb-footer__col--tests { grid-column: span 2; }
}
@media (min-width: 992px) {
    .rb-footer__grid { grid-template-columns: 1.3fr 1.4fr .8fr .8fr; }
    .rb-footer__brand { grid-column: auto; }
    .rb-footer__col--tests { grid-column: auto; grid-row: auto; }
    .rb-footer__bottom { flex-direction: row; justify-content: space-between; }
}

/* Accordion (Phase 4): <div class="rb-accordion"><details class="rb-accordion__item"><summary>…<span class="rb-accordion__icon"></span></summary><p>…</p></details></div> */
.rb-accordion { display: flex; flex-direction: column; gap: var(--rb-space-3); }
.rb-accordion__item { border: 1px solid var(--rb-border); border-radius: var(--rb-radius-md); background: var(--rb-surface); transition: border-color var(--rb-duration) ease, box-shadow var(--rb-duration) ease; }
.rb-accordion__item[open] { border-color: color-mix(in srgb, var(--rb-primary) 35%, var(--rb-border)); box-shadow: var(--rb-shadow-sm); }
.rb-accordion__item summary { display: flex; align-items: center; justify-content: space-between; gap: var(--rb-space-4); min-height: 60px; padding: var(--rb-space-4) var(--rb-space-5); border-radius: inherit; color: var(--rb-text); font-weight: var(--rb-fw-bold); line-height: 1.4; list-style: none; cursor: pointer; }
.rb-accordion__item summary::-webkit-details-marker { display: none; }
.rb-accordion__item summary:focus-visible { outline: 3px solid var(--rb-focus-ring); outline-offset: 2px; }
.rb-accordion__icon { position: relative; flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%; background: var(--rb-surface-soft); }
.rb-accordion__icon::before, .rb-accordion__icon::after { position: absolute; top: 50%; left: 50%; width: 12px; height: 2px; border-radius: 2px; background: var(--rb-primary); content: ""; transform: translate(-50%, -50%); transition: transform var(--rb-duration) var(--rb-ease); }
.rb-accordion__icon::after { transform: translate(-50%, -50%) rotate(90deg); }
.rb-accordion__item[open] .rb-accordion__icon::after { transform: translate(-50%, -50%) rotate(0deg); }
.rb-accordion__item p { margin: 0; padding: 0 var(--rb-space-5) var(--rb-space-5); color: var(--rb-text-muted); line-height: 1.7; }

/* Breadcrumb links: 44px hit area (Phase 4). */
.breadcrumbs__item a { display: inline-flex; align-items: center; min-height: var(--rb-touch-min); min-width: var(--rb-touch-min); }
.breadcrumbs__item a:focus-visible { outline: 3px solid var(--rb-focus-ring); outline-offset: 2px; border-radius: 6px; }
.breadcrumb-wrap { padding-top: 4px; padding-bottom: 0; }
.breadcrumbs { align-items: center; color: var(--rb-text-muted); font-size: var(--rb-fs-sm); }
.breadcrumbs__item { display: inline-flex; align-items: center; min-height: var(--rb-touch-min); }
.breadcrumbs__item:not(:last-child)::after { color: var(--rb-text-muted); }
.breadcrumbs__item a { color: var(--rb-text-muted); text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; }
.breadcrumbs__item a:hover { color: var(--rb-primary); text-decoration-color: currentColor; }
.breadcrumbs__item.is-current { color: var(--rb-text); font-weight: var(--rb-fw-semibold); }
@media (max-width: 767.98px) { .breadcrumb-wrap { display: none; } }
