/* ==========================================================================
   TenX Design System
   Monochrome, soft, and quiet. Every value lives in a token so apps can
   re-tune the system without touching component CSS.
   ========================================================================== */

/* ---------- 1. Primitive tokens ---------- */
:root {
    --tx-white: #ffffff;
    --tx-gray-50: #fafafa;
    --tx-gray-100: #f4f4f4;
    --tx-gray-150: #ededed;
    --tx-gray-200: #e4e4e4;
    --tx-gray-300: #d0d0d0;
    --tx-gray-400: #a3a3a3;
    --tx-gray-500: #737373;
    --tx-gray-600: #525252;
    --tx-gray-700: #383838;
    --tx-gray-800: #242424;
    --tx-gray-850: #1a1a1a;
    --tx-gray-900: #141414;
    --tx-black: #0a0a0a;

    /* Typography */
    --tx-font-sans: "Inter", "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Helvetica Neue", Arial, sans-serif;
    --tx-font-display: "Inter Display", "Inter", "Segoe UI Variable Display", "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Display", Roboto, sans-serif;
    --tx-font-mono: "JetBrains Mono", "Cascadia Code", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

    --tx-text-xs: 0.75rem;
    --tx-text-sm: 0.875rem;
    --tx-text-md: 0.9375rem;
    --tx-text-lg: 1.125rem;
    --tx-text-xl: 1.375rem;
    --tx-text-2xl: 1.75rem;
    --tx-text-3xl: 2.25rem;
    --tx-text-4xl: 3rem;

    --tx-leading-tight: 1.15;
    --tx-leading-snug: 1.35;
    --tx-leading-normal: 1.55;

    --tx-tracking-tight: -0.022em;
    --tx-tracking-snug: -0.011em;
    --tx-tracking-wide: 0.06em;

    /* Spacing (4px base) */
    --tx-space-1: 0.25rem;
    --tx-space-2: 0.5rem;
    --tx-space-3: 0.75rem;
    --tx-space-4: 1rem;
    --tx-space-5: 1.25rem;
    --tx-space-6: 1.5rem;
    --tx-space-8: 2rem;
    --tx-space-10: 2.5rem;
    --tx-space-12: 3rem;
    --tx-space-16: 4rem;

    /* Shape */
    --tx-radius-xs: 6px;
    --tx-radius-sm: 8px;
    --tx-radius-md: 12px;
    --tx-radius-lg: 18px;
    --tx-radius-xl: 24px;
    --tx-radius-full: 999px;

    /* Control sizing */
    --tx-control-sm: 2rem;
    --tx-control-md: 2.5rem;
    --tx-control-lg: 3rem;

    /* Motion — long, soft deceleration */
    --tx-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --tx-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --tx-duration-fast: 140ms;
    --tx-duration: 240ms;
    --tx-duration-slow: 420ms;

    /* Safe areas. iOS and the web fill these in through env(); Android reports only display
       cutouts there, so the native host overwrites them with the real window insets. */
    --tx-inset-top: env(safe-area-inset-top, 0px);
    --tx-inset-right: env(safe-area-inset-right, 0px);
    --tx-inset-bottom: env(safe-area-inset-bottom, 0px);
    --tx-inset-left: env(safe-area-inset-left, 0px);

    --tx-z-dropdown: 1000;
    --tx-z-overlay: 1100;
    --tx-z-toast: 1200;
}

/* ---------- 2. Semantic tokens: light (default) ---------- */
:root,
[data-theme="light"] {
    color-scheme: light;

    --tx-bg: var(--tx-white);
    --tx-bg-subtle: var(--tx-gray-50);
    --tx-surface: var(--tx-white);
    --tx-surface-raised: var(--tx-white);
    --tx-surface-sunken: var(--tx-gray-100);
    --tx-surface-hover: var(--tx-gray-100);
    --tx-surface-active: var(--tx-gray-150);

    --tx-fg: var(--tx-black);
    --tx-fg-muted: var(--tx-gray-600);
    /* Deliberately not gray-500 (#737373): that reaches 4.74:1 on white but only 4.31:1 on
       --tx-surface-sunken, which is where most subtle text actually sits — striped rows, hints
       inside panels. #6b6b6b clears 4.5:1 on both. */
    --tx-fg-subtle: #6b6b6b;
    --tx-fg-disabled: var(--tx-gray-400);

    --tx-border: var(--tx-gray-200);
    --tx-border-subtle: var(--tx-gray-150);
    --tx-border-strong: var(--tx-gray-300);

    /* The "accent" is simply ink: black on white, white on black. */
    --tx-accent: var(--tx-black);
    --tx-accent-hover: var(--tx-gray-800);
    --tx-accent-active: var(--tx-gray-700);
    --tx-on-accent: var(--tx-white);

    --tx-ring: var(--tx-black);
    --tx-overlay: rgb(10 10 10 / 0.32);

    --tx-success: #1d7a4b;
    --tx-success-soft: #eef7f2;
    --tx-warning: #9a5b00;
    --tx-warning-soft: #fdf6ea;
    --tx-danger: #c0271d;
    --tx-danger-soft: #fdf0ef;
    --tx-danger-solid: #c0271d;

    /* Status colours as they sit on the inverted accent surface (toasts) */
    --tx-on-accent-success: #7ee2b0;
    --tx-on-accent-warning: #ffc56a;
    --tx-on-accent-danger: #ff8f86;

    --tx-switch-off: var(--tx-gray-300);

    --tx-shadow-xs: 0 1px 2px rgb(0 0 0 / 0.04);
    --tx-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 6px rgb(0 0 0 / 0.04);
    --tx-shadow-md: 0 2px 4px rgb(0 0 0 / 0.03), 0 8px 24px rgb(0 0 0 / 0.07);
    --tx-shadow-lg: 0 4px 8px rgb(0 0 0 / 0.03), 0 24px 64px rgb(0 0 0 / 0.14);
}

/* ---------- 3. Semantic tokens: dark ---------- */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --tx-bg: var(--tx-black);
        --tx-bg-subtle: #0f0f0f;
        --tx-surface: var(--tx-gray-900);
        --tx-surface-raised: var(--tx-gray-850);
        --tx-surface-sunken: #070707;
        --tx-surface-hover: var(--tx-gray-850);
        --tx-surface-active: var(--tx-gray-800);
        --tx-fg: #f5f5f5;
        --tx-fg-muted: var(--tx-gray-400);
        --tx-fg-subtle: #8a8a8a;
        --tx-fg-disabled: var(--tx-gray-600);
        --tx-border: #262626;
        --tx-border-subtle: #1c1c1c;
        --tx-border-strong: #474747;
        --tx-accent: #f5f5f5;
        --tx-accent-hover: var(--tx-gray-200);
        --tx-accent-active: var(--tx-gray-300);
        --tx-on-accent: var(--tx-black);
        --tx-ring: #f5f5f5;
        --tx-overlay: rgb(0 0 0 / 0.6);
        --tx-success: #5cc493;
        --tx-success-soft: #0f1f17;
        --tx-warning: #e3ad52;
        --tx-warning-soft: #221a0c;
        --tx-danger: #f0766c;
        --tx-danger-soft: #2a1210;
        --tx-on-accent-success: #1d7a4b;
        --tx-on-accent-warning: #9a5b00;
        --tx-on-accent-danger: #c0271d;
        --tx-switch-off: var(--tx-gray-700);
        --tx-shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
        --tx-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4), 0 2px 6px rgb(0 0 0 / 0.3);
        --tx-shadow-md: 0 2px 4px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.45);
        --tx-shadow-lg: 0 4px 8px rgb(0 0 0 / 0.3), 0 24px 64px rgb(0 0 0 / 0.6);
    }
}

[data-theme="dark"] {
    color-scheme: dark;
    --tx-bg: var(--tx-black);
    --tx-bg-subtle: #0f0f0f;
    --tx-surface: var(--tx-gray-900);
    --tx-surface-raised: var(--tx-gray-850);
    --tx-surface-sunken: #070707;
    --tx-surface-hover: var(--tx-gray-850);
    --tx-surface-active: var(--tx-gray-800);
    --tx-fg: #f5f5f5;
    --tx-fg-muted: var(--tx-gray-400);
    --tx-fg-subtle: #8a8a8a;
    --tx-fg-disabled: var(--tx-gray-600);
    --tx-border: #262626;
    --tx-border-subtle: #1c1c1c;
    --tx-border-strong: #474747;
    --tx-accent: #f5f5f5;
    --tx-accent-hover: var(--tx-gray-200);
    --tx-accent-active: var(--tx-gray-300);
    --tx-on-accent: var(--tx-black);
    --tx-ring: #f5f5f5;
    --tx-overlay: rgb(0 0 0 / 0.6);
    --tx-success: #5cc493;
    --tx-success-soft: #0f1f17;
    --tx-warning: #e3ad52;
    --tx-warning-soft: #221a0c;
    --tx-danger: #f0766c;
    --tx-danger-soft: #2a1210;
    --tx-on-accent-success: #1d7a4b;
    --tx-on-accent-warning: #9a5b00;
    --tx-on-accent-danger: #c0271d;
    --tx-switch-off: var(--tx-gray-700);
    --tx-shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
    --tx-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4), 0 2px 6px rgb(0 0 0 / 0.3);
    --tx-shadow-md: 0 2px 4px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.45);
    --tx-shadow-lg: 0 4px 8px rgb(0 0 0 / 0.3), 0 24px 64px rgb(0 0 0 / 0.6);
}

/* ---------- 4. Base ---------- */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--tx-bg);
    color: var(--tx-fg);
    font-family: var(--tx-font-sans);
    font-size: var(--tx-text-md);
    line-height: var(--tx-leading-normal);
    letter-spacing: var(--tx-tracking-snug);
    font-feature-settings: "cv11", "ss01", "ss03";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    transition: background-color var(--tx-duration) var(--tx-ease), color var(--tx-duration) var(--tx-ease);
}

::selection {
    background: var(--tx-fg);
    color: var(--tx-bg);
}

:focus-visible {
    outline: 2px solid var(--tx-ring);
    outline-offset: 2px;
}

/* ---------- 5. Typography helpers ---------- */
.tx-display, .tx-h1, .tx-h2, .tx-h3, .tx-h4 {
    margin: 0;
    font-family: var(--tx-font-display);
    font-weight: 600;
    letter-spacing: var(--tx-tracking-tight);
    line-height: var(--tx-leading-tight);
    color: var(--tx-fg);
    text-wrap: balance;
}

.tx-display { font-size: clamp(2.5rem, 6vw, 4rem); letter-spacing: -0.035em; font-weight: 600; }
.tx-h1 { font-size: var(--tx-text-3xl); }
.tx-h2 { font-size: var(--tx-text-2xl); }
.tx-h3 { font-size: var(--tx-text-xl); }
.tx-h4 { font-size: var(--tx-text-lg); letter-spacing: var(--tx-tracking-snug); }

.tx-lead { margin: 0; font-size: var(--tx-text-lg); line-height: var(--tx-leading-normal); color: var(--tx-fg-muted); text-wrap: pretty; }
.tx-body { margin: 0; color: var(--tx-fg); text-wrap: pretty; }
.tx-muted { color: var(--tx-fg-muted); }
.tx-subtle { color: var(--tx-fg-subtle); }
.tx-small { font-size: var(--tx-text-sm); }
.tx-mono { font-family: var(--tx-font-mono); font-size: 0.92em; letter-spacing: 0; }

.tx-eyebrow {
    margin: 0;
    font-size: var(--tx-text-xs);
    font-weight: 500;
    letter-spacing: var(--tx-tracking-wide);
    text-transform: uppercase;
    color: var(--tx-fg-subtle);
}

.tx-link {
    color: var(--tx-fg);
    text-decoration: underline;
    text-decoration-color: var(--tx-border-strong);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: text-decoration-color var(--tx-duration-fast) var(--tx-ease);
}

.tx-link:hover { text-decoration-color: currentColor; }

/* ---------- 6. Icon ---------- */
.tx-icon {
    display: inline-block;
    flex: none;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tx-logo {
    display: inline-block;
    flex: none;
    color: currentColor;
}

/* ---------- 7. Button ---------- */
.tx-btn {
    --_h: var(--tx-control-md);
    --_px: var(--tx-space-5);
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--tx-space-2);
    height: var(--_h);
    padding: 0 var(--_px);
    border: 1px solid transparent;
    border-radius: var(--tx-radius-full);
    font: inherit;
    font-size: var(--tx-text-sm);
    font-weight: 500;
    letter-spacing: var(--tx-tracking-snug);
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition:
        background-color var(--tx-duration-fast) var(--tx-ease),
        border-color var(--tx-duration-fast) var(--tx-ease),
        color var(--tx-duration-fast) var(--tx-ease),
        box-shadow var(--tx-duration) var(--tx-ease),
        transform var(--tx-duration) var(--tx-ease);
}

.tx-btn:active:not(:disabled):not([aria-disabled="true"]) { transform: scale(0.975); }

.tx-btn--sm { --_h: var(--tx-control-sm); --_px: var(--tx-space-4); font-size: var(--tx-text-xs); }
.tx-btn--lg { --_h: var(--tx-control-lg); --_px: var(--tx-space-6); font-size: var(--tx-text-md); }
.tx-btn--block { display: flex; width: 100%; }
.tx-btn--icon { width: var(--_h); padding: 0; }
.tx-btn .tx-icon { font-size: 1.15em; }

.tx-btn--primary { background: var(--tx-accent); color: var(--tx-on-accent); box-shadow: var(--tx-shadow-xs); }
.tx-btn--primary:hover { background: var(--tx-accent-hover); box-shadow: var(--tx-shadow-sm); }
.tx-btn--primary:active { background: var(--tx-accent-active); }

.tx-btn--secondary { background: var(--tx-surface); color: var(--tx-fg); border-color: var(--tx-border); box-shadow: var(--tx-shadow-xs); }
.tx-btn--secondary:hover { background: var(--tx-surface-hover); border-color: var(--tx-border-strong); }
.tx-btn--secondary:active { background: var(--tx-surface-active); }

.tx-btn--ghost { background: transparent; color: var(--tx-fg); }
.tx-btn--ghost:hover { background: var(--tx-surface-hover); }
.tx-btn--ghost:active { background: var(--tx-surface-active); }

.tx-btn--danger { background: var(--tx-danger-solid); color: #fff; box-shadow: var(--tx-shadow-xs); }
.tx-btn--danger:hover { filter: brightness(1.08); }

.tx-btn--link {
    height: auto;
    padding: 0;
    border-radius: var(--tx-radius-xs);
    background: none;
    color: var(--tx-fg);
    text-decoration: underline;
    text-decoration-color: var(--tx-border-strong);
    text-underline-offset: 4px;
}

.tx-btn--link:hover { text-decoration-color: currentColor; }
.tx-btn--link:active:not(:disabled) { transform: none; }

.tx-btn:disabled,
.tx-btn[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.42;
    box-shadow: none;
    filter: none;
}

.tx-btn[aria-busy="true"] { cursor: progress; }
.tx-btn[aria-busy="true"] > :not(.tx-spinner) { visibility: hidden; }
.tx-btn[aria-busy="true"] > .tx-spinner { position: absolute; inset: 0; margin: auto; }

/* ---------- 8. Spinner ---------- */
.tx-spinner {
    display: inline-block;
    flex: none;
    width: 1.1em;
    height: 1.1em;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    opacity: 0.85;
    animation: tx-spin 0.8s linear infinite;
}

.tx-spinner--lg { width: 1.75rem; height: 1.75rem; border-width: 2px; }

@keyframes tx-spin { to { transform: rotate(360deg); } }

/* ---------- 9. Card ---------- */
.tx-card {
    display: flex;
    flex-direction: column;
    background: var(--tx-surface);
    border: 1px solid var(--tx-border);
    border-radius: var(--tx-radius-lg);
    box-shadow: var(--tx-shadow-xs);
    overflow: hidden;
    transition: box-shadow var(--tx-duration) var(--tx-ease), border-color var(--tx-duration) var(--tx-ease), transform var(--tx-duration) var(--tx-ease);
}

.tx-card--flat { box-shadow: none; }
.tx-card--elevated { border-color: var(--tx-border-subtle); box-shadow: var(--tx-shadow-md); }

.tx-card--interactive { cursor: pointer; }
.tx-card--interactive:hover { border-color: var(--tx-border-strong); box-shadow: var(--tx-shadow-md); transform: translateY(-2px); }

.tx-card__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--tx-space-4); padding: var(--tx-space-6) var(--tx-space-6) 0; }
.tx-card__heading { display: grid; gap: var(--tx-space-1); min-width: 0; }
.tx-card__title { margin: 0; font-size: var(--tx-text-lg); font-weight: 600; letter-spacing: var(--tx-tracking-tight); line-height: var(--tx-leading-snug); }
.tx-card__subtitle { margin: 0; font-size: var(--tx-text-sm); color: var(--tx-fg-muted); }
.tx-card__body { padding: var(--tx-space-6); flex: 1; }
.tx-card__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--tx-space-2);
    padding: var(--tx-space-4) var(--tx-space-6);
    border-top: 1px solid var(--tx-border-subtle);
    background: var(--tx-bg-subtle);
}

/* ---------- 10. Form fields ---------- */
.tx-field { display: grid; gap: var(--tx-space-2); min-width: 0; }

.tx-field__label {
    font-size: var(--tx-text-sm);
    font-weight: 500;
    color: var(--tx-fg);
}

.tx-field__required { margin-left: 2px; color: var(--tx-fg-subtle); }

.tx-field__hint, .tx-field__error { margin: 0; font-size: var(--tx-text-xs); line-height: var(--tx-leading-snug); }
.tx-field__hint { color: var(--tx-fg-subtle); }
.tx-field__error { color: var(--tx-danger); }

.tx-control {
    --_h: var(--tx-control-md);
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--tx-space-2);
    min-height: var(--_h);
    padding: 0 var(--tx-space-3);
    background: var(--tx-surface);
    border: 1px solid var(--tx-border);
    border-radius: var(--tx-radius-md);
    color: var(--tx-fg-subtle);
    transition: border-color var(--tx-duration-fast) var(--tx-ease), box-shadow var(--tx-duration) var(--tx-ease), background-color var(--tx-duration-fast) var(--tx-ease);
}

.tx-control:hover { border-color: var(--tx-border-strong); }

.tx-control:focus-within {
    border-color: var(--tx-fg);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--tx-fg) 8%, transparent);
}

.tx-control--sm { --_h: var(--tx-control-sm); border-radius: var(--tx-radius-sm); }
.tx-control--lg { --_h: var(--tx-control-lg); }
.tx-control--textarea { padding: 0; align-items: stretch; }

.tx-control__input {
    flex: 1;
    min-width: 0;
    height: calc(var(--_h) - 2px);
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--tx-fg);
    font: inherit;
    font-size: var(--tx-text-md);
    letter-spacing: inherit;
    appearance: none;
}

.tx-control--sm .tx-control__input { font-size: var(--tx-text-sm); }
.tx-control__input::placeholder { color: var(--tx-fg-subtle); opacity: 1; }
.tx-control__input:focus-visible { outline: none; }

textarea.tx-control__input {
    height: auto;
    min-height: 6rem;
    padding: var(--tx-space-3);
    line-height: var(--tx-leading-normal);
    resize: vertical;
}

select.tx-control__input { padding-right: var(--tx-space-6); cursor: pointer; }
.tx-control__chevron { position: absolute; right: var(--tx-space-3); pointer-events: none; }

.tx-control__adornment { display: inline-flex; align-items: center; flex: none; color: var(--tx-fg-subtle); }

.tx-field--invalid .tx-control { border-color: var(--tx-danger); }
.tx-field--invalid .tx-control:focus-within { box-shadow: 0 0 0 4px color-mix(in srgb, var(--tx-danger) 14%, transparent); }

.tx-field--disabled .tx-control { background: var(--tx-surface-sunken); border-color: var(--tx-border-subtle); cursor: not-allowed; }
.tx-field--disabled .tx-control__input { color: var(--tx-fg-disabled); cursor: not-allowed; }
.tx-field--disabled .tx-field__label { color: var(--tx-fg-muted); }

/* Autofill: keep it monochrome */
.tx-control__input:-webkit-autofill {
    -webkit-text-fill-color: var(--tx-fg);
    -webkit-box-shadow: 0 0 0 100px var(--tx-surface) inset;
    transition: background-color 9999s;
}

/* ---------- 11. Checkbox & switch ---------- */
.tx-check {
    display: inline-flex;
    align-items: flex-start;
    gap: var(--tx-space-3);
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.tx-check__input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    pointer-events: none;
}

.tx-check__box {
    display: grid;
    place-items: center;
    flex: none;
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.15em;
    border: 1.5px solid var(--tx-border-strong);
    border-radius: 5px;
    background: var(--tx-surface);
    color: var(--tx-on-accent);
    transition: background-color var(--tx-duration-fast) var(--tx-ease), border-color var(--tx-duration-fast) var(--tx-ease), transform var(--tx-duration) var(--tx-ease);
}

.tx-check__box .tx-icon {
    font-size: 0.8rem;
    stroke-width: 2.4;
    stroke-dasharray: 20;
    stroke-dashoffset: 20;
    transition: stroke-dashoffset var(--tx-duration) var(--tx-ease);
}

.tx-check:hover .tx-check__box { border-color: var(--tx-fg-muted); }
.tx-check:active .tx-check__box { transform: scale(0.92); }

.tx-check__input:checked + .tx-check__box { background: var(--tx-accent); border-color: var(--tx-accent); }
.tx-check__input:checked + .tx-check__box .tx-icon { stroke-dashoffset: 0; }
.tx-check__input:focus-visible + .tx-check__box,
.tx-check__input:focus-visible + .tx-switch__track { outline: 2px solid var(--tx-ring); outline-offset: 2px; }

.tx-check__text { display: grid; gap: 2px; font-size: var(--tx-text-md); line-height: var(--tx-leading-snug); color: var(--tx-fg); }
.tx-check__desc { font-size: var(--tx-text-sm); color: var(--tx-fg-muted); }

.tx-check--disabled { cursor: not-allowed; opacity: 0.5; }

.tx-switch__track {
    position: relative;
    flex: none;
    width: 2.375rem;
    height: 1.375rem;
    margin-top: 0.05em;
    border-radius: var(--tx-radius-full);
    background: var(--tx-switch-off);
    transition: background-color var(--tx-duration) var(--tx-ease);
}

.tx-switch__thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: calc(1.375rem - 6px);
    height: calc(1.375rem - 6px);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.2), 0 2px 6px rgb(0 0 0 / 0.08);
    transition: transform var(--tx-duration-slow) var(--tx-ease), width var(--tx-duration) var(--tx-ease);
}

.tx-check:active .tx-switch__thumb { width: calc(1.375rem - 2px); }

.tx-check__input:checked + .tx-switch__track { background: var(--tx-accent); }
.tx-check__input:checked + .tx-switch__track .tx-switch__thumb { transform: translateX(1rem); background: var(--tx-on-accent); }
.tx-check:active .tx-check__input:checked + .tx-switch__track .tx-switch__thumb { transform: translateX(calc(1rem - 4px)); }

/* ---------- 12. Badge ---------- */
.tx-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    height: 1.5rem;
    padding: 0 0.625rem;
    border: 1px solid var(--tx-border);
    border-radius: var(--tx-radius-full);
    background: var(--tx-surface);
    color: var(--tx-fg);
    font-size: var(--tx-text-xs);
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

.tx-badge--solid { background: var(--tx-accent); border-color: var(--tx-accent); color: var(--tx-on-accent); }
.tx-badge--soft { background: var(--tx-surface-sunken); border-color: transparent; }
.tx-badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.tx-badge--success { color: var(--tx-success); }
.tx-badge--warning { color: var(--tx-warning); }
.tx-badge--danger { color: var(--tx-danger); }
.tx-badge--soft.tx-badge--success { background: var(--tx-success-soft); }
.tx-badge--soft.tx-badge--warning { background: var(--tx-warning-soft); }
.tx-badge--soft.tx-badge--danger { background: var(--tx-danger-soft); }

/* ---------- 13. Avatar ---------- */
.tx-avatar {
    --_s: 2.5rem;
    position: relative;
    display: inline-grid;
    place-items: center;
    flex: none;
    width: var(--_s);
    height: var(--_s);
    border-radius: 50%;
    background: var(--tx-surface-sunken);
    color: var(--tx-fg);
    font-size: calc(var(--_s) * 0.38);
    font-weight: 600;
    letter-spacing: 0;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px var(--tx-border-subtle);
}

.tx-avatar--sm { --_s: 2rem; }
.tx-avatar--lg { --_s: 3.5rem; }
.tx-avatar--inverse { background: var(--tx-accent); color: var(--tx-on-accent); box-shadow: none; }
.tx-avatar img { width: 100%; height: 100%; object-fit: cover; }

.tx-avatar-group { display: inline-flex; }
.tx-avatar-group > .tx-avatar { box-shadow: 0 0 0 2px var(--tx-bg); }
.tx-avatar-group > .tx-avatar + .tx-avatar { margin-left: -0.4rem; }

/* ---------- 14. Alert ---------- */
.tx-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--tx-space-3);
    padding: var(--tx-space-4);
    border: 1px solid var(--tx-border);
    border-radius: var(--tx-radius-md);
    background: var(--tx-surface);
    color: var(--tx-fg);
    font-size: var(--tx-text-sm);
    line-height: var(--tx-leading-snug);
}

.tx-alert__icon { flex: none; font-size: 1.125rem; margin-top: 1px; }
.tx-alert__content { flex: 1; display: grid; gap: 2px; min-width: 0; }
.tx-alert__title { font-weight: 600; }
.tx-alert__message { color: var(--tx-fg-muted); }
.tx-alert__close { margin: -0.375rem -0.375rem -0.375rem 0; }

.tx-alert--inverse { background: var(--tx-accent); color: var(--tx-on-accent); border-color: var(--tx-accent); }
.tx-alert--inverse .tx-alert__message { color: inherit; opacity: 0.72; }
.tx-alert--inverse .tx-btn--ghost { color: inherit; }
.tx-alert--inverse .tx-btn--ghost:hover { background: color-mix(in srgb, var(--tx-on-accent) 12%, transparent); }

.tx-alert--success { background: var(--tx-success-soft); border-color: color-mix(in srgb, var(--tx-success) 22%, transparent); }
.tx-alert--success .tx-alert__icon { color: var(--tx-success); }
.tx-alert--warning { background: var(--tx-warning-soft); border-color: color-mix(in srgb, var(--tx-warning) 22%, transparent); }
.tx-alert--warning .tx-alert__icon { color: var(--tx-warning); }
.tx-alert--danger { background: var(--tx-danger-soft); border-color: color-mix(in srgb, var(--tx-danger) 22%, transparent); }
.tx-alert--danger .tx-alert__icon { color: var(--tx-danger); }

/* ---------- 15. Divider ---------- */
.tx-divider { height: 1px; margin: 0; border: 0; background: var(--tx-border); }
.tx-divider--vertical { width: 1px; height: auto; align-self: stretch; }

.tx-divider-label {
    display: flex;
    align-items: center;
    gap: var(--tx-space-4);
    color: var(--tx-fg-subtle);
    font-size: var(--tx-text-xs);
    letter-spacing: var(--tx-tracking-wide);
    text-transform: uppercase;
}

.tx-divider-label::before, .tx-divider-label::after { content: ""; flex: 1; height: 1px; background: var(--tx-border); }

/* ---------- 16. Skeleton ---------- */
.tx-skeleton {
    display: block;
    border-radius: var(--tx-radius-sm);
    background: linear-gradient(90deg, color-mix(in srgb, var(--tx-fg) 6%, transparent) 0%, color-mix(in srgb, var(--tx-fg) 11%, transparent) 50%, color-mix(in srgb, var(--tx-fg) 6%, transparent) 100%);
    background-size: 200% 100%;
    animation: tx-shimmer 1.6s var(--tx-ease-in-out) infinite;
}

.tx-skeleton--text { height: 0.8em; border-radius: var(--tx-radius-xs); }
.tx-skeleton--circle { border-radius: 50%; }

@keyframes tx-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- 17. Tabs ---------- */
.tx-tabs { display: grid; gap: var(--tx-space-5); }

.tx-tabs__list {
    --_count: 1;
    --_index: 0;
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--_count), minmax(0, 1fr));
    width: fit-content;
    max-width: 100%;
    padding: 4px;
    border-radius: var(--tx-radius-full);
    background: var(--tx-surface-sunken);
    isolation: isolate;
}

.tx-tabs__list--block { width: 100%; }

.tx-tabs__thumb {
    position: absolute;
    z-index: -1;
    top: 4px;
    bottom: 4px;
    left: 4px;
    width: calc((100% - 8px) / var(--_count));
    border-radius: var(--tx-radius-full);
    background: var(--tx-surface);
    box-shadow: var(--tx-shadow-sm), 0 0 0 1px var(--tx-border-subtle);
    transform: translateX(calc(100% * var(--_index)));
    transition: transform var(--tx-duration-slow) var(--tx-ease);
}

.tx-tabs__tab {
    height: 2.125rem;
    padding: 0 var(--tx-space-5);
    border: 0;
    border-radius: var(--tx-radius-full);
    background: none;
    color: var(--tx-fg-muted);
    font: inherit;
    font-size: var(--tx-text-sm);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--tx-duration) var(--tx-ease);
}

.tx-tabs__tab:hover { color: var(--tx-fg); }
.tx-tabs__tab[aria-selected="true"] { color: var(--tx-fg); }
.tx-tabs__tab:disabled { color: var(--tx-fg-disabled); cursor: not-allowed; }

/* underline variant */
.tx-tabs--underline .tx-tabs__list {
    display: flex;
    gap: var(--tx-space-6);
    width: 100%;
    padding: 0;
    border-radius: 0;
    background: none;
    border-bottom: 1px solid var(--tx-border);
}

.tx-tabs--underline .tx-tabs__thumb { display: none; }

.tx-tabs--underline .tx-tabs__tab {
    position: relative;
    height: 2.75rem;
    padding: 0;
    border-radius: 0;
}

.tx-tabs--underline .tx-tabs__tab::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1.5px;
    background: var(--tx-fg);
    transform: scaleX(0);
    transition: transform var(--tx-duration) var(--tx-ease);
}

.tx-tabs--underline .tx-tabs__tab[aria-selected="true"]::after { transform: scaleX(1); }

.tx-tabs__panel { animation: tx-fade-up var(--tx-duration-slow) var(--tx-ease); }
.tx-tabs__panel:focus-visible { outline-offset: 4px; border-radius: var(--tx-radius-sm); }

@keyframes tx-fade-up { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 18. Dialog ---------- */
.tx-dialog {
    width: min(100% - 2rem, var(--_w, 28rem));
    max-height: min(100% - 2rem, 48rem);
    margin: auto;
    padding: 0;
    border: 1px solid var(--tx-border-subtle);
    border-radius: var(--tx-radius-xl);
    background: var(--tx-surface-raised);
    color: var(--tx-fg);
    box-shadow: var(--tx-shadow-lg);
    opacity: 0;
    transform: translateY(8px) scale(0.98);
    transition:
        opacity var(--tx-duration) var(--tx-ease),
        transform var(--tx-duration-slow) var(--tx-ease),
        overlay var(--tx-duration) allow-discrete,
        display var(--tx-duration) allow-discrete;
}

.tx-dialog--sm { --_w: 22rem; }
.tx-dialog--lg { --_w: 40rem; }

.tx-dialog[open] { display: flex; flex-direction: column; opacity: 1; transform: none; }

@starting-style {
    .tx-dialog[open] { opacity: 0; transform: translateY(8px) scale(0.98); }
}

.tx-dialog::backdrop {
    background: var(--tx-overlay);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity var(--tx-duration) var(--tx-ease), overlay var(--tx-duration) allow-discrete, display var(--tx-duration) allow-discrete;
}

.tx-dialog[open]::backdrop { opacity: 1; }

@starting-style {
    .tx-dialog[open]::backdrop { opacity: 0; }
}

.tx-dialog__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--tx-space-4); padding: var(--tx-space-6) var(--tx-space-6) 0; }
.tx-dialog__title { margin: 0; font-size: var(--tx-text-lg); font-weight: 600; letter-spacing: var(--tx-tracking-tight); line-height: var(--tx-leading-snug); }
.tx-dialog__desc { margin: var(--tx-space-1) 0 0; font-size: var(--tx-text-sm); color: var(--tx-fg-muted); }
.tx-dialog__close { margin: -0.5rem -0.5rem 0 0; }
.tx-dialog__body { padding: var(--tx-space-5) var(--tx-space-6); overflow: auto; }
.tx-dialog__footer { display: flex; justify-content: flex-end; gap: var(--tx-space-2); padding: 0 var(--tx-space-6) var(--tx-space-6); }

/* On phones the dialog becomes a bottom sheet */
@media (max-width: 520px) {
    .tx-dialog {
        width: 100%;
        max-width: 100%;
        margin: auto 0 0;
        border-radius: var(--tx-radius-xl) var(--tx-radius-xl) 0 0;
        padding-bottom: var(--tx-inset-bottom);
        transform: translateY(100%);
    }

    @starting-style {
        .tx-dialog[open] { transform: translateY(100%); }
    }

    .tx-dialog__footer { flex-direction: column-reverse; }
    .tx-dialog__footer .tx-btn { width: 100%; }
}

/* ---------- 19. Toast ---------- */
.tx-toaster {
    position: fixed;
    z-index: var(--tx-z-toast);
    left: 50%;
    bottom: calc(var(--tx-space-6) + var(--tx-inset-bottom));
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: var(--tx-space-2);
    width: min(100% - 2rem, 24rem);
    transform: translateX(-50%);
    pointer-events: none;
}

.tx-toast {
    display: flex;
    align-items: center;
    gap: var(--tx-space-3);
    width: 100%;
    padding: var(--tx-space-3) var(--tx-space-3) var(--tx-space-3) var(--tx-space-4);
    border-radius: var(--tx-radius-md);
    background: var(--tx-accent);
    color: var(--tx-on-accent);
    box-shadow: var(--tx-shadow-lg);
    font-size: var(--tx-text-sm);
    pointer-events: auto;
    animation: tx-toast-in var(--tx-duration-slow) var(--tx-ease);
}

.tx-toast--leaving { animation: tx-toast-out var(--tx-duration) var(--tx-ease) forwards; }
.tx-toast__icon { flex: none; font-size: 1.1rem; }
.tx-toast__body { flex: 1; display: grid; gap: 1px; min-width: 0; }
.tx-toast__title { font-weight: 600; }
.tx-toast__message { opacity: 0.72; }
.tx-toast--success .tx-toast__icon { color: var(--tx-on-accent-success); }
.tx-toast--warning .tx-toast__icon { color: var(--tx-on-accent-warning); }
.tx-toast--danger .tx-toast__icon { color: var(--tx-on-accent-danger); }

.tx-toast .tx-btn--ghost { color: inherit; }
.tx-toast .tx-btn--ghost:hover { background: color-mix(in srgb, var(--tx-on-accent) 14%, transparent); }

@keyframes tx-toast-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes tx-toast-out { to { opacity: 0; transform: translateY(6px) scale(0.97); } }

/* ---------- 20. Layout helpers ---------- */
.tx-stack { display: flex; flex-direction: column; gap: var(--_gap, var(--tx-space-4)); }
.tx-stack--row { flex-direction: row; align-items: center; }
.tx-stack--wrap { flex-wrap: wrap; }

.tx-container { width: min(100% - 2.5rem, 72rem); margin-inline: auto; }

.tx-surface-sunken { background: var(--tx-surface-sunken); }

.tx-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- 21. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
    }

    .tx-spinner { animation: tx-spin 1.6s linear infinite !important; }
}

/* ---------- The other TenX tools ---------- */
.tx-family { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr)); gap: var(--tx-space-2); }

.tx-family__item {
    all: unset;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 0 var(--tx-space-2);
    padding: var(--tx-space-3);
    border: 1px solid var(--tx-border);
    border-radius: var(--tx-radius-md);
    cursor: pointer;
    min-width: 0;
    transition: border-color var(--tx-duration) var(--tx-ease), background-color var(--tx-duration) var(--tx-ease);
}

.tx-family__item:hover { border-color: var(--tx-border-strong); background: var(--tx-surface-hover); }
.tx-family__item:focus-visible { outline: 2px solid var(--tx-ring); outline-offset: 2px; }
.tx-family__name { font-size: var(--tx-text-sm); font-weight: 600; }
.tx-family__blurb { grid-column: 1 / -1; font-size: var(--tx-text-xs); color: var(--tx-fg-subtle); }
.tx-family__go { color: var(--tx-fg-subtle); font-size: 0.9em; }

/* ---------- Skip link ---------- */
/* Out of the way until it has focus: the first Tab press on any page offers a way past the
   navigation rail, which is otherwise a dozen stops before the content on every screen. */
.tx-skip {
    position: fixed;
    z-index: 200;
    top: calc(var(--tx-space-3) + var(--tx-inset-top));
    left: 50%;
    transform: translate(-50%, calc(-100% - var(--tx-space-6)));
    padding: var(--tx-space-2) var(--tx-space-4);
    border-radius: var(--tx-radius-full);
    background: var(--tx-fg);
    color: var(--tx-bg);
    font-size: var(--tx-text-sm);
    font-weight: 500;
    text-decoration: none;
    transition: transform var(--tx-duration) var(--tx-ease);
}

/* :focus rather than :focus-visible — a skip link has to appear however focus reached it, and it
   can never be focused by a click because it sits off-screen until then. */
.tx-skip:focus {
    transform: translate(-50%, 0);
    outline: 2px solid var(--tx-ring);
    outline-offset: 2px;
}

/* The content is focusable only so the skip link can move focus there; it never shows a ring. */
[id="content"]:focus { outline: none; }

/* ---------- Legal and about pages ---------- */
/* Long-form reading: a measure that stops around 70 characters, and space between ideas rather
   than boxes around them. */
.tx-legal { display: grid; gap: var(--tx-space-4); max-width: 42rem; line-height: var(--tx-leading-normal); }
.tx-legal h2 { margin: var(--tx-space-3) 0 0; font-size: var(--tx-text-lg); font-weight: 600; letter-spacing: var(--tx-tracking-tight); }
.tx-legal h2:first-of-type { margin-top: 0; }
.tx-legal p { margin: 0; color: var(--tx-fg-muted); text-wrap: pretty; }
.tx-legal__lead { font-size: var(--tx-text-lg); color: var(--tx-fg) !important; text-wrap: pretty; }
.tx-legal ul { margin: 0; padding-left: var(--tx-space-5); display: grid; gap: var(--tx-space-2); color: var(--tx-fg-muted); }
.tx-legal code { font-family: var(--tx-font-mono); font-size: 0.9em; padding: 0.1em 0.35em; border-radius: var(--tx-radius-xs); background: var(--tx-surface-sunken); }
.tx-legal a { color: var(--tx-fg); text-decoration: underline; text-underline-offset: 2px; }
.tx-legal .tx-family { margin-top: var(--tx-space-1); }
.tx-legal__actions { display: flex; flex-wrap: wrap; gap: var(--tx-space-2); margin-top: var(--tx-space-1); }

.tx-legal__link {
    all: unset;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: var(--tx-space-2);
    padding: var(--tx-space-2) var(--tx-space-4);
    border: 1px solid var(--tx-border);
    border-radius: var(--tx-radius-full);
    background: var(--tx-surface);
    font-size: var(--tx-text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--tx-duration) var(--tx-ease), border-color var(--tx-duration) var(--tx-ease);
}

.tx-legal__link:hover { background: var(--tx-surface-hover); border-color: var(--tx-border-strong); }
.tx-legal__link:focus-visible { outline: 2px solid var(--tx-ring); outline-offset: 2px; }

.tx-legal__updated { margin-top: var(--tx-space-4); font-size: var(--tx-text-sm); color: var(--tx-fg-subtle) !important; }

/* The three legal pages, linked from each app's About panel. */
.tx-legal-links { margin: var(--tx-space-3) 0 0; font-size: var(--tx-text-sm); color: var(--tx-fg-subtle); }
.tx-legal-links a { color: var(--tx-fg-muted); text-decoration: none; }
.tx-legal-links a:hover { color: var(--tx-fg); text-decoration: underline; }
