/* Final theme surface guard: loaded last so popups, comments, menus, and late page CSS follow site themes. */
:root {
  --surface-theme-bg: var(--bg, #f0f2f5);
  --surface-theme-card: color-mix(in srgb, var(--card, #fff) 94%, var(--bg, #f0f2f5));
  --surface-theme-card-solid: var(--card, #fff);
  --surface-theme-soft: color-mix(in srgb, var(--bg, #f0f2f5) 76%, var(--card, #fff));
  --surface-theme-soft-accent: color-mix(in srgb, var(--accent, #1877f2) 13%, var(--card, #fff));
  --surface-theme-text: var(--text, #1c1e21);
  --surface-theme-muted: var(--muted, #65676b);
  --surface-theme-line: color-mix(in srgb, var(--line, #d9dde3) 84%, transparent);
  --surface-theme-accent: var(--accent, #1877f2);
  --surface-theme-on-accent: #fff;
  --surface-theme-danger: #be123c;
  --surface-theme-success: #047857;
  --surface-theme-shadow: 0 16px 42px color-mix(in srgb, var(--text, #1c1e21) 9%, transparent);
  --surface-theme-overlay: color-mix(in srgb, #000 68%, transparent);
}

html[data-theme="high_contrast"] {
  --surface-theme-card: var(--card, #111);
  --surface-theme-card-solid: var(--card, #111);
  --surface-theme-soft: var(--bg, #000);
  --surface-theme-soft-accent: color-mix(in srgb, var(--accent, #ffea00) 22%, var(--bg, #000));
  --surface-theme-line: var(--line, #fff);
  --surface-theme-on-accent: #000;
  --surface-theme-danger: #ff6b6b;
  --surface-theme-success: #7dff9f;
  --surface-theme-overlay: rgba(0, 0, 0, .86);
}

body:not(.guest-landing-page) :where(
  .card:not(.has-card-wallpaper),
  .panel,
  .box,
  .modal-card,
  .dialog,
  [role="dialog"],
  [class*="-dialog"],
  [class*="-modal-card"],
  [class*="-toast-card"],
  [class*="-popover"],
  [class*="-dropdown"],
  [class*="-flyout"],
  .top-search-suggest,
  .profile-social-dialog,
  .profile-social-user,
  .profile-stat-pop-btn,
  .wallpaper-modal-dialog,
  .wallpaper-ui-example-card,
  .hmoob-media-picker-dialog,
  .hmp-image-tile,
  .hmp-sticker-tile,
  .report-modal-card,
  .report-toast-card,
  .report-admin-card,
  .report-target-preview,
  .safety-ack-panel,
  .composer-card,
  .composer-launcher-card,
  .composer-modal,
  .comments-wrap,
  .comment-item,
  .comment-bubble,
  .post-menu,
  .content-action-menu,
  .platform-reaction-flyout,
  .content-reaction-flyout,
  .entity-settings-lightbox-dialog,
  .profile-media-lightbox-dialog,
  .quick-story-viewer-panel,
  .qna-edit-dialog
) {
  background: var(--surface-theme-card) !important;
  background-color: var(--surface-theme-card) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--surface-theme-shadow);
}

body:not(.guest-landing-page) :where(
  .modal-backdrop,
  .ucl-backdrop,
  .report-modal-backdrop,
  .safety-ack-modal,
  .hmoob-media-picker-backdrop,
  .wallpaper-modal-backdrop,
  .blog-editor-lightbox-backdrop,
  .chat-modal-backdrop,
  .auto-modal-backdrop,
  .point-marquee-backdrop,
  .point-shop-insufficient-backdrop,
  [class*="-backdrop"]
) {
  background: var(--surface-theme-overlay) !important;
}

body:not(.guest-landing-page) :where(
  input,
  textarea,
  select,
  .search-input,
  .comment-input,
  .composer-input,
  .wallpaper-preview,
  .hmp-empty,
  .hmp-error,
  .hmp-sticker-loading,
  .top-search-suggest-item,
  .profile-social-user,
  .report-reason-btn,
  .report-target-preview,
  .report-preview-meta span,
  .safety-ack-meta div,
  .safety-ack-message,
  .ucl-reaction-chip,
  .ucl-comment-bubble,
  .ucl-like-btn,
  .ucl-empty,
  .ucl-error,
  .ucl-sort-row button,
  .ucl-composer,
  .ucl-reply-form textarea,
  .ucl-composer textarea,
  .wallpaper-display-options label,
  .wallpaper-file-label span,
  .platform-reaction-option,
  .platform-reaction-summary,
  .content-action-btn,
  .post-menu button,
  .post-menu a
) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

body:not(.guest-landing-page) :where(input, textarea, select):focus {
  border-color: var(--surface-theme-accent) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--surface-theme-accent) 18%, transparent) !important;
  outline: 0;
}

body:not(.guest-landing-page) :where(
  h1,
  h2,
  h3,
  h4,
  strong,
  label,
  .title,
  .name,
  .ucl-side-head h2,
  .ucl-author-name,
  .ucl-content h1,
  .ucl-comment-head a,
  .report-modal-card h3,
  .report-toast-card strong,
  .report-target-preview > strong,
  .safety-ack-panel h2,
  .safety-ack-meta dd,
  .top-search-suggest-item strong,
  .profile-social-user strong,
  .profile-stat-pop-btn strong,
  .wallpaper-modal-head h2
) {
  color: var(--surface-theme-text) !important;
}

body:not(.guest-landing-page) :where(
  p,
  small,
  .muted,
  .subtitle,
  .description,
  .help,
  .report-help,
  .report-toast-card span,
  .report-admin-meta,
  .report-preview-missing,
  .safety-ack-lead,
  .safety-ack-meta dt,
  .top-search-suggest-empty,
  .top-search-suggest-item small,
  .profile-social-user small,
  .profile-social-status,
  .profile-stat-pop-btn span,
  .wallpaper-modal-head p,
  .wallpaper-overlay-note,
  .hmp-head span,
  .hmp-upload-btn small,
  .hmp-image-tile span,
  .hmp-sticker-tile span,
  .ucl-side-head p,
  .ucl-author-copy span,
  .ucl-body-text,
  .ucl-shared-card p,
  .ucl-reaction-empty,
  .ucl-comment-date,
  .ucl-loader,
  .ucl-reply-btn,
  .comment-empty
) {
  color: var(--surface-theme-muted) !important;
}

body:not(.guest-landing-page) :where(
  button[type="submit"],
  .primary-action,
  .pretty-action,
  .load-more,
  .load-more-btn,
  .view-more,
  .send-btn,
  .save-btn,
  .composer-submit,
  .report-btn,
  .safety-ack-ok,
  .hmp-load,
  .hmp-tabs button.is-active,
  .hmp-sticker-set-tabs button.is-active,
  .hmp-upload-btn > span,
  .ucl-composer button,
  .ucl-reply-form button[type="submit"],
  .ucl-sort-row button.is-active,
  .ucl-like-btn.is-active,
  .wallpaper-save-btn,
  .profile-social-more,
  .platform-reaction-main.is-active
) {
  background: var(--surface-theme-accent) !important;
  background-color: var(--surface-theme-accent) !important;
  border-color: var(--surface-theme-accent) !important;
  color: var(--surface-theme-on-accent) !important;
}

html[data-theme="high_contrast"] body:not(.guest-landing-page) :where(
  button[type="submit"],
  .primary-action,
  .pretty-action,
  .load-more,
  .load-more-btn,
  .view-more,
  .send-btn,
  .save-btn,
  .composer-submit,
  .report-btn,
  .safety-ack-ok,
  .hmp-load,
  .hmp-tabs button.is-active,
  .hmp-sticker-set-tabs button.is-active,
  .hmp-upload-btn > span,
  .ucl-composer button,
  .ucl-reply-form button[type="submit"],
  .ucl-sort-row button.is-active,
  .ucl-like-btn.is-active,
  .wallpaper-save-btn,
  .profile-social-more,
  .platform-reaction-main.is-active
) {
  color: #000 !important;
}

body:not(.guest-landing-page) :where(
  .secondary-action,
  .cancel-btn,
  .report-cancel,
  .safety-ack-disagree,
  .wallpaper-remove-btn,
  .wallpaper-modal-close,
  .report-modal-x,
  .report-toast-close,
  .hmp-close,
  .ucl-close,
  .ucl-comment-delete
) {
  background: var(--surface-theme-soft) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

body:not(.guest-landing-page) :where(
  .error-box,
  .ucl-error,
  .hmp-error,
  .report-link-btn,
  .report-action-btn,
  .safety-ack-error
) {
  color: var(--surface-theme-danger) !important;
}

body:not(.guest-landing-page) :where(
  .ok-box,
  .success-box,
  .report-ack-pill.is-agreed
) {
  color: var(--surface-theme-success) !important;
}

.ucl {
  color: var(--surface-theme-text) !important;
}

.ucl-shell {
  background: var(--surface-theme-card) !important;
  border-color: var(--surface-theme-line) !important;
}

.ucl-main {
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--surface-theme-text) 16%, transparent), transparent 58%),
    color-mix(in srgb, var(--surface-theme-bg) 86%, #000) !important;
}

.ucl.ucl-image-mode .ucl-media-stage {
  background: #000 !important;
}

.ucl-content-panel,
.ucl-side,
.ucl-side-head,
.ucl-target-react,
.ucl-thread,
.ucl-composer {
  background: var(--surface-theme-card) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

.ucl-comment-text {
  color: var(--surface-theme-text) !important;
}

.ucl-media-empty,
.ucl-shared-card,
.ucl-shared-icon {
  background: var(--surface-theme-soft) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

.ucl-reaction-flyout,
.content-reaction-flyout,
.platform-reaction-flyout {
  background: var(--surface-theme-card-solid) !important;
  border-color: var(--surface-theme-line) !important;
}

.top-search-suggest.top-search-flyout,
body .top-search-suggest,
.profile-social-modal.profile-social-flyout-shell .profile-social-dialog {
  background: var(--surface-theme-card) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

.top-search-suggest .top-search-suggest-text strong,
.top-search-suggest .top-search-suggest-item strong,
.profile-social-modal.profile-social-flyout-shell .profile-social-user strong {
  color: var(--surface-theme-text) !important;
}

.top-search-suggest .top-search-suggest-text small,
.top-search-suggest .top-search-suggest-item small,
.profile-social-modal.profile-social-flyout-shell .profile-social-user small {
  color: var(--surface-theme-muted) !important;
}

/* Profile feed sidebars have their own card/tile classes, so keep them tied to the active theme here. */
body.profile-page {
  --profile-rail-surface: color-mix(in srgb, var(--card, #fff) 94%, var(--bg, #f0f2f5));
  --profile-rail-soft: color-mix(in srgb, var(--bg, #f0f2f5) 76%, var(--card, #fff));
  --profile-rail-hover: color-mix(in srgb, var(--accent, #1877f2) 13%, var(--profile-rail-soft));
  --profile-rail-border: color-mix(in srgb, var(--line, #d9dde3) 84%, transparent);
  --profile-rail-shadow: 0 16px 42px color-mix(in srgb, var(--text, #1c1e21) 9%, transparent);
}

html[data-theme="high_contrast"] body.profile-page {
  --profile-rail-surface: var(--card, #111);
  --profile-rail-soft: var(--bg, #000);
  --profile-rail-hover: color-mix(in srgb, var(--accent, #ffea00) 22%, var(--bg, #000));
  --profile-rail-border: var(--line, #fff);
  --profile-rail-shadow: none;
}

body.profile-page :where(
  .profile-left-sidebar-stack > .card:not(.has-card-wallpaper),
  .profile-sidebar-stack > .card:not(.has-card-wallpaper),
  .profile-sidebar-avatar-card,
  .profile-rebuilt-sidebar .profile-side-widget,
  .profile-sidebar-friends-card,
  .profile-sidebar-gallery,
  .profile-sidebar-gifts-card,
  .achievements-rail-card,
  .profile-owner-preview-sidecard,
  .left-sidebar .admin-sidebar-block,
  .right-sidebar .admin-sidebar-block
) {
  background: var(--profile-rail-surface) !important;
  background-color: var(--profile-rail-surface) !important;
  background-image: none !important;
  border-color: var(--profile-rail-border) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--profile-rail-shadow) !important;
}

body.profile-page .profile-sidebar-avatar-card {
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

body.profile-page :where(
  .profile-side-slide,
  .profile-side-feature,
  .profile-side-mini-grid a,
  .profile-side-empty,
  .profile-side-post-icon,
  .profile-side-large-icon,
  .profile-side-image,
  .profile-sidebar-gallery-tile,
  .profile-sidebar-gallery-empty,
  .profile-sidebar-friend-avatar,
  .profile-gift-tile,
  .profile-gifts-empty,
  .achievement-sidebar-tile,
  .achievement-sidebar-thumb,
  .achievements-sidebar-empty
) {
  background: var(--profile-rail-soft) !important;
  background-color: var(--profile-rail-soft) !important;
  border-color: var(--profile-rail-border) !important;
  color: var(--surface-theme-text) !important;
}

body.profile-page :where(
  .profile-side-slide:hover,
  .profile-side-mini-grid a:hover,
  .profile-sidebar-gallery-tile:hover,
  .achievement-sidebar-tile:hover
) {
  background: var(--profile-rail-hover) !important;
  color: var(--surface-theme-text) !important;
}

body.profile-page :where(
  .profile-side-head h3,
  .profile-sidebar-gallery-head h3,
  .profile-side-slide strong,
  .profile-side-feature strong,
  .profile-side-mini-grid span,
  .profile-gifts-head h3,
  .profile-gift-tile strong,
  .achievement-sidebar-name,
  .profile-owner-preview-sidecard strong
) {
  color: var(--surface-theme-text) !important;
}

body.profile-page :where(
  .profile-side-slide small,
  .profile-side-feature small,
  .profile-gifts-head p,
  .profile-gift-tile small,
  .profile-gift-tile em,
  .achievements-rail-meta,
  .profile-owner-preview-sidecard p,
  .profile-sidebar-gallery-head span,
  .profile-side-empty,
  .achievements-sidebar-empty
) {
  color: var(--surface-theme-muted) !important;
}

html[data-theme="high_contrast"] body.profile-page :where(
  .profile-sidebar-visibility-toggle,
  .achievements-sidebar-more-btn,
  .profile-owner-preview-sidecard .point-shop-cta-btn
) {
  background: var(--surface-theme-accent) !important;
  border-color: var(--surface-theme-accent) !important;
  color: var(--surface-theme-on-accent) !important;
}

/* Profile sidebar theme hardening: older profile/admin rules use specific !important white cards. */
body.profile-page .left-sidebar,
body.profile-page .right-sidebar,
body.profile-page .profile-left-sidebar-stack,
body.profile-page .profile-sidebar-stack,
body.profile-page .profile-rebuilt-sidebar {
  color: var(--surface-theme-text) !important;
}

body.profile-page .left-sidebar :is(
  .card:not(.has-card-wallpaper),
  .panel,
  .profile-sidebar-avatar-card,
  .profile-side-widget,
  .profile-sidebar-friends-card,
  .profile-sidebar-gallery,
  .profile-sidebar-gifts-card,
  .achievements-rail-card,
  .profile-owner-preview-sidecard,
  .admin-sidebar-block.admin-block-context-sidebar
),
body.profile-page .right-sidebar :is(
  .card:not(.has-card-wallpaper),
  .panel,
  .profile-sidebar-avatar-card,
  .profile-side-widget,
  .profile-sidebar-friends-card,
  .profile-sidebar-gallery,
  .profile-sidebar-gifts-card,
  .achievements-rail-card,
  .profile-owner-preview-sidecard,
  .admin-sidebar-block.admin-block-context-sidebar
) {
  background: var(--profile-rail-surface) !important;
  background-color: var(--profile-rail-surface) !important;
  background-image: none !important;
  border-color: var(--profile-rail-border) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--profile-rail-shadow) !important;
}

body.profile-page .left-sidebar .profile-sidebar-avatar-card.card,
body.profile-page .right-sidebar .profile-sidebar-avatar-card.card,
body.profile-page .profile-left-sidebar-stack > .profile-sidebar-avatar-card.card,
body.profile-page .profile-sidebar-stack > .profile-sidebar-avatar-card.card {
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  border-color: transparent !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.profile-page .left-sidebar :is(
  .profile-side-slide,
  .profile-side-feature,
  .profile-side-mini-grid a,
  .profile-side-empty,
  .profile-side-post-icon,
  .profile-side-large-icon,
  .profile-side-image,
  .profile-sidebar-gallery-tile,
  .profile-sidebar-gallery-empty,
  .profile-sidebar-friend-avatar,
  .profile-gift-tile,
  .profile-gifts-empty,
  .achievement-sidebar-tile,
  .achievement-sidebar-thumb,
  .achievements-sidebar-empty,
  .admin-sidebar-addon-placeholder,
  .admin-sidebar-link-card,
  .admin-sidebar-oembed
),
body.profile-page .right-sidebar :is(
  .profile-side-slide,
  .profile-side-feature,
  .profile-side-mini-grid a,
  .profile-side-empty,
  .profile-side-post-icon,
  .profile-side-large-icon,
  .profile-side-image,
  .profile-sidebar-gallery-tile,
  .profile-sidebar-gallery-empty,
  .profile-sidebar-friend-avatar,
  .profile-gift-tile,
  .profile-gifts-empty,
  .achievement-sidebar-tile,
  .achievement-sidebar-thumb,
  .achievements-sidebar-empty,
  .admin-sidebar-addon-placeholder,
  .admin-sidebar-link-card,
  .admin-sidebar-oembed
) {
  background: var(--profile-rail-soft) !important;
  background-color: var(--profile-rail-soft) !important;
  background-image: none !important;
  border-color: var(--profile-rail-border) !important;
  color: var(--surface-theme-text) !important;
}

body.profile-page .left-sidebar :is(
  .profile-side-head,
  .profile-sidebar-gallery-head,
  .profile-gifts-head,
  .admin-block-title-row
),
body.profile-page .right-sidebar :is(
  .profile-side-head,
  .profile-sidebar-gallery-head,
  .profile-gifts-head,
  .admin-block-title-row
) {
  border-color: var(--profile-rail-border) !important;
}

body.profile-page .left-sidebar :is(
  .profile-side-head h3,
  .profile-sidebar-gallery-head h3,
  .profile-gifts-head h3,
  .profile-side-slide strong,
  .profile-side-feature strong,
  .profile-side-mini-grid span,
  .profile-gift-tile strong,
  .achievement-sidebar-name,
  .admin-sidebar-block h3,
  .admin-sidebar-block strong
),
body.profile-page .right-sidebar :is(
  .profile-side-head h3,
  .profile-sidebar-gallery-head h3,
  .profile-gifts-head h3,
  .profile-side-slide strong,
  .profile-side-feature strong,
  .profile-side-mini-grid span,
  .profile-gift-tile strong,
  .achievement-sidebar-name,
  .admin-sidebar-block h3,
  .admin-sidebar-block strong
) {
  color: var(--surface-theme-text) !important;
}

body.profile-page .left-sidebar :is(
  .profile-side-slide small,
  .profile-side-feature small,
  .profile-gifts-head p,
  .profile-gift-tile small,
  .profile-gift-tile em,
  .achievements-rail-meta,
  .profile-sidebar-gallery-head span,
  .profile-side-empty,
  .achievements-sidebar-empty,
  .admin-sidebar-block p,
  .admin-sidebar-block small,
  .admin-sidebar-addon-placeholder small
),
body.profile-page .right-sidebar :is(
  .profile-side-slide small,
  .profile-side-feature small,
  .profile-gifts-head p,
  .profile-gift-tile small,
  .profile-gift-tile em,
  .achievements-rail-meta,
  .profile-sidebar-gallery-head span,
  .profile-side-empty,
  .achievements-sidebar-empty,
  .admin-sidebar-block p,
  .admin-sidebar-block small,
  .admin-sidebar-addon-placeholder small
) {
  color: var(--surface-theme-muted) !important;
}

body.profile-page .left-sidebar :is(.admin-block-icon, .profile-sidebar-visibility-toggle, .achievements-sidebar-more-btn),
body.profile-page .right-sidebar :is(.admin-block-icon, .profile-sidebar-visibility-toggle, .achievements-sidebar-more-btn) {
  background: var(--surface-theme-accent) !important;
  background-color: var(--surface-theme-accent) !important;
  border-color: var(--surface-theme-accent) !important;
  color: var(--surface-theme-on-accent) !important;
}

/* Backend/admin theme hardening: keep all admin surfaces tied to active theme variables. */
body.admin-surface,
body.admin-standalone-page,
body[class^="admin-"],
body[class*=" admin-"] {
  --admin-bg: var(--surface-theme-bg);
  --admin-panel: var(--surface-theme-card);
  --admin-panel-solid: var(--surface-theme-card-solid);
  --admin-panel-soft: var(--surface-theme-soft);
  --admin-ink: var(--surface-theme-text);
  --admin-muted: var(--surface-theme-muted);
  --admin-line: var(--surface-theme-line);
  --admin-blue: var(--surface-theme-accent);
  --admin-teal: color-mix(in srgb, var(--surface-theme-accent) 58%, #0f9f8f);
  --admin-gold: color-mix(in srgb, var(--surface-theme-accent) 38%, #d97706);
  --admin-danger: var(--surface-theme-danger);
  --admin-success: var(--surface-theme-success);
  --admin-shadow: var(--surface-theme-shadow);
  background:
    radial-gradient(circle at 12% 4%, color-mix(in srgb, var(--surface-theme-accent) 12%, transparent), transparent 30%),
    radial-gradient(circle at 88% 10%, color-mix(in srgb, var(--surface-theme-accent) 8%, transparent), transparent 28%),
    linear-gradient(180deg, var(--surface-theme-bg) 0%, var(--surface-theme-bg) 100%) !important;
  background-color: var(--surface-theme-bg) !important;
  color: var(--surface-theme-text) !important;
}

html[data-theme="high_contrast"] body.admin-surface,
html[data-theme="high_contrast"] body.admin-standalone-page,
html[data-theme="high_contrast"] body[class^="admin-"],
html[data-theme="high_contrast"] body[class*=" admin-"] {
  --admin-shadow: none;
  background: var(--surface-theme-bg) !important;
}

body.admin-surface :where(.topbar, .footer-bar),
body.admin-standalone-page :where(.topbar, .footer-bar),
body[class^="admin-"] :where(.topbar, .footer-bar),
body[class*=" admin-"] :where(.topbar, .footer-bar),
.admin-universal-bar,
.admin-universal-search,
.admin-universal-search-results {
  background: color-mix(in srgb, var(--surface-theme-card-solid) 88%, transparent) !important;
  background-color: color-mix(in srgb, var(--surface-theme-card-solid) 88%, transparent) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--admin-shadow) !important;
}

body.admin-surface :is(
  .main-content > .card,
  .card:not(.has-card-wallpaper),
  .panel,
  .admin-form-card,
  .admin-table-card,
  .admin-backend-card,
  .admin-backend-cache-panel,
  .admin-backend-hero > div,
  .admin-control-panel,
  .admin-control-hero,
  .admin-control-stat,
  .admin-control-link-card,
  .admin-page.card,
  .admin-card,
  .admin-ui-edit-card,
  .admin-site-data-card,
  .admin-site-data-panel,
  .platform-pro-panel,
  .settings-system-hub,
  .admin-cache-panel,
  .admin-sidebar-admin-hero,
  .admin-sidebar-admin-card,
  .admin-suite-hero-panel,
  .admin-suite-tool-card,
  .admin-suite-module-card,
  .admin-posts-panel,
  .admin-posts-hero > div,
  .admin-posts-hero > aside,
  .admin-posts-stats article,
  .admin-lite-hero,
  .admin-lite-section,
  .admin-lite-card,
  .admin-sidebar-block,
  .admin-feed-block,
  [class*="admin-"][class*="-card"],
  [class*="admin-"][class*="-panel"],
  [class*="admin-"][class*="-hero"],
  [class*="admin-"][class*="-section"],
  [class*="admin-"][class*="-stat"],
  [class*="admin-"][class*="-tile"],
  [class*="admin-"][class*="-module"]
),
body.admin-standalone-page :is(
  .admin-standalone-hero,
  .admin-standalone-card,
  [class*="admin-"][class*="-card"],
  [class*="admin-"][class*="-panel"],
  [class*="admin-"][class*="-hero"],
  [class*="admin-"][class*="-section"],
  [class*="admin-"][class*="-tile"]
) {
  background: var(--surface-theme-card) !important;
  background-color: var(--surface-theme-card) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--admin-shadow) !important;
}

body.admin-surface :is(
  .admin-universal-bar > a,
  .admin-universal-result,
  .admin-backend-link-grid a,
  .admin-quick-grid a,
  .settings-system-grid a,
  .fp14-links a,
  .admin-table td,
  .notif-admin-table td,
  .main-content table:not(.calendar-table) td,
  .admin-table-wrap,
  .notif-admin-table-wrap,
  .table-wrap,
  code,
  pre,
  details,
  .empty-state,
  .admin-backend-empty,
  .fp14-output,
  .admin-post-row,
  .admin-post-meta span,
  .admin-post-foot span,
  .admin-item-card,
  .animated-asset-admin-card,
  .admin-sidebar-feed-slot,
  .admin-sidebar-feed-built-in,
  .admin-sidebar-feed-custom-list > span,
  .admin-sidebar-feed-custom-list a,
  .admin-sidebar-addon-placeholder,
  .admin-sidebar-link-card,
  .admin-sidebar-oembed,
  .admin-notification-icon-field,
  .admin-suite-search-input,
  .admin-lite-subcard
),
body.admin-standalone-page :is(
  .admin-standalone-preview,
  .admin-standalone-note
) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

body.admin-surface :is(
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  select,
  textarea,
  .admin-universal-search input
),
body.admin-standalone-page :is(
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  select,
  textarea
) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: none !important;
}

body.admin-surface :is(input, select, textarea):focus,
body.admin-standalone-page :is(input, select, textarea):focus {
  border-color: var(--surface-theme-accent) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--surface-theme-accent) 20%, transparent) !important;
  outline: 0 !important;
}

body.admin-surface :is(
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  strong,
  label,
  summary,
  th,
  .admin-universal-result strong,
  .admin-universal-bar > a > strong,
  .admin-card-title,
  .admin-block-title-row h3,
  .admin-sidebar-block h3,
  .admin-sidebar-block strong
),
body.admin-standalone-page :is(
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  strong,
  label,
  summary
) {
  color: var(--surface-theme-text) !important;
}

body.admin-surface :is(
  p,
  small,
  .muted,
  .admin-muted,
  .admin-universal-empty,
  .admin-universal-result small,
  .admin-table th,
  .notif-admin-table th,
  .main-content table:not(.calendar-table) th,
  .admin-sidebar-block p,
  .admin-sidebar-block small,
  .admin-sidebar-addon-placeholder small,
  .admin-help,
  .admin-note
),
body.admin-standalone-page :is(
  p,
  small,
  .muted,
  .admin-standalone-muted
) {
  color: var(--surface-theme-muted) !important;
}

body.admin-surface :is(
  button,
  input[type="submit"],
  .pretty-action,
  .admin-grid-form button,
  .review-form button,
  .admin-cache-action,
  .admin-sidebar-button,
  .admin-sidebar-link-card.is-primary,
  .admin-suite-primary-action
),
body.admin-standalone-page :is(
  button,
  .admin-standalone-action
) {
  background: var(--surface-theme-accent) !important;
  background-color: var(--surface-theme-accent) !important;
  border-color: var(--surface-theme-accent) !important;
  color: var(--surface-theme-on-accent) !important;
}

body.admin-surface :is(
  a.pretty-action:nth-of-type(even),
  .admin-backend-hero-actions a:nth-child(2),
  button.secondary,
  .admin-secondary-action,
  .admin-standalone-action.is-secondary
),
body.admin-standalone-page :is(
  .admin-standalone-action.is-secondary
) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

.admin-universal-bar > a > span,
.admin-universal-search > span,
.admin-universal-result em,
body.admin-surface .admin-block-icon {
  background: var(--surface-theme-accent) !important;
  background-color: var(--surface-theme-accent) !important;
  color: var(--surface-theme-on-accent) !important;
}

body.admin-surface :is(
  .ok-box,
  .alert.success
),
body.admin-standalone-page .admin-standalone-ok {
  background: color-mix(in srgb, var(--surface-theme-success) 15%, var(--surface-theme-card)) !important;
  border-color: color-mix(in srgb, var(--surface-theme-success) 44%, var(--surface-theme-line)) !important;
  color: var(--surface-theme-success) !important;
}

body.admin-surface :is(
  .error-box,
  .alert.error
) {
  background: color-mix(in srgb, var(--surface-theme-danger) 14%, var(--surface-theme-card)) !important;
  border-color: color-mix(in srgb, var(--surface-theme-danger) 44%, var(--surface-theme-line)) !important;
  color: var(--surface-theme-danger) !important;
}

body.admin-surface :is(
  .load-lab-form,
  .load-lab-route-preview,
  .load-lab-risk,
  .load-lab-risk > strong,
  .load-lab-metric,
  .load-lab-panel,
  .load-lab-recommendation,
  .load-lab-snapshot span,
  .load-lab-guard-grid div,
  .load-lab-table td
) {
  background: var(--surface-theme-card) !important;
  background-color: var(--surface-theme-card) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--admin-shadow) !important;
}

body.admin-surface :is(
  .load-lab-route-preview,
  .load-lab-recommendation,
  .load-lab-snapshot span,
  .load-lab-guard-grid div,
  .load-lab-table td
) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
}

body.admin-surface :is(
  .load-lab-risk-good,
  .load-lab-recommendation.good
) {
  background: color-mix(in srgb, var(--surface-theme-success) 14%, var(--surface-theme-card)) !important;
  border-color: color-mix(in srgb, var(--surface-theme-success) 38%, var(--surface-theme-line)) !important;
}

body.admin-surface :is(
  .load-lab-risk-warn,
  .load-lab-risk-slow,
  .load-lab-recommendation.warn,
  .load-lab-recommendation.info
) {
  background: color-mix(in srgb, var(--surface-theme-accent) 13%, var(--surface-theme-card)) !important;
  border-color: color-mix(in srgb, var(--surface-theme-accent) 36%, var(--surface-theme-line)) !important;
}

body.admin-surface :is(
  .load-lab-risk-danger,
  .load-lab-diagnosis .load-lab-guard-grid div,
  .load-lab-recommendation.danger
) {
  background: color-mix(in srgb, var(--surface-theme-danger) 13%, var(--surface-theme-card)) !important;
  border-color: color-mix(in srgb, var(--surface-theme-danger) 40%, var(--surface-theme-line)) !important;
}

body.admin-surface :is(
  .load-lab-eyebrow,
  .load-lab-route-preview span
) {
  color: var(--surface-theme-accent) !important;
}

body.admin-surface :is(
  .load-lab-form label,
  .load-lab-route-preview strong,
  .load-lab-risk h2,
  .load-lab-risk > strong,
  .load-lab-metric strong,
  .load-lab-recommendation strong,
  .load-lab-snapshot strong,
  .load-lab-redis-samples summary,
  .load-lab-guard-grid strong,
  .load-lab-guard-grid code,
  .load-lab-table td
) {
  color: var(--surface-theme-text) !important;
}

body.admin-surface :is(
  .load-lab-form label small,
  .load-lab-route-preview small,
  .load-lab-actions p,
  .load-lab-risk p,
  .load-lab-metric span,
  .load-lab-metric small,
  .load-lab-redis-panel > p,
  .load-lab-recommendation p,
  .load-lab-snapshot span,
  .load-lab-guard-grid p,
  .load-lab-table th
) {
  color: var(--surface-theme-muted) !important;
}

html[data-theme="high_contrast"] body.admin-surface :is(
  .main-content > .card,
  .card,
  .panel,
  [class*="admin-"][class*="-card"],
  [class*="admin-"][class*="-panel"],
  [class*="admin-"][class*="-hero"],
  [class*="admin-"][class*="-section"],
  [class*="admin-"][class*="-tile"],
  input,
  select,
  textarea,
  table td,
  code,
  pre,
  details
),
html[data-theme="high_contrast"] body.admin-standalone-page :is(
  .admin-standalone-hero,
  .admin-standalone-card,
  input,
  select,
  textarea
) {
  border-color: var(--surface-theme-line) !important;
  box-shadow: none !important;
}

/* Box/window theme catch-all: one-off page CSS often names surfaces without .card/.panel. */
body:not(.guest-landing-page) :is(
  .box,
  [class*="-box"],
  [class*="-window"],
  [class*="-card"],
  [class*="-panel"],
  [class*="-widget"],
  [class*="-tile"],
  [class*="-surface"],
  [class*="-drawer"],
  [class*="-choice"],
  [class*="-stat"]
):not(.has-card-wallpaper):not(.feed-left-nav-card):not([class*="avatar"]):not([class*="image"]):not([class*="img"]):not([class*="media"]):not([class*="photo"]):not([class*="banner"]):not([class*="icon"]):not([class*="button"]):not([class*="btn"]):not([class*="swatch"]):not([class*="badge"]):not([class*="reaction"]):not([class*="emoji"]):not([class*="progress"]) {
  background: var(--surface-theme-card) !important;
  background-color: var(--surface-theme-card) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--surface-theme-shadow) !important;
      padding: 5px;
    border-radius: 10px;
}

body:not(.guest-landing-page) :is(
  [class*="-empty"],
  [class*="-note"],
  [class*="-notice"],
  [class*="-hint"],
  [class*="-meta"],
  [class*="-output"],
  [class*="-result"],
  [class*="-item"],
  [class*="-slot"],
  [class*="-wrap"]
):not([class*="avatar"]):not([class*="image"]):not([class*="img"]):not([class*="media"]):not([class*="photo"]):not([class*="banner"]):not([class*="icon"]):not([class*="button"]):not([class*="btn"]):not([class*="progress"]) {
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

body:not(.guest-landing-page) :is(
  [class*="-empty"],
  [class*="-note"],
  [class*="-notice"],
  [class*="-hint"],
  [class*="-output"],
  [class*="-result"],
  [class*="-slot"]
):not([class*="avatar"]):not([class*="image"]):not([class*="img"]):not([class*="media"]):not([class*="photo"]):not([class*="banner"]):not([class*="icon"]):not([class*="button"]):not([class*="btn"]):not([class*="progress"]) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  background-image: none !important;
}

body.admin-surface :is(
  .auto-panel,
  .auto-admin-stat-grid > div,
  .auto-admin-listing-card,
  .auto-sidebar-ad-preview,
  .maintenance-action-box,
  .hmn-autofill-card,
  .hmn-stat,
  .translation-table-wrap,
  .translation-save-row,
  .translation-test-row,
  .uma-panel,
  .uma-stat,
  .uma-thumb,
  .uw-banner-preset-choice
) {
  background: var(--surface-theme-card) !important;
  background-color: var(--surface-theme-card) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--admin-shadow) !important;
}

body.admin-surface :is(
  .auto-admin-footer-links a,
  .auto-sidebar-ad-preview,
  .hmn-stat,
  .hmn-note,
  .translation-table tbody th,
  .translation-save-row,
  .translation-test-row,
  .uma-thumb,
  .uma-result,
  .uw-banner-preset-choice
) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

body:not(.guest-landing-page) :is(
  .box,
  [class*="-box"],
  [class*="-window"],
  [class*="-card"],
  [class*="-panel"],
  [class*="-widget"],
  [class*="-tile"],
  [class*="-surface"],
  [class*="-drawer"],
  [class*="-choice"],
  [class*="-stat"]
) :is(h1, h2, h3, h4, h5, h6, strong, label, summary, th) {
  color: var(--surface-theme-text) !important;
}

body:not(.guest-landing-page) :is(
  .box,
  [class*="-box"],
  [class*="-window"],
  [class*="-card"],
  [class*="-panel"],
  [class*="-widget"],
  [class*="-tile"],
  [class*="-surface"],
  [class*="-drawer"],
  [class*="-choice"],
  [class*="-stat"]
):not(.post-card):not(.feed-post-card):not(.profile-post-card):not(.entity-post-card):not(.blog-post-card):not(.shop-item-card) :is(p, small, em, .muted, .helper-small-muted, [class*="-muted"], [class*="-help"]) {
  color: var(--surface-theme-muted) !important;
}

body:not(.guest-landing-page) :is(
  .box,
  [class*="-box"],
  [class*="-window"],
  [class*="-card"],
  [class*="-panel"],
  [class*="-widget"],
  [class*="-tile"],
  [class*="-surface"],
  [class*="-drawer"],
  [class*="-choice"],
  [class*="-stat"]
) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

html[data-theme="high_contrast"] body:not(.guest-landing-page) :is(
  .box,
  [class*="-box"],
  [class*="-window"],
  [class*="-card"],
  [class*="-panel"],
  [class*="-widget"],
  [class*="-tile"],
  [class*="-surface"],
  [class*="-drawer"],
  [class*="-choice"],
  [class*="-stat"],
  [class*="-empty"],
  [class*="-note"],
  [class*="-notice"],
  [class*="-output"],
  [class*="-result"],
  [class*="-slot"]
) {
  border-color: var(--surface-theme-line) !important;
  box-shadow: none !important;
}

/* Admin row/article escapes: these are plain child nodes, not named cards. */
body.admin-surface :is(
  .admin-backend-stats article,
  .admin-role-row,
  .admin-member-result-card,
  .admin-member-search-results,
  .admin-role-list,
  .admin-permission-details,
  .admin-role-mini-grid,
  .platform-admin-events article,
  .platform-admin-empty,
  .platform-admin-module-card,
  .platform-admin-switch,
  .platform-admin-section-head > span
) {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--admin-shadow) !important;
}

body.admin-surface :is(
  .admin-backend-stats article strong,
  .admin-role-row strong,
  .admin-member-result-card strong,
  .admin-member-identity strong,
  .admin-permission-details summary,
  .platform-admin-events article strong,
  .platform-admin-module-copy strong,
  .platform-admin-switch strong
) {
  color: var(--surface-theme-text) !important;
}

body.admin-surface :is(
  .admin-backend-stats article span,
  .admin-backend-stats article small,
  .admin-role-row span,
  .admin-member-result-card span,
  .admin-member-identity span,
  .admin-permission-details .perm-grid label,
  .platform-admin-events article small,
  .platform-admin-empty,
  .platform-admin-module-copy small,
  .platform-admin-module-card em,
  .platform-admin-switch small
) {
  color: var(--surface-theme-muted) !important;
}

body.admin-surface :is(
  .admin-role-row input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  .admin-role-row select,
  .admin-member-result-card input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  .admin-member-result-card select,
  .platform-admin-card input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  .platform-admin-card select,
  .platform-admin-card textarea
) {
  background: var(--surface-theme-card) !important;
  background-color: var(--surface-theme-card) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}

body.admin-surface :is(
  .platform-admin-events article span,
  .platform-admin-module-card.is-on em,
  .platform-admin-module-card:has(input:checked) em
) {
  color: var(--surface-theme-accent) !important;
}

html[data-theme="high_contrast"] body.admin-surface :is(
  .admin-backend-stats article,
  .admin-role-row,
  .admin-member-result-card,
  .admin-permission-details,
  .platform-admin-events article,
  .platform-admin-module-card,
  .platform-admin-switch,
  .platform-admin-section-head > span
) {
  box-shadow: none !important;
}

/* Main feed left navigation floats on light/bright themes; dark themes restore surfaces below. */
body.home-feed-page .left-sidebar,
body.home-feed-page .left-sidebar .feed-sidebar-stack,
body.home-feed-page .left-sidebar .feed-left-nav-card,
body.home-feed-page .left-sidebar .feed-left-nav-card.card {
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  border-color: transparent !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

body.home-feed-page .left-sidebar .feed-left-nav-card {
  padding-left: 0 !important;
  padding-right: 0 !important;
}

body.home-feed-page .left-sidebar .feed-left-nav-link,
body.home-feed-page .left-sidebar .feed-left-nav-link:hover {
  background: transparent !important;
  background-color: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

body.home-feed-page .left-sidebar .feed-left-nav-link.is-active {
  background: transparent !important;
  background-color: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  font-weight: 950 !important;
}

:is(html[data-theme="dark"], html[data-theme="lavender_night"], html[data-theme="midnight_slate"], html[data-theme="high_contrast"]) body.home-feed-page .left-sidebar .feed-left-nav-card,
:is(html[data-theme="dark"], html[data-theme="lavender_night"], html[data-theme="midnight_slate"], html[data-theme="high_contrast"]) body.home-feed-page .left-sidebar .feed-left-nav-card.card {
  background: var(--surface-theme-card) !important;
  background-color: var(--surface-theme-card) !important;
  background-image: none !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
  box-shadow: var(--surface-theme-shadow) !important;
}

:is(html[data-theme="dark"], html[data-theme="lavender_night"], html[data-theme="midnight_slate"], html[data-theme="high_contrast"]) body.home-feed-page .left-sidebar .feed-left-nav-link:hover,
:is(html[data-theme="dark"], html[data-theme="lavender_night"], html[data-theme="midnight_slate"], html[data-theme="high_contrast"]) body.home-feed-page .left-sidebar .feed-left-nav-link.is-active {
  background: var(--surface-theme-soft) !important;
  background-color: var(--surface-theme-soft) !important;
  border-color: var(--surface-theme-line) !important;
  color: var(--surface-theme-text) !important;
}
