/* Approved Fortune / Wafer presentation.
   Additive UI only: route layout, canvas content, native controls and account
   behavior remain with their existing owners. Load after page/surface styles.
   Shared navigation and authentication have their own component styles. */
@layer fortune-design {
  html:not([data-fortune-theme="dark"]) {
    --fortune-surface-bg: #fff !important;
    --fortune-surface-panel: #fff !important;
    --fortune-surface-raised: #f7f7f8 !important;
    --fortune-surface-inset: #f5f5f6 !important;
    --fortune-surface-hover: #efeff1 !important;
    --fortune-surface-line: #e3e3e6 !important;
    --fortune-surface-line-soft: #ededf0 !important;
    --fortune-surface-text: #09090b !important;
    --fortune-surface-muted: #58585f !important;
    --fortune-surface-dim: #777780 !important;
    --fortune-surface-accent: #171719 !important;
    --fortune-surface-accent-text: #fff !important;
    --fortune-surface-action: #111113 !important;
    --fortune-surface-action-text: #fff !important;
    --fortune-surface-active: #f0f0f2 !important;
    --fortune-surface-active-text: #101012 !important;
    --fortune-surface-shadow: 0 12px 40px #1717210b !important;
    --fortune-approved-glass: rgb(255 255 255 / 94%);
    --fortune-approved-tab-tray: linear-gradient(180deg, #f8f8f9eb, #eeeef1c7);
    --fortune-approved-tab-surface: linear-gradient(180deg, #fff, #ffffffed);
    --fortune-approved-tab-line: #ffffffed;
    --fortune-approved-tab-shadow: 0 1px 3px #1f262c19, 0 3px 8px #1f262c0a;
    --fortune-approved-card-shadow: 0 3px 16px #15152404;
    --fortune-approved-focus: #62626c;
  }

  html[data-fortune-theme="dark"] {
    --fortune-surface-bg: #101012 !important;
    --fortune-surface-panel: #19191d !important;
    --fortune-surface-raised: #242429 !important;
    --fortune-surface-inset: #202025 !important;
    --fortune-surface-hover: #2a2a31 !important;
    --fortune-surface-line: #36363e !important;
    --fortune-surface-line-soft: #2c2c33 !important;
    --fortune-surface-text: #f6f6f8 !important;
    --fortune-surface-muted: #b0b0ba !important;
    --fortune-surface-dim: #8f8f9c !important;
    --fortune-surface-accent: #f0f0f4 !important;
    --fortune-surface-accent-text: #111113 !important;
    --fortune-surface-action: #f5f5f7 !important;
    --fortune-surface-action-text: #151518 !important;
    --fortune-surface-active: #292930 !important;
    --fortune-surface-active-text: #f6f6f8 !important;
    --fortune-surface-shadow: 0 12px 40px #0004 !important;
    --fortune-approved-glass: rgb(25 25 29 / 94%);
    --fortune-approved-tab-tray: linear-gradient(180deg, #2a2a31eb, #202025db);
    --fortune-approved-tab-surface: linear-gradient(180deg, #41414a, #34343b);
    --fortune-approved-tab-line: #ffffff14;
    --fortune-approved-tab-shadow: 0 1px 3px #0004, 0 3px 8px #0002;
    --fortune-approved-card-shadow: 0 3px 16px #00000012;
    --fortune-approved-focus: #bebecb;
  }

  html {
    --fortune-radius: 18px;
    --fortune-composer-radius: 22px;
    --fortune-accent: var(--fortune-surface-accent) !important;
    --landing-accent: var(--fortune-surface-accent) !important;
    --fortune-approved-rgb: conic-gradient(from 210deg, var(--fortune-warm-stops, #ffb000 0%, #ff7f0a 38%, #ff4a1f 70%, #e01800 100%));
  }

  /* Keep all existing tokens as aliases so older screens receive the same
     palette without inspecting or changing their rendered content. */
  html[data-fortune-theme] body:is(.fortune-ui, .split-studio, .fortune-landing, .fortune-projects, .fortune-legal, .fortune-academy, .fortune-adspy, .fortune-team, .director-open-canvas) {
    --ui-bg: var(--fortune-surface-bg) !important;
    --ui-panel: var(--fortune-surface-panel) !important;
    --ui-panel-2: var(--fortune-surface-raised) !important;
    --ui-surface: var(--fortune-surface-panel) !important;
    --ui-raised: var(--fortune-surface-raised) !important;
    --ui-inset: var(--fortune-surface-inset) !important;
    --ui-hover: var(--fortune-surface-hover) !important;
    --ui-line: var(--fortune-surface-line) !important;
    --ui-line-soft: var(--fortune-surface-line-soft) !important;
    --ui-text: var(--fortune-surface-text) !important;
    --ui-muted: var(--fortune-surface-muted) !important;
    --ui-dim: var(--fortune-surface-dim) !important;
    --ui-action: var(--fortune-surface-action) !important;
    --ui-action-text: var(--fortune-surface-action-text) !important;
    --bg: var(--fortune-surface-bg) !important;
    --panel: var(--fortune-surface-panel) !important;
    --surface: var(--fortune-surface-panel) !important;
    --elevated: var(--fortune-surface-raised) !important;
    --inset: var(--fortune-surface-inset) !important;
    --soft: var(--fortune-surface-inset) !important;
    --hover: var(--fortune-surface-hover) !important;
    --line: var(--fortune-surface-line) !important;
    --line-soft: var(--fortune-surface-line-soft) !important;
    --text: var(--fortune-surface-text) !important;
    --ink: var(--fortune-surface-text) !important;
    --muted: var(--fortune-surface-muted) !important;
    --dim: var(--fortune-surface-dim) !important;
    --gold: var(--fortune-surface-accent) !important;
    --accent: var(--fortune-surface-accent) !important;
    --active: var(--fortune-surface-active) !important;
    --button: var(--fortune-surface-action) !important;
    --button-text: var(--fortune-surface-action-text) !important;
    --fortune-composer-surface: var(--fortune-surface-panel) !important;
    background-color: var(--fortune-surface-bg) !important;
    color: var(--fortune-surface-text) !important;
  }

  html[data-fortune-theme] body.fortune-academy {
    --academy-bg: var(--fortune-surface-bg) !important;
    --academy-panel: var(--fortune-surface-panel) !important;
    --academy-inset: var(--fortune-surface-inset) !important;
    --academy-hover: var(--fortune-surface-hover) !important;
    --academy-line: var(--fortune-surface-line) !important;
    --academy-soft: var(--fortune-surface-line-soft) !important;
    --academy-text: var(--fortune-surface-text) !important;
    --academy-muted: var(--fortune-surface-muted) !important;
    --academy-accent: var(--fortune-surface-accent) !important;
    --academy-active: var(--fortune-surface-active) !important;
  }

  html[data-fortune-theme] body.fortune-team {
    --team-bg: var(--fortune-surface-bg) !important;
    --team-card: var(--fortune-surface-panel) !important;
    --team-text: var(--fortune-surface-text) !important;
    --team-muted: var(--fortune-surface-muted) !important;
    --team-line: var(--fortune-surface-line) !important;
    --team-hover: var(--fortune-surface-hover) !important;
    --team-button: var(--fortune-surface-action) !important;
    --team-button-text: var(--fortune-surface-action-text) !important;
    --team-accent: var(--fortune-surface-accent) !important;
  }

  html[data-fortune-theme] body.director-open-canvas {
    --director-hover: var(--fortune-surface-hover) !important;
    --director-active: var(--fortune-surface-active) !important;
    --director-shadow: var(--fortune-surface-shadow) !important;
  }

  /* Application cards, not authored canvas nodes, media or storefront frames. */
  html[data-fortune-theme] body:is(.fortune-ui, .fortune-projects, .fortune-academy, .fortune-adspy, .fortune-team, .fortune-legal) :is(.integration-card, .connection-detail, .connection-review, .settings-workspaces, .launch-card, .launch-campaign, .launch-empty, .launch-review, .launch-preset-card, .launch-soon-card, .team-card, .research-card, .brand-card, .social-post-card, .sh-starter-card, .ff-saved-card, .ff-home-setup, .ff-result-grid > section, .fw-agent-card, .fw-saved-asset, .project-thumbnail, .projects-empty, .studio-history-card) {
    border-color: var(--fortune-surface-line) !important;
    border-radius: 18px !important;
    background: var(--fortune-approved-glass) !important;
    color: var(--fortune-surface-text) !important;
    box-shadow: var(--fortune-approved-card-shadow) !important;
  }

  html[data-fortune-theme] body.fortune-legal :is(article, section, .contents, .deletion) {
    background: var(--fortune-approved-glass) !important;
    border-radius: 18px !important;
  }

  /* Menus/dialogs keep their native scroll bounds and stacking contexts. */
  html[data-fortune-theme] body :is(.fortune-account-panel, .create-destination-menu, .library-dialog, .video-studio-menu, .home-store-popover, .connection-dialog, .light-dialog, .studio-guide-dialog, .ff-dialog, .team-dialog, .ad-assistant-menu, .bhq-menu, .bhq-dialog, .bhq-dock-panel, .research-dialog, .brand-dialog, .director-dialog) {
    background: var(--fortune-approved-glass) !important;
    color: var(--fortune-surface-text) !important;
    border-color: var(--fortune-surface-line) !important;
    border-radius: 20px !important;
    box-shadow: var(--fortune-surface-shadow) !important;
  }

  /* Only UI form fields: omit color/range/file controls and editable artwork. */
  html[data-fortune-theme] body:is(.fortune-ui, .fortune-team, .fortune-projects, .fortune-academy, .fortune-adspy) :is(.settings-workspaces, .connections-page, .launch-card, .team-card, .light-dialog, .library-dialog, .connection-dialog, .ff-dialog) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]), textarea, select) {
    border-radius: 12px !important;
    border-color: var(--fortune-surface-line) !important;
    background-color: var(--fortune-surface-panel) !important;
    color: var(--fortune-surface-text) !important;
  }

  /* Use painted background layers for the RGB edge: no overlay can cover a
     field, no new stacking context can trap a menu, and no overflow is clipped. */
  html[data-fortune-theme] body :is(.fortune-composer, #sh-form, #chat-form, #script-form, #studio-form, #academy-chat-form, .ad-chat-composer, .ff-composer, .image-main-composer, .vs-composer, .director-fort-panel-form, :where(#canvas-operation) > #composer, .home-composer-stack) {
    border: 1px solid transparent !important;
    border-radius: var(--fortune-composer-radius) !important;
    background: linear-gradient(var(--fortune-surface-panel), var(--fortune-surface-panel)) padding-box, var(--fortune-approved-rgb) border-box !important;
    color: var(--fortune-surface-text) !important;
    box-shadow: -7px 0 20px -12px #ff4a1f6b, 7px 0 20px -12px #ffb00069, 0 -6px 20px -12px #ff7f0a66, 0 6px 20px -12px #e0180061 !important;
    transition: box-shadow .35s ease, border-color .25s ease !important;
  }

  html[data-fortune-theme] body :is(.fortune-composer, #sh-form, #chat-form, #script-form, #studio-form, #academy-chat-form, .ad-chat-composer, .ff-composer, .image-main-composer, .vs-composer, .director-fort-panel-form, :where(#canvas-operation) > #composer, .home-composer-stack):focus-within {
    box-shadow: -7px 0 22px -11px #ff4a1f8f, 7px 0 22px -11px #ffb00080, 0 -6px 22px -11px #ff7f0a80, 0 6px 22px -11px #e0180080 !important;
  }

  /* Home has one shared outer surface around its context controls. */
  html[data-fortune-theme] body.app-hub.chat-home .home-composer-stack #chat-form,
  html[data-fortune-theme] body.app-hub.chat-home .home-composer-stack #chat-form:focus-within {
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  /* Existing tab semantics, event handlers and hidden/disabled tabs stay intact. */
  html[data-fortune-theme] body :is(.studio-workspace-switch, .projects-view-switch, .output-tabs, .voice-duration-switch, .context-tabs, .format-switch, .fw-chat-tabs, .launch-tabs) {
    border: 1px solid var(--fortune-surface-line-soft) !important;
    border-radius: 999px !important;
    background: var(--fortune-approved-tab-tray) !important;
    box-shadow: 0 1px 0 var(--fortune-approved-tab-line) inset, 0 2px 5px #19202805 !important;
    backdrop-filter: blur(16px) saturate(1.15) !important;
    -webkit-backdrop-filter: blur(16px) saturate(1.15) !important;
    padding: 3px !important;
    gap: 2px !important;
    overflow: visible !important;
  }

  html[data-fortune-theme] body :is(.studio-workspace-switch, .projects-view-switch, .output-tabs, .voice-duration-switch, .context-tabs, .format-switch, .fw-chat-tabs, .launch-tabs) > :is(button, a) {
    border: 0 !important;
    border-radius: 999px !important;
    color: var(--fortune-surface-muted) !important;
    background: transparent !important;
    box-shadow: none !important;
    transition: color .22s ease, background .25s ease, transform .36s cubic-bezier(.22, 1.2, .36, 1) !important;
  }

  html[data-fortune-theme] body :is(.studio-workspace-switch, .projects-view-switch, .output-tabs, .voice-duration-switch, .context-tabs, .format-switch, .fw-chat-tabs, .launch-tabs) > :is(button, a):hover:not(:disabled) {
    color: var(--fortune-surface-text) !important;
    background: var(--fortune-surface-hover) !important;
  }

  html[data-fortune-theme] body :is(.studio-workspace-switch, .projects-view-switch, .output-tabs, .voice-duration-switch, .context-tabs, .format-switch, .fw-chat-tabs, .launch-tabs) > :is(button, a):is([aria-selected="true"], [aria-pressed="true"], [aria-current="page"], .active, .is-active) {
    color: var(--fortune-surface-text) !important;
    background: var(--fortune-approved-tab-surface) !important;
    box-shadow: var(--fortune-approved-tab-shadow) !important;
  }

  html[data-fortune-theme] body .studio-motion-switch[data-highlight-ready="true"] > [aria-selected="true"] {
    background: transparent !important;
    box-shadow: none !important;
  }

  html[data-fortune-theme] body .studio-switch-highlight {
    background: var(--fortune-approved-tab-surface) !important;
    box-shadow: var(--fortune-approved-tab-shadow) !important;
    border: 1px solid var(--fortune-approved-tab-line) !important;
    box-sizing: border-box;
    transition: transform .58s cubic-bezier(.22, 1.08, .3, 1), width .58s cubic-bezier(.22, 1.08, .3, 1), height .25s ease, opacity .2s ease !important;
  }

  html[data-fortune-theme] body :is(.primary-button, .secondary-button, .quiet-button, .button-primary, .button-tonal, .project-search, .search-submit, .academy-secondary, .academy-fort-primary) {
    border-radius: 999px !important;
  }

  html[data-fortune-theme] body :is(.primary-button, .button-primary) {
    background: var(--fortune-surface-action) !important;
    border-color: var(--fortune-surface-action) !important;
    color: var(--fortune-surface-action-text) !important;
  }

  html[data-fortune-theme] body :is(.secondary-button, .quiet-button, .button-tonal) {
    background: var(--fortune-surface-inset) !important;
    border-color: var(--fortune-surface-line) !important;
    color: var(--fortune-surface-text) !important;
  }

  html[data-fortune-theme] body :is(.studio-workspace-switch, .projects-view-switch, .output-tabs, .voice-duration-switch, .context-tabs, .format-switch, .fw-chat-tabs, .launch-tabs) > :is(button, a):focus-visible {
    outline: 2px solid var(--fortune-approved-focus) !important;
    outline-offset: 2px !important;
  }

  /* Only the landing navigation carries a glass surface. The fixed header's
     full-width strip stays clear so moving artwork is never hard-clipped. */
  html[data-fortune-theme] body.fortune-landing [data-fortune-header].site-header {
    grid-template-columns: minmax(0, 1fr) auto !important;
    background: transparent !important;
    backdrop-filter: none !important;
  }

  html[data-fortune-theme] body.fortune-landing [data-fortune-header].site-header > [data-fortune-header-start] {
    grid-column: 1 !important;
    overflow: visible !important;
  }

  html[data-fortune-theme] body.fortune-landing [data-fortune-header].site-header > [data-fortune-header-actions] {
    grid-column: 2 !important;
  }

  html[data-fortune-theme] body.fortune-landing [data-fortune-header].site-header [data-fortune-header-context] {
    flex: 0 1 auto !important;
    width: max-content !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  html[data-fortune-theme] body.fortune-landing [data-fortune-header].site-header .header-nav {
    box-sizing: border-box !important;
    height: auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 4px !important;
    gap: 2px !important;
    border: 1px solid var(--fortune-surface-line) !important;
    border-radius: 999px !important;
    background: var(--fortune-approved-glass) !important;
    color: var(--fortune-surface-text) !important;
    box-shadow: 0 3px 14px #15152408 !important;
    backdrop-filter: blur(14px) saturate(1.1) !important;
    -webkit-backdrop-filter: blur(14px) saturate(1.1) !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
    pointer-events: auto;
  }

  html[data-fortune-theme] body.fortune-landing [data-fortune-header].site-header .header-nav::-webkit-scrollbar {
    display: none;
  }

  html[data-fortune-theme] body.fortune-landing [data-fortune-header].site-header .header-nav > :is(a, button) {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 34px !important;
    padding: 7px 12px !important;
    border-radius: 999px !important;
    white-space: nowrap;
  }

  @media (prefers-reduced-motion: reduce) {
    html[data-fortune-theme] body :is(.fortune-composer, #sh-form, #chat-form, #script-form, #studio-form, #academy-chat-form, .ad-chat-composer, .ff-composer, .image-main-composer, .vs-composer, .director-fort-panel-form, :where(#canvas-operation) > #composer, .home-composer-stack, .studio-switch-highlight),
    html[data-fortune-theme] body :is(.studio-workspace-switch, .projects-view-switch, .output-tabs, .voice-duration-switch, .context-tabs, .format-switch, .fw-chat-tabs, .launch-tabs) > :is(button, a) {
      transition: none !important;
    }
  }
}
