/* EmuTron "Style A — Command Deck": app shell + global primitives.
 *
 * Owns: the left sidebar (logo, page tabs, version + log out), the per-page top bar (title, engine
 * status pill, close-engine button), the global background, page placement, and the Style A look of
 * the shared primitives (buttons, segmented controls, toggles/checkboxes, sliders, selects/inputs,
 * cards). Every rule is scoped under #app and built on the --rd-* tokens (tokens.css), so the five
 * themes keep working through --scheme. Primitive rules keep a low specificity (#app + one class, or
 * #app :where(...)) so the per-page redesign files, loaded after this one, can refine them.
 *
 * Markup contract kept intact: .tab-btn[data-page] + data-i18n, #header-tabs, #tab-underline (now the
 * sliding active-tab highlight, positioned by app.js updateUnderline()), #engine-conn-indicator /
 * -dot / -text (app.js writes their state colors inline — the few !important rules below only
 * re-skin those inline values), #btn-close, #brand-typer. */

#app {
    --rd-topbar-h: 102px;
    --rd-page-pad-x: 32px;
    --rd-sidebar-w: 232px;
    background: var(--rd-bg);
    accent-color: var(--rd-accent);
}

/* Neutral near-black base for every theme: the legacy per-theme --bg* tokens carry navy / plum
 * tints (Ice, Aurora, Galaxy, Rose); Style A keeps the surfaces neutral and lets only the accent
 * (--scheme) change. Specificity (#app.theme-x) beats emulator.css's .theme-x blocks. */
#app,
#app.theme-dark,
#app.theme-galaxy,
#app.theme-ice,
#app.theme-rose,
#app.theme-aurora {
    --bg: rgb(8, 8, 8);
    --bg2: rgb(11, 11, 11);
    --bg3: rgb(23, 23, 23);
    --bg4: rgb(32, 32, 32);
    --bg5: rgba(28, 28, 28, 0.7);
    --grad-bot: transparent;
}

/* ------------------------------------------------------------------ */
/*  Global background: dark base, soft accent glows, faint grid        */
/* ------------------------------------------------------------------ */
html,
body { background: #000; }

#app { background: #020203; }

/* Pure black stage; the animated canvas (#starfield: sparkles + accent waves, drawn in app.js)
 * carries the ambience. Only a faint accent bloom at the top remains here. */
#app::before {
    background: radial-gradient(1000px 520px at 60% -8%, color-mix(in srgb, var(--scheme) 7%, transparent), transparent 70%);
    opacity: 1;
}

#app::after {
    animation: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

/* Legacy ambience stays in the DOM (scripts drive it) but Style A's backdrop is the clean glow +
 * grid above: the theme-tinted orbs and bottom wash are hidden, the starfield is a faint texture. */
#app #starfield { opacity: 1; }
#app #bottom-gradient { display: none; }
#app .ambient-orb { display: none; }
#app #cursor-glow { opacity: 0.04; }
#app:hover #cursor-glow { opacity: 0.05; }

/* ------------------------------------------------------------------ */
/*  Sidebar (.header)                                                   */
/* ------------------------------------------------------------------ */
#app .header {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    inset-inline-end: auto;
    width: var(--rd-sidebar-w);
    height: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 28px;
    padding: 24px 16px 20px;
    z-index: 10;
    background: var(--rd-sidebar);
    border-bottom: 0;
    border-inline-end: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(14px) saturate(1.1);
    -webkit-backdrop-filter: blur(14px) saturate(1.1);
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: none;
    font-family: var(--rd-font);
}

#app .header::-webkit-scrollbar { display: none; }

#app .header::after { content: none; display: none; }

#app .header-left {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 0 8px;
}

#app .rd-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

#app .rd-brand-logo {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    object-fit: contain;
    filter: drop-shadow(0 0 10px var(--rd-accent-glow));
}

#app .rd-brand-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

#app .rd-brand-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--rd-text);
    line-height: 1.2;
}

#app .rd-brand-sub {
    font-size: 11px;
    line-height: 1.35;
    /* Small text on the sidebar glass: --rd-text-3 (0.45) lands just under 4.5:1. */
    color: rgba(255, 255, 255, 0.55);
}

/* The legacy typewriter keeps running (app.js owns its timers) but is not part of Style A. */
#app .brand-typer { display: none; }

/* -- Page tabs -- */
#app .header-tabs {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 0;
    height: auto;
    position: relative;
    -webkit-mask-image: none;
    mask-image: none;
}

#app .tab-btn {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: var(--rd-touch);
    padding: 12px 14px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--rd-text-2);
    font-family: var(--rd-font);
    font-size: 14px;
    font-weight: 500;
    text-align: start;
    text-shadow: none;
    white-space: nowrap;
    cursor: pointer;
    transform: none;
    transition: color 0.2s ease, background-color 0.2s ease;
}

#app .tab-btn .rd-nav-icon,
#app .tab-btn svg {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    color: currentColor;
    transition: color 0.2s ease;
}

#app .tab-btn:hover {
    color: var(--rd-text);
    background: rgba(255, 255, 255, 0.04);
    transform: none;
}

#app .tab-btn.active {
    color: var(--rd-text);
    font-weight: 600;
    background: transparent;
    text-shadow: none;
}

#app .tab-btn.active svg { color: var(--rd-accent); }

/* Macro count badge: app.js writes the real macro count into data-rd-count (an attribute, so the
 * i18n text swap that rebuilds the button's children cannot remove it). */
#app .tab-btn[data-rd-count]::after {
    content: attr(data-rd-count);
    margin-inline-start: auto;
    padding: 2px 8px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    font-family: var(--rd-mono);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.45;
}

#app .tab-btn:focus-visible {
    outline: 2px solid var(--rd-accent);
    outline-offset: 2px;
}

/* Sliding active highlight (app.js sets left/top/width/height to the active tab's box). */
#app .tab-underline {
    position: absolute;
    z-index: 0;
    bottom: auto;
    border-radius: 12px;
    background: var(--rd-accent-soft);
    box-shadow: inset 0 0 0 1px var(--rd-accent-line);
    pointer-events: none;
    transition:
        left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        top 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* -- License card (real /api/license/status fields only; hidden until read) -- */
#app .rd-license-card {
    margin-top: auto;
    margin-bottom: -16px; /* the sidebar's 28px gap -> the mockup's 12px card-to-footer gap */
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--rd-border);
}

#app .rd-license-card[hidden] { display: none; }

#app .rd-license-state {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--rd-text);
}

#app .rd-license-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--rd-accent);
    box-shadow: 0 0 10px var(--rd-accent);
}

#app .rd-license-left {
    margin-inline-start: auto;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--rd-accent-soft);
    border: 1px solid var(--rd-accent-line);
    /* Neutral text: some theme accents (Galaxy violet) fall under 4.5:1 as small text. */
    color: rgba(255, 255, 255, 0.85);
    font-family: var(--rd-mono);
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

#app .rd-license-left[hidden] { display: none; }

#app .rd-license-card.is-invalid .rd-license-dot {
    background: var(--rd-danger);
    box-shadow: 0 0 10px var(--rd-danger);
}

#app .rd-license-meta {
    font-size: 12px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.6);
}

#app .rd-license-meta[hidden] { display: none; }

/* -- Sidebar foot: version + log out -- */
#app .rd-license-card:not([hidden]) + .rd-sidebar-foot { margin-top: 0; }

#app .rd-sidebar-foot {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
}

#app .rd-version {
    font-family: var(--rd-font);
    font-size: 12px;
    color: rgba(255, 255, 255, 0.55);
}

#app .rd-logout {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 8px 10px;
    margin-inline-end: -10px;
    border: 0;
    border-radius: var(--rd-radius-sm);
    background: none;
    color: rgba(255, 255, 255, 0.6);
    font-family: var(--rd-font);
    font-size: 12px;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
}

/* Wide sidebar: text-only "Log out" like the mockup; the icon returns on the rail / top strip. */
#app .rd-logout svg { display: none; }

#app .rd-logout:hover {
    color: #FF8A8E;
    background: rgba(229, 72, 77, 0.1);
}

#app .rd-logout:focus-visible {
    outline: 2px solid var(--rd-accent);
    outline-offset: 2px;
}

/* The sidebar log-out confirm modal is appended to <body>; lift it above the app layers. */
body > #etd-logout-modal { z-index: 2147482000; }

/* ------------------------------------------------------------------ */
/*  Top bar (.header-right): page title + status pill + close          */
/* ------------------------------------------------------------------ */
#app .header-right {
    position: absolute;
    top: 0;
    inset-inline-start: var(--rd-sidebar-w);
    inset-inline-end: 0;
    height: var(--rd-topbar-h);
    z-index: 9;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px var(--rd-page-pad-x) 24px;
    font-family: var(--rd-font);
}

#app .rd-titles {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    margin-inline-end: auto;
}

#app .rd-page-sub {
    font-size: 13px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Only the active page's subtitle shows (pages with their own in-page subtitle have none here). */
#app .rd-page-sub { display: none; }
#app:has(#page-home.active) .rd-page-sub[data-rd-sub="home"]:not([hidden]),
#app:has(#page-scripts.active) .rd-page-sub[data-rd-sub="scripts"] { display: block; }

#app .rd-page-sub-name {
    color: var(--rd-text);
    font-family: var(--rd-mono);
}

#app .rd-page-title {
    margin: 0;
    min-width: 0;
    font-size: var(--rd-page-title);
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
    color: var(--rd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Only the title of the active page shows (no JS: follows .content-page.active). */
#app .rd-title { display: none; }
#app:has(#page-home.active) .rd-title[data-rd-title="home"],
#app:has(#page-scripts.active) .rd-title[data-rd-title="scripts"],
#app:has(#page-macros.active) .rd-title[data-rd-title="macros"],
#app:has(#page-curve.active) .rd-title[data-rd-title="curve"],
#app:has(#page-config.active) .rd-title[data-rd-title="config"] { display: inline; }

/* Engine status pill. Default (pre-JS) = offline; app.js then writes background / border-color /
 * color inline per state. The text stays white and the state color tints the dot, ring and border. */
#app #engine-conn-indicator {
    flex: 0 1 auto;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 16px;
    border-radius: 22px;
    border: 1px solid;
    color: var(--rd-offline);
    background: rgba(255, 255, 255, 0.04) !important;
    /* Mockup pill: neutral glass + hairline; the state color lives only in the dot. */
    border-color: rgba(255, 255, 255, 0.09) !important;
    box-shadow: none;
    font-family: var(--rd-font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

#app #engine-conn-indicator:hover {
    background: rgba(255, 255, 255, 0.07) !important;
}

#app #engine-conn-indicator:focus-visible {
    outline: 2px solid var(--rd-accent);
    outline-offset: 2px;
}

#app #engine-conn-dot {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 18%, transparent) !important;
}

#app #engine-conn-text {
    display: inline;
    min-width: 0;
    color: var(--rd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#app .rd-conn-hz {
    flex: 0 0 auto;
    font-family: var(--rd-mono);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

#app .rd-conn-hz[hidden] { display: none; }

/* Engage key chip: a read-only label of the configured RemappKey (not a button). */
#app .rd-engage-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 8px 0 16px;
    border-radius: 22px;
    background: var(--rd-accent-soft);
    border: 1px solid var(--rd-accent-line);
    color: var(--rd-accent);
    font-family: var(--rd-font);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: default;
}

/* Shown where the mockups carry the Engage control (Home, Smoothing, Mouse Curve); Macros and
 * Config use that slot for their own actions. */
#app .rd-engage-chip[hidden],
#app:has(#page-macros.active) .rd-engage-chip,
#app:has(#page-config.active) .rd-engage-chip { display: none; }

#app .rd-engage-label { color: var(--rd-text); }

#app .rd-engage-key {
    min-width: 30px;
    padding: 5px 10px;
    border-radius: 16px;
    background: var(--rd-accent);
    color: var(--rd-on-accent);
    font-family: var(--rd-mono);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 4px 16px var(--rd-accent-glow);
}

/* Close-engine (x). */
#app .hdr-close {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0 0 2px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: rgba(255, 255, 255, 0.04);
    color: var(--rd-text-2);
    font-family: var(--rd-font);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

#app .hdr-close:hover {
    background: rgba(229, 72, 77, 0.14);
    border-color: rgba(229, 72, 77, 0.5);
    color: #FF8A8E;
}

#app .hdr-close:focus-visible {
    outline: 2px solid var(--rd-danger);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------ */
/*  Page placement: right of the sidebar, below the top bar            */
/* ------------------------------------------------------------------ */
#app .content-page {
    top: var(--rd-topbar-h);
    bottom: 0;
    inset-inline-start: var(--rd-sidebar-w);
    inset-inline-end: 0;
    padding: 0 var(--rd-page-pad-x) var(--rd-page-pad-x);
    font-family: var(--rd-font);
    scrollbar-width: thin;
    scrollbar-color: var(--rd-accent-line) transparent;
}

/* ------------------------------------------------------------------ */
/*  Global primitives                                                   */
/* ------------------------------------------------------------------ */

/* Focus ring for anything keyboard-focusable that has no ring of its own. */
#app :where(button, [role="button"], a[href], select, input, textarea, summary):focus-visible {
    outline: 2px solid var(--rd-accent);
    outline-offset: 2px;
}

/* -- Primary buttons: accent fill, dark text -- */
#app .btn-primary,
#app .btn-accent,
#app .card-btn.accent {
    background: var(--rd-accent);
    color: var(--rd-on-accent);
    border: 0;
    border-radius: 12px;
    font-family: var(--rd-font);
    font-weight: 700;
    letter-spacing: 0.01em;
    box-shadow: 0 8px 28px var(--rd-accent-glow);
    text-shadow: none;
    transition: filter 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

#app .btn-primary { min-height: var(--rd-touch); }

#app .btn-accent,
#app .card-btn.accent { min-height: 40px; }

#app .btn-primary::before { content: none; }

#app .card-btn.accent::before { opacity: 0; }

#app .btn-primary:hover,
#app .btn-accent:hover,
#app .card-btn.accent:hover {
    background: var(--rd-accent);
    color: var(--rd-on-accent);
    border-color: transparent;
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 10px 32px var(--rd-accent-glow);
}

#app .btn-primary:active,
#app .btn-accent:active,
#app .card-btn.accent:active {
    filter: brightness(0.96);
    transform: translateY(0) scale(0.98);
    box-shadow: 0 4px 14px var(--rd-accent-glow);
}

#app .btn-primary:disabled,
#app .btn-accent:disabled,
#app .card-btn.accent:disabled {
    filter: grayscale(0.4) brightness(0.8);
    box-shadow: none;
    transform: none;
    cursor: not-allowed;
}

/* -- Secondary buttons: transparent with a hairline border -- */
#app .btn-outline,
#app .card-btn:not(.accent) {
    min-height: 40px;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: var(--rd-radius-sm);
    font-family: var(--rd-font);
    font-weight: 600;
    letter-spacing: 0.01em;
    box-shadow: none;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

#app .card-btn:not(.accent)::before { opacity: 0; }

#app .btn-outline:hover,
#app .card-btn:not(.accent):hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--rd-accent-line);
    color: var(--rd-text);
    box-shadow: none;
    transform: none;
}

#app .btn-outline:active,
#app .card-btn:not(.accent):active {
    background: rgba(255, 255, 255, 0.08);
    transform: scale(0.98);
    box-shadow: none;
}

/* -- Segmented controls (app.js initSegControl() still slides .seg-highlight) -- */
#app .seg-control {
    padding: 4px;
    border-radius: 12px;
    background: var(--rd-surface-sunken);
    border: 1px solid var(--rd-border);
    box-shadow: none;
}

#app .seg-btn {
    min-height: var(--rd-control-h);
    padding: 0 14px;
    border-radius: 9px;
    color: rgba(255, 255, 255, 0.6);
    font-family: var(--rd-font);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0;
    text-shadow: none;
}

#app .seg-btn:hover:not(.active) { color: var(--rd-text); }

/* The active segment carries the accent fill itself, so it stays readable even before app.js has
 * measured the highlight (it only measures on init and on click; a hidden page measures 0). The
 * highlight keeps sliding underneath as the glow. */
#app .seg-btn.active {
    color: var(--rd-text);
    background: rgba(255, 255, 255, 0.1);
    text-shadow: none;
}

/* Mockup segmented control: the active segment is a raised neutral chip (white 10 %) with white
 * text, not an accent fill; the sliding highlight is kept transparent so the two never double up. */
#app .seg-highlight {
    top: 4px;
    height: calc(100% - 8px);
    border-radius: 9px;
    background: transparent;
    box-shadow: none;
}

/* -- Toggle switches -- */
#app .t-slider {
    background: rgba(255, 255, 255, 0.12);
    outline: 1px solid var(--rd-border-strong);
    outline-offset: 0;
}

#app .t-slider:hover {
    background: rgba(255, 255, 255, 0.18);
    outline-color: rgba(255, 255, 255, 0.18);
}

#app .t-slider::after {
    background: #FFFFFF;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

#app .toggle-switch input:checked + .t-slider {
    background: var(--rd-accent);
    outline: 1px solid var(--rd-accent-line);
    box-shadow: 0 0 14px var(--rd-accent-glow);
}

#app .toggle-switch input:checked + .t-slider::after {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

#app .toggle-switch input:focus-visible + .t-slider {
    outline: 2px solid var(--rd-accent);
    outline-offset: 2px;
}

/* -- Custom checkboxes -- */
#app .checkmark {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    border: 1.5px solid rgba(255, 255, 255, 0.28);
    background: var(--rd-surface-sunken);
}

#app .checkbox-row:hover .checkmark { border-color: var(--rd-accent-line); }

#app .checkbox-row input:checked + .checkmark {
    background: var(--rd-accent);
    border-color: var(--rd-accent);
    box-shadow: 0 0 12px var(--rd-accent-glow);
}

#app .checkbox-row input:checked + .checkmark::after { color: var(--rd-on-accent); }

#app .checkbox-row input:focus-visible + .checkmark {
    outline: 2px solid var(--rd-accent);
    outline-offset: 2px;
}

/* -- Range sliders: app.js paints the accent fill inline; Style A owns the thumb -- */
#app input[type="range"] { accent-color: var(--rd-accent); }

/* Legacy .styled-slider hairline was blue-tinted (rgba(60,100,160,...)); keep it neutral. */
#app .styled-slider { border-color: rgba(255, 255, 255, 0.06); }

#app input[type="range"]::-webkit-slider-thumb {
    background: #FFFFFF;
    border-color: var(--rd-accent);
    box-shadow: 0 0 0 4px var(--rd-accent-soft), 0 2px 6px rgba(0, 0, 0, 0.45);
}

#app input[type="range"]:active::-webkit-slider-thumb {
    box-shadow: 0 0 0 6px var(--rd-accent-line), 0 0 14px var(--rd-accent-glow), 0 2px 8px rgba(0, 0, 0, 0.5);
}

#app input[type="range"]::-moz-range-thumb {
    background: #FFFFFF;
    border-color: var(--rd-accent);
    box-shadow: 0 0 0 4px var(--rd-accent-soft), 0 2px 6px rgba(0, 0, 0, 0.45);
}

#app input[type="range"]:focus-visible { outline: 2px solid var(--rd-accent); outline-offset: 4px; }

/* -- Selects and text fields: sunken, 10px radius -- */
#app .styled-select,
#app :where(.content-page, .header-right) :where(select) {
    border-radius: var(--rd-radius-sm);
    background-color: var(--rd-surface-sunken);
    border: 1px solid var(--rd-border);
    color: var(--rd-text);
    font-family: var(--rd-font);
    box-shadow: none;
}

#app .styled-select:hover,
#app :where(.content-page) :where(select):hover {
    background-color: rgba(0, 0, 0, 0.45);
    border-color: var(--rd-border-strong);
    transform: none;
    box-shadow: none;
}

#app .styled-select:focus,
#app :where(.content-page) :where(select):focus {
    border-color: var(--rd-accent);
    box-shadow: 0 0 0 3px var(--rd-accent-soft);
}

#app :where(select) option {
    background: #141414;
    color: var(--rd-text);
}

#app :where(.content-page) :where(input[type="text"]:not(.macros-search), input[type="number"], input[type="search"]:not(.macros-search), textarea) {
    border-radius: var(--rd-radius-sm);
    background-color: var(--rd-surface-sunken);
    border: 1px solid var(--rd-border);
    color: var(--rd-text);
    font-family: var(--rd-font);
}

#app :where(.content-page) :where(input[type="text"]:not(.macros-search), input[type="number"], input[type="search"]:not(.macros-search), textarea):focus {
    border-color: var(--rd-accent);
    box-shadow: 0 0 0 3px var(--rd-accent-soft);
    outline: none;
}

#app :where(.content-page) :where(input, textarea)::placeholder { color: var(--rd-text-3); }

/* -- Cards -- */
#app .card {
    border-radius: var(--rd-radius-lg);
    background: var(--rd-surface);
    border: 1px solid var(--rd-border);
    box-shadow: none;
}

#app .card::before { opacity: 0.25; }

#app .card:hover {
    transform: none;
    border-color: var(--rd-border-strong);
    box-shadow: none;
}

#app .card:hover::after { opacity: 0.25; }

#app .card-title {
    font-family: var(--rd-font);
    font-size: var(--rd-label);
    font-weight: 600;
    letter-spacing: 0.12em;
    color: var(--rd-text-3);
}

/* ------------------------------------------------------------------ */
/*  Responsive                                                          */
/* ------------------------------------------------------------------ */

/* Medium widths: the sidebar collapses to an icon rail (labels stay in the DOM for screen readers
 * and i18n; only their glyphs are shrunk away). */
@media (max-width: 1100px) and (min-width: 901px) {
    #app { --rd-sidebar-w: 84px; --rd-page-pad-x: 24px; }

    #app .header { padding: 22px 12px 16px; gap: 24px; }

    #app .header-left { align-items: center; padding: 0; }

    #app .rd-brand-text { display: none; }

    #app .tab-btn {
        justify-content: center;
        gap: 0;
        padding: 12px 0;
        font-size: 0;
    }

    #app .tab-btn svg { width: 20px; height: 20px; }

    /* Macro count rides on the icon's corner in the rail. */
    #app .tab-btn[data-rd-count]::after {
        position: absolute;
        top: 5px;
        inset-inline-end: 8px;
        margin: 0;
        min-width: 17px;
        padding: 0 5px;
        background: rgba(44, 44, 44, 0.95);
        box-shadow: 0 0 0 2px var(--rd-bg);
        color: var(--rd-text);
        font-size: 10px;
        line-height: 1.7;
        text-align: center;
    }

    #app .rd-sidebar-foot {
        flex-direction: column;
        justify-content: flex-end;
        padding: 0;
    }

    #app .rd-version { font-size: 10px; }

    #app .rd-license-card { display: none; }

    #app .rd-logout svg { display: block; }

    #app .rd-logout {
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        margin: 0;
    }

    #app .rd-logout-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
}

/* Narrow widths: the sidebar becomes a top strip (logo, scrollable tabs, log out) with the top bar
 * underneath; pages start below both. */
@media (max-width: 900px) {
    #app {
        --rd-strip-h: 64px;
        --rd-topbar-h: 64px;
        --rd-page-pad-x: 16px;
        --rd-sidebar-w: 0px;
    }

    #app .header {
        inset-block: 0 auto;
        inset-inline: 0;
        width: auto;
        height: var(--rd-strip-h);
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 0 12px;
        border-inline-end: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        overflow: visible;
    }

    #app .header-left {
        display: flex;
        flex: 0 0 auto;
        padding: 0;
    }

    #app .rd-brand-text { display: none; }

    #app .rd-brand-logo { width: 34px; height: 34px; }

    #app .header-tabs {
        flex: 1 1 auto;
        min-width: 0;
        flex-direction: row;
        align-items: center;
        gap: 2px;
        height: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent);
        mask-image: linear-gradient(90deg, #000 88%, transparent);
    }

    #app[dir="rtl"] .header-tabs {
        -webkit-mask-image: linear-gradient(270deg, #000 88%, transparent);
        mask-image: linear-gradient(270deg, #000 88%, transparent);
    }

    #app .tab-btn {
        width: auto;
        flex: 0 0 auto;
        gap: 8px;
        min-height: 40px;
        padding: 0 12px;
        font-size: 13px;
    }

    #app .tab-btn svg { width: 16px; height: 16px; }

    #app .rd-sidebar-foot {
        flex: 0 0 auto;
        margin: 0;
        padding: 0;
    }

    #app .rd-version { display: none; }

    #app .rd-license-card { display: none; }

    #app .rd-logout svg { display: block; }

    #app .rd-logout {
        justify-content: center;
        width: 40px;
        height: 40px;
        padding: 0;
        margin: 0;
    }

    #app .rd-logout-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    #app .header-right {
        top: var(--rd-strip-h);
        inset-inline: 0;
        gap: 8px;
        padding: 10px var(--rd-page-pad-x);
    }

    #app .rd-page-title { font-size: 20px; }

    #app #engine-conn-indicator { height: 40px; padding: 0 14px !important; }

    #app #engine-conn-text { display: inline; }

    #app .hdr-close { width: 40px; height: 40px; }

    #app .rd-titles { gap: 2px; }

    #app .rd-page-sub { font-size: 12px; }

    #app .rd-conn-hz { display: none; }

    #app .rd-engage-chip { height: 40px; gap: 8px; padding: 0 6px 0 12px; }

    #app .content-page {
        top: calc(var(--rd-strip-h) + var(--rd-topbar-h));
        inset-inline: 0;
        padding: 0 var(--rd-page-pad-x) var(--rd-page-pad-x);
    }
}

@media (max-width: 560px) {
    /* Keep the pill to its dot so title, pill and close always fit; the full text stays in the
     * accessible name and the hover title. */
    #app #engine-conn-indicator { width: 40px; padding: 0 !important; justify-content: center; }

    #app #engine-conn-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    #app .tab-btn { padding: 0 10px; }

    /* Engage chip shrinks to its key (the full label stays for screen readers). */
    #app .rd-engage-chip { padding: 0 5px; gap: 0; }

    #app .rd-engage-chip svg { display: none; }

    #app .rd-engage-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
}

@media (prefers-reduced-motion: reduce) {
    #app .tab-underline,
    #app .tab-btn,
    #app #engine-conn-indicator { transition: none; }
}
