$morph-ease: cubic-bezier(0.215, 0.61, 0.355, 1);
$morph-duration: 0.25s;

.footerRoot {
  width: 100%;
  user-select: none;
  background: #181818;
  --tool-chrome-icon: rgba(255, 255, 255, 0.88);
  --tool-chrome-icon-hover: #ffffff;

  ::selection {
    background: rgba(255, 255, 255, 0.12);
    color: #e0e0e0;
  }
}

.footerBar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0.25rem 1rem;
  background: #181818;
  border-top: 1px solid var(--tool-chrome-border);
}

.footerBrand {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
  margin-right: 0.375rem;
  padding: 0.375rem 0.5rem;
  border-radius: 0.5rem;
  text-decoration: none;
  color: #fff;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      background: #2a2a2a;
      color: #fff;
    }
  }
}

.footerBrandLogo {
  flex-shrink: 0;
  width: 0.875rem;
  height: 0.875rem;
}

.footerBrandName {
  font-size: 0.9375rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1;
  white-space: nowrap;
}

.footerLeft {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  flex-shrink: 0;
}

.footerRight {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
}

.footerTabs {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  flex-shrink: 0;
}

.footerTab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0.375rem 0.75rem;
  border: none;
  border-radius: 0.5rem;
  background: transparent;
  color: #fff;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;

  &:focus:not(:focus-visible) {
    outline: none;
  }

  &:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.35);
    outline-offset: 2px;
  }

  @media (hover: hover) and (pointer: fine) {
    &:hover:not(.footerTabActive) {
      background: #2a2a2a;
      color: #fff;
    }
  }
}

.footerTabHoverArea {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.footerTabBadge {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  pointer-events: none;
  user-select: none;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 999px;
  background-color: rgba(255, 255, 255, 0.22);
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.5625rem;
  font-weight: 600;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(45%, -18%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.18);
}

.footerTabActive {
  background: #2a2a2a;
  color: #fff;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      color: #fff;
    }
  }
}

.footerUtilities {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.footerGroup {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.footerBarControls {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.root {
  --review-morph-duration: #{$morph-duration};
  --review-morph-ease: #{$morph-ease};
  pointer-events: none;
  position: absolute;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  // Keep the positioning shell transparent so only the rounded morphToolbar pill shows.
  &[data-prototype-root] {
    background: transparent;
  }
  user-select: none;

  ::selection {
    background: rgba(255, 255, 255, 0.12);
    color: #e0e0e0;
  }

  &.cornerBottomRight {
    right: 1rem;
    bottom: 1rem;
    align-items: flex-end;
  }

  &.cornerBottomLeft {
    left: 1rem;
    bottom: 1rem;
    align-items: flex-start;
  }

  &.cornerTopRight {
    right: 1rem;
    top: 1rem;
    align-items: flex-end;
  }

  &.cornerTopLeft {
    left: 1rem;
    top: 1rem;
    align-items: flex-start;
  }

  &.cornerTopCenter {
    left: 50%;
    top: 1rem;
    transform: translateX(-50%);
    align-items: center;
  }

  &.cornerBottomCenter {
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    align-items: center;
  }

  &.cornerLeftCenter {
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    align-items: flex-start;
  }

  &.cornerRightCenter {
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    align-items: flex-end;
  }

  &.isDragging {
    right: auto !important;
    bottom: auto !important;
    left: auto;
    top: auto;
    transform: none !important;
    align-items: flex-start;
  }

  &.isSnapping {
    transition:
      left 0.25s cubic-bezier(0.215, 0.61, 0.355, 1),
      top 0.25s cubic-bezier(0.215, 0.61, 0.355, 1);
  }

  @media (prefers-reduced-motion: reduce) {
    &.isSnapping {
      transition: none;
    }
  }

  &.cornerBottomRight,
  &.cornerTopRight,
  &.cornerRightCenter {
    .morphToolbar.morphCollapsed:active {
      transform-origin: center right;
    }
  }

  &.cornerBottomLeft,
  &.cornerTopLeft,
  &.cornerLeftCenter {
    .morphToolbar.morphCollapsed:active {
      transform-origin: center left;
    }
  }

  &.cornerTopCenter,
  &.cornerBottomCenter {
    .morphToolbar.morphCollapsed:active {
      transform-origin: center center;
    }
  }
}

.bar {
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
  background: transparent;

  &.barExpanded {
    cursor: default;
    touch-action: auto;
  }

  &.dragging {
    cursor: grabbing;
  }
}

.barGroup {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  width: auto;
  user-select: none;
  background: transparent;

  ::selection {
    background: transparent;
    color: inherit;
  }
}

.controlPills {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  gap: 0.5rem;
}

.controlPillsRow {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  gap: 0.625rem;

  > * {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
  }

  [data-prototype-target] {
    display: inline-flex;
    width: auto;
    max-width: none;
  }
}

.floatingBarControls {
  pointer-events: auto;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

// Portaled via @prototype/components/ui/tooltip (not clipped by morph overflow).
.toolbarTooltipContent {
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.01em;
  background: #1e1e1e;
  color: #e0e0e0;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.2),
    0 0 0 1px #333333;
}

// Dropdown triggers: pressed look only while the menu is open (not focus after Esc).
.toolbarMenuTrigger {
  &:focus:not(:focus-visible) {
    outline: none;
  }

  &:focus-visible:not([data-menu-open="true"]) {
    background: transparent;
  }
}

.morphToolbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  overflow: hidden;
  width: auto;
  min-width: 44px;
  height: 44px;
  border: none;
  background: #1e1e1e;
  color: var(--tool-chrome-icon, #888888);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.2),
    0 0 0 1px #333333;
  pointer-events: auto;
  user-select: none;
  transition:
    max-width $morph-duration $morph-ease,
    border-radius $morph-duration $morph-ease,
    padding $morph-duration $morph-ease,
    background-color 150ms ease;

  &.morphCollapsed {
    max-width: 44px;
    border-radius: 22px;
    padding: 0;
    cursor: pointer;
    outline: none;

    &:focus:not(:focus-visible) {
      outline: none;
    }

    &:focus-visible {
      outline: none;
      background: #252525;
    }

    @media (hover: hover) and (pointer: fine) {
      &:hover {
        background: #252525;
      }
    }

  }

  &.morphExpanded {
    max-width: 48rem;
    border-radius: 1.5rem;
    padding: 0.375rem;
    overflow: visible;
  }
}

.morphInner {
  display: flex;
  width: max-content;
  align-items: center;
  gap: 0.375rem;
}

.morphSection {
  display: grid;
  min-width: 0;
  // visibility is included so it stays visible through the close animation
  // (CSS makes visibility:hidden wait until the end, visibility:visible fires immediately on open).
  transition:
    grid-template-columns $morph-duration $morph-ease,
    opacity $morph-duration $morph-ease,
    visibility $morph-duration;

  &.sectionCollapsed {
    grid-template-columns: 0fr;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  &.sectionExpanded {
    grid-template-columns: 1fr;
    visibility: visible;
    overflow: visible;
  }
}

.morphSectionInner {
  display: flex;
  min-width: 0;
  overflow: hidden;
  align-items: center;
  gap: 0.375rem;
  white-space: nowrap;
}

.sectionExpanded .morphSectionInner {
  overflow: visible;
}

.morphCloseInner {
  justify-content: center;
  gap: 0.375rem;
}

.morphAnchor {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .morphToolbar,
  .morphSection {
    transition: none;
  }
}

.toolbarButtonHovered {
  background: #252525;
  color: var(--tool-chrome-icon-hover, #a3a3a3);
}

.panel {
  pointer-events: auto;
  width: 18rem;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.625rem 0.625rem;
  border-radius: 1rem;
  background: #1e1e1e;
  color: #e0e0e0;
  user-select: text;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.24),
    0 0 0 1px #333333;

  // Let nested prototype controls inherit a dark surface.
  --bg-main: #1e1e1e;
  --bg-top: #252525;
  --bg-subtle: #181818;
  --bg-layered: #252525;
  --text-primary: #e0e0e0;
  --text-secondary: #888888;
  --text-tertiary: #666666;
  --border-solid: #333333;
  --border-faint: #2a2a2a;
  --border-medium: #404040;
  --color-active: var(--prototype-comment-color-blue);
  --accent: var(--prototype-comment-color-blue);
  --accent-foreground: #fff;
}

.panelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.panelTitle {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: rgba(255, 255, 255, 0.92);
}

.panelHeaderActions {
  display: flex;
  align-items: center;
  gap: 0.125rem;
}

.panelContent {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panelSectionLabel {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.panelSection {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.panelTweakButton {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      background: rgba(255, 255, 255, 0.1);
      border-color: rgba(255, 255, 255, 0.16);
      color: #fff;
    }
  }
}

.panelTweakButtonIcon {
  color: var(--tool-chrome-icon, #888888);
}

.panelIconButton {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--tool-chrome-icon, #888888);
  cursor: pointer;
  outline: none;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;

  &:focus:not(:focus-visible) {
    outline: none;
  }

  &:focus-visible {
    outline: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--tool-chrome-icon-hover, #a3a3a3);
  }

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      background: rgba(255, 255, 255, 0.08);
      color: var(--tool-chrome-icon-hover, #a3a3a3);
    }
  }
}

// Light mode — keep in sync with capture-styles.module.scss [data-prototype-comment-theme="light"].
.root[data-prototype-comment-theme="light"],
.footerRoot[data-prototype-comment-theme="light"] {
  ::selection {
    background: rgba(0, 0, 0, 0.08);
    color: rgba(0, 0, 0, 0.92);
  }

  &.footerRoot {
    background: var(--tool-chrome-ground);
    --tool-chrome-icon: rgba(0, 0, 0, 0.45);
    --tool-chrome-icon-hover: rgba(0, 0, 0, 0.85);
  }

  .footerBar {
    background: var(--tool-chrome-ground);
  }

  .footerBrand {
    color: var(--tool-chrome-text-heading);

    @media (hover: hover) and (pointer: fine) {
      &:hover {
        background: var(--tool-chrome-gray-highlight);
        color: var(--tool-chrome-text-heading);
      }
    }
  }

  .footerTab {
    color: var(--tool-chrome-text);

    &:focus-visible {
      outline: 2px solid rgba(0, 0, 0, 0.2);
    }

    @media (hover: hover) and (pointer: fine) {
      &:hover:not(.footerTabActive) {
        background: var(--tool-chrome-gray-highlight);
        color: var(--tool-chrome-text-heading);
      }
    }
  }

  .footerTabActive {
    background: rgba(0, 0, 0, 0.08);
    color: var(--tool-chrome-text-heading);

    @media (hover: hover) and (pointer: fine) {
      &:hover {
        color: var(--tool-chrome-text-heading);
      }
    }
  }

  .footerTabBadge {
    background-color: rgba(0, 0, 0, 0.12);
    color: rgba(0, 0, 0, 0.72);
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.06),
      0 1px 2px rgba(0, 0, 0, 0.08);
  }

  .morphToolbar {
    background: #fff;
    color: rgba(0, 0, 0, 0.85);
    box-shadow:
      0 2px 8px rgba(0, 0, 0, 0.08),
      0 4px 16px rgba(0, 0, 0, 0.06),
      0 0 0 1px rgba(0, 0, 0, 0.04);

    &.morphCollapsed {
      &:focus-visible {
        background: #f5f5f5;
      }

      @media (hover: hover) and (pointer: fine) {
        &:hover {
          background: #f5f5f5;
        }
      }
    }
  }

  .toolbarButtonHovered {
    background: rgba(0, 0, 0, 0.06);
    color: rgba(0, 0, 0, 0.85);
  }

  .toolbarMenuTrigger {
    &:focus-visible:not([data-menu-open="true"]) {
      background: transparent;
      color: rgba(0, 0, 0, 0.5);
    }
  }

  .panel {
    background: #fff;
    color: rgba(0, 0, 0, 0.88);
    box-shadow:
      0 4px 20px rgba(0, 0, 0, 0.1),
      0 8px 32px rgba(0, 0, 0, 0.06),
      0 0 0 1px rgba(0, 0, 0, 0.04);

    --bg-main: #fff;
    --bg-top: #fafafa;
    --bg-subtle: #f5f5f5;
    --bg-layered: #f0f0f0;
    --text-primary: rgba(0, 0, 0, 0.92);
    --text-secondary: rgba(0, 0, 0, 0.68);
    --text-tertiary: rgba(0, 0, 0, 0.45);
    --border-solid: rgba(0, 0, 0, 0.1);
    --border-faint: rgba(0, 0, 0, 0.06);
    --border-medium: rgba(0, 0, 0, 0.16);
    --accent-foreground: rgba(0, 0, 0, 0.92);
  }

  .panelTitle {
    color: rgba(0, 0, 0, 0.92);
  }

  .panelSectionLabel {
    color: rgba(0, 0, 0, 0.45);
  }

  .panelTweakButton {
    border-color: rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.04);
    color: rgba(0, 0, 0, 0.88);

    @media (hover: hover) and (pointer: fine) {
      &:hover {
        background: rgba(0, 0, 0, 0.06);
        border-color: rgba(0, 0, 0, 0.14);
        color: rgba(0, 0, 0, 0.92);
      }
    }
  }

  .panelTweakButtonIcon {
    color: rgba(0, 0, 0, 0.45);
  }

  .panelIconButton {
    color: rgba(0, 0, 0, 0.55);

    &:focus-visible {
      background: rgba(0, 0, 0, 0.06);
      color: rgba(0, 0, 0, 0.92);
    }

    @media (hover: hover) and (pointer: fine) {
      &:hover {
        background: rgba(0, 0, 0, 0.06);
        color: rgba(0, 0, 0, 0.92);
      }
    }
  }
}

// Portaled into [data-prototype-root], not the footer chrome node.
:global([data-prototype-root][data-prototype-comment-theme="light"]) {
  .toolbarTooltipContent {
    background: #fff;
    color: rgba(0, 0, 0, 0.88);
    box-shadow:
      0 2px 8px rgba(0, 0, 0, 0.08),
      0 0 0 1px rgba(0, 0, 0, 0.1);
  }
}
