/* Neutral fills retain their contrast over custom project backdrops. */
:root {
  --sd-header-utility-gap: 4px;
  --sd-button-black: #0a0a0a;
  --sd-button-black-hover: #151515;
  --sd-button-charcoal: #121212;
  --sd-button-hover: #202020;
  --sd-button-selected: #191919;
  --sd-button-raised: linear-gradient(180deg, rgb(255 255 255 / 4%), transparent);
}

@layer sd-control-surfaces {
  #preview-bar {
    --sd-editor-control-size: 38px;
    --sd-editor-control-radius: 10px;
    --sd-editor-utility-width: var(--sd-editor-control-size);
  }
  html:not(.sd-phone-mode) #preview-bar {
    --sd-editor-utility-width: 30px;
    column-gap: var(--sd-header-utility-gap) !important;
  }
  html:not(.sd-phone-mode) #preview-options { column-gap: var(--sd-header-utility-gap) !important; padding-inline-end: 0 !important; }
  html:not(.sd-phone-mode) #preview-bar :is(.preview-icon-btn, .sd-draft-reader) { margin-inline: 0 !important; }
  html.sd-phone-mode #preview-bar { --sd-editor-control-radius: 7px; }

  #preview-bar :is(.preview-toggle, .preview-icon-btn, .sd-draft-reader) {
    box-sizing: border-box !important;
    height: var(--sd-editor-control-size) !important;
    min-height: var(--sd-editor-control-size) !important;
    border-radius: var(--sd-editor-control-radius) !important;
  }
  #preview-bar :is(.preview-icon-btn, .sd-draft-reader) {
    width: var(--sd-editor-utility-width) !important;
    min-width: var(--sd-editor-utility-width) !important;
    max-width: var(--sd-editor-utility-width) !important;
    padding: 0 !important;
    align-self: center;
    justify-self: center;
    background: transparent !important;
    box-shadow: none !important;
  }
  #preview-bar :is(.preview-icon-btn, .sd-draft-reader):is(:hover, :focus-visible, :active):not(:disabled) {
    background-color: var(--sd-button-charcoal) !important;
  }
  #preview-overlay #preview-bar :is(.preview-icon-btn, .sd-draft-reader):focus-visible {
    background-color: var(--sd-button-charcoal) !important;
    outline: 2px solid var(--accent) !important;
    outline-offset: -2px;
  }
  #preview-bar :is(.preview-icon-btn, .sd-draft-reader) > svg {
    width: 22px !important;
    height: 22px !important;
  }
  html.sd-phone-mode #preview-options:has(> .sd-draft-reader) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) var(--sd-editor-control-size) !important;
  }
  @media (max-width: 1000px) {
    html:not(.sd-phone-mode) #preview-bar {
      display: grid !important;
      grid-template-columns: max-content repeat(6, var(--sd-editor-utility-width)) !important;
      justify-content: start !important;
      gap: 6px var(--sd-header-utility-gap) !important;
    }
    html:not(.sd-phone-mode) #preview-bar-logo { grid-area: 1 / 1; justify-self: start; }
    html:not(.sd-phone-mode) #preview-bar-title {
      grid-area: 1 / 1 / 2 / -1;
      margin-inline-start: 48px !important;
      width: auto !important;
    }
    html:not(.sd-phone-mode) #preview-options {
      grid-area: 2 / 1;
      width: max-content !important;
      margin: 0 !important;
    }
    html:not(.sd-phone-mode) #preview-bar > .preview-icon-btn { grid-row: 2; }
  }

  :where(
    .sd-black-button, .btn-sec:not(.upg-cta), .btn-primary:not(.upg-cta, #account-modal-bg .btn-primary, #dupe-submit-btn, #adpt-submit-btn),
    .bkp-btn, .trash-action-btn, .vh-action-btn, .account-photo-remove, .fmt-btn, .unstack-btn,
    #proj-btn, #hamburger-btn, #new-btn, #project-search-toggle, #layer-dropdown-toggle,
    #mobile-project-home, #mobile-drafts-btn, #sd-phone-context-more, .sd-phone-card-more, #upgrade-free-plan-btn,
    #draft-workspace-tab, .hdr-btn.export-btn, .project-draft-toggle, .mm-grid-item, .mm-close, #pv-search-scope-both,
    .preview-toggle, .preview-search-inline-btn, .preview-replace-btn,
    .pv-focus-tool, .pv-mini-nav-button, .pv-nav-button, .pv-pane-action, .pv-pane-back-btn,
    .pv-scene-convert-btn, .pv-focus-home-btn, .pv-focus-collapse-toggle, .pv-logline-btn,
    .pv-distill-btn, .pv-story-render-btn, .pv-pane-render-btn, .pv-pane-format-btn,
    .card-add, .card-open-btn, .card-restore-btn, .card-ai-btn, .sd-focus-open-btn,
    .sd-focus-panel-btn, .storypad-ai-btn, .scene-page-tab, .sd-card-read-aloud,
    .sd-proposal-refresh, .sd-recordings button, .sd-idea-add, .sd-idea-commit, .sd-idea-undo-remove,
    .mgr-view-btn, .mgr-card-action-btn, .mgr-card-open-btn, #manager-close-btn,
    .notes-back-btn, .note-tag-add-btn, .trash-restore-btn, .project-search-chip,
    .ai-chat-hdr-btn, .ai-chat-quick, .chat-apply-btn, .edgar-note-focus-action,
    #ai-chat-fab-drag, #ai-chat-fab-minimize, #ai-chat-restore-chip, #ai-chat-research-depth, #ai-chat-notes-archive-toggle,
    .founder-ai-note-close, .sd-edgar-hide-menu-cancel
  ) {
    background-color: var(--sd-control-rest, var(--sd-button-charcoal)) !important;
    background-image: var(--sd-control-image, none) !important;

    &:where(:hover:not(:disabled), :active:not(:disabled)) {
      background-color: var(--sd-control-hover, var(--sd-button-hover)) !important;
    }
    &:where(.active, .on, .selected, [aria-pressed="true"], [aria-current="true"]) {
      background-color: var(--sd-button-selected) !important;
    }
  }

  /* Navigation tabs and menu choices had a slight highlight above a nearly black base. */
  :where(
    #proj-btn, #new-btn, #project-search-toggle, .preview-toggle, .layer-tab, .bar-pill,
    .mgr-add-btn, .mm-grid-item, #bar-dupe-btn, .proj-manager-btn, .proj-home-btn,
    .export-menu button, #project-draft-menu button, #project-draft-menu summary,
    #pv-search-scope-both, #pv-search-scope-ref, #pv-search-scope-final
  ) {
    --sd-control-rest: #0e0e0e;
    --sd-control-image: var(--sd-button-raised);
  }

  :where(.btn-primary, .sd-reader-play, .sd-reader-quick, .sd-black-primary) {
    --sd-control-rest: var(--sd-button-black);
    --sd-control-hover: var(--sd-button-black-hover);
  }

  :where(.layer-tab.active, #project-draft-menu [aria-current="true"], #pv-search-scope-both.on):where(:not(:focus-visible, :hover)) {
    background-color: var(--sd-button-black) !important;
    background-image: var(--sd-button-raised) !important;
  }
  :where(.mm-item, #mobile-logout-btn, .ctx-item:not(.danger), html.sd-phone-mode #layer-dropdown-menu .layer-tab):hover {
    background-color: var(--sd-button-hover) !important;
    background-image: none !important;
  }

  /* These choices already signal the selected layer, format, or plan with color. */
  :where(
    .layer-tab, .bar-pill, .type-card, .type-pill, .mgr-add-btn, #bar-dupe-btn,
    .proj-manager-btn, .proj-home-btn, .export-menu button,
    #project-draft-menu button, #project-draft-menu summary, .ai-chat-mode-btn,
    .ai-chat-research-tab, #edgar-support-include-chat, .account-plan-option,
    #pv-search-scope-both, #pv-search-scope-ref, #pv-search-scope-final
  ):where(:not(:hover, :focus-visible, :active, .active, .on, .selected, [aria-selected="true"], [aria-current="true"], [aria-pressed="true"])) {
    background-color: var(--sd-control-rest, var(--sd-button-charcoal)) !important;
    background-image: var(--sd-control-image, none) !important;
  }
}
