/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@namespace html url("http://www.w3.org/1999/xhtml");

/* Customization mode */

:root {
  --drag-drop-transition-duration: 0.3s;

  @media (prefers-reduced-motion: reduce) {
    --drag-drop-transition-duration: 0s;
  }
}

:root[customizing] .customization-target:not(#widget-overflow-fixed-list) {
  min-width: var(--size-layout-xsmall);
}

/* When customizing, overflowable toolbars move automatically moved items back
 * from the overflow menu, but we still don't want to render them outside of
 * the customization target. */
toolbar[overflowable][customizing] > .customization-target {
  overflow: clip;
}

#customization-container {
  flex-direction: column;
  min-height: 0;
  background-color: var(--toolbar-background-color);
  color: var(--toolbar-text-color);
  color-scheme: var(--toolbar-color-scheme);

  &:not([hidden]) {
    /* In a separate rule to avoid 'display:flex' causing the node to be
     * displayed while the container is still hidden. */
    display: flex;
  }
}

#customization-content-container {
  display: flex;
  flex: 1; /* Grow so there isn't empty space below the footer */
  min-height: 0; /* Allow this to shrink so the footer doesn't get pushed out. */
}

#customization-header {
  font-weight: var(--font-weight-heading);
  font-size: 1.2em;
  margin: 20px 20px 15px;
}

#customization-panel-container {
  --customization-panel-padding: 20px;

  overflow-y: auto;
  display: flex;
  flex-direction: column;
  flex: none;
  padding: 0 var(--customization-panel-padding) 25px;
}

#customization-footer-spacer,
#customization-spacer {
  flex: 1 1 auto;
}

#customization-footer {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
  border-top: 1px solid rgba(0, 0, 0, 0.15);
  padding: 10px;

  > .footer-button,
  > .customization-checkbox,
  > .customization-link {
    margin-block: 0;
  }
}

#customization-palette-container {
  display: flex;
  flex-direction: column;
  flex: 1;
}

#customization-palette {
  padding: 5px 20px 20px;
  transition: opacity 0.3s ease-in-out;
  opacity: 0;

  &:not([hidden]) {
    display: block;
    flex: 1 1 auto;
    overflow: auto;
    min-height: 3em;
    margin-bottom: 20px;
  }

  &[showing="true"] {
    opacity: 1;
  }

  .toolbarbutton-1 {
    appearance: none;
    flex-direction: column;
    padding: 12px 0 9px;
    margin: 0;

    :root[lwtheme-image] & {
      fill: currentColor;
    }

    > .toolbarbutton-badge-stack > .toolbarbutton-icon {
      width: var(--panel-and-palette-icon-size);
      height: var(--panel-and-palette-icon-size);
      min-width: var(--panel-and-palette-icon-size);
      min-height: var(--panel-and-palette-icon-size);
      padding: 0;
    }
  }
}

toolbarpaletteitem {
  -moz-window-dragging: no-drag;
  justify-content: flex-start;

  > toolbarbutton,
  > toolbaritem {
    /* Prevent children from getting events. */
    pointer-events: none;
    justify-content: center;
  }

  > toolbarspring {
    outline: 1px solid;
    opacity: 0.6;

    &[removable="false"] {
      outline: 1px dashed;
    }
  }

  toolbarbutton[disabled] {
    color: inherit !important;
  }

  &[removable="false"] {
    opacity: 0.5;
  }

  &[dragover] {
    border-inline-color: transparent;
  }

  &[place="palette"] {
    flex-direction: column;
    width: 7em;
    max-width: 7em;
    /* icon (16) + margin (9 + 12) + 3 lines of text: */
    height: calc(39px + 3em);
    margin-bottom: 5px;
    margin-inline-end: 24px;
    overflow: visible;
    display: inline-flex;
    vertical-align: top;

    &[hidden] {
      display: none;
    }

    &::after {
      content: attr(title);
      display: block;
      text-align: center;
    }

    /* Webextension buttons */
    > toolbarbutton[constrain-size="true"] > .toolbarbutton-icon,
    > toolbarbutton[constrain-size="true"] > .toolbarbutton-badge-stack > .toolbarbutton-icon {
      height: var(--panel-and-palette-icon-size);
      width: var(--panel-and-palette-icon-size);
    }

    > toolbarspring {
      outline-offset: -8px;
      max-height: 37px;
    }

    > #search-container {
      min-width: 7em;
      width: 7em;
      min-height: 37px;
      max-height: 37px;
    }
  }

  &[place="toolbar"] {
    /* Override the toolkit styling for items being dragged over. */
    border-inline-width: 0;
    margin-inline: 0;

    > toolbarspring {
      outline-offset: -2px;
      margin-block: 5px;
    }
  }

  &[place="panel"] {
    border-block: 0 solid transparent;

    > .toolbarbutton-1,
    > toolbaritem {
      flex: 1;
    }
  }

  &[place="palette"],
  &[place="panel"],
  &[place="toolbar"] {
    @media not (-moz-platform: macos) {
      -moz-user-focus: normal;
    }

    &:focus-visible {
      outline-width: 0;
    }

    &:not([mousedown]):focus-visible {
      /* Delay adding the focusring back until after the transform transition completes. */
      transition: outline-width 0.01s linear var(--drag-drop-transition-duration);
      outline: var(--default-focusring);

      &[place="toolbar"] {
        outline-offset: calc(-1 * var(--default-focusring-width) - 4px);
      }
    }
  }

  &:not([notransition]) {
    &[place="palette"] {
      transition: transform var(--drag-drop-transition-duration) ease-in-out;
    }

    &[place="panel"],
    &[place="toolbar"] {
      transition: border-width var(--drag-drop-transition-duration) ease-in-out;
    }
  }

  &:not([place="palette"]) > #stop-reload-button {
    justify-content: inherit;
  }

  #PersonalToolbar & toolbarbutton[checked],
  toolbar & toolbarbutton[checked] > :where(.toolbarbutton-icon, .toolbarbutton-text, .toolbarbutton-badge-stack) {
    background-color: revert !important;
  }

  > toolbarbutton > .toolbarbutton-icon,
  > toolbarbutton > .toolbarbutton-badge-stack > .toolbarbutton-icon,
  > #search-container,
  > toolbaritem.toolbaritem-combined-buttons {
    transition: transform var(--drag-drop-transition-duration) cubic-bezier(0.6, 2, 0.75, 1.5) !important;
  }

  &[mousedown] {
    cursor: -moz-grabbing;

    > toolbarbutton > .toolbarbutton-icon,
    > toolbarbutton > .toolbarbutton-badge-stack > .toolbarbutton-icon {
      transform: scale(1.3);
    }

    > #search-container,
    > toolbaritem.toolbaritem-combined-buttons {
      transform: scale(1.1);
    }

    > #search-container > #searchbar,
    .urlbar-background {
      outline: 1px solid color-mix(in srgb, currentColor 60%, transparent);
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.13);
    }
  }

  > #search-container > #searchbar > .searchbar-textbox {
    /* Hide searchbar placeholder text in customize mode. */
    visibility: hidden;
  }
}

#wrapper-edit-controls > #edit-controls > toolbarbutton > .toolbarbutton-icon {
  opacity: 1; /* To ensure these buttons always look enabled in customize mode */
}

#wrapper-zoom-controls[place="palette"] > #zoom-controls > #zoom-reset-button,
#wrapper-zoom-controls[place="palette"] > #zoom-controls > #zoom-reset-button + separator {
  display: none;
}

/* Squeeze together the multi-button toolbarpaletteitems: */
#wrapper-zoom-controls[place="palette"] > #zoom-controls > #zoom-out-button,
#wrapper-edit-controls[place="palette"] > #edit-controls > #cut-button,
#wrapper-profiler-button[place="palette"] > #profiler-button > #profiler-button-button {
  align-items: flex-end;
}
#wrapper-zoom-controls[place="palette"] > #zoom-controls > #zoom-in-button,
#wrapper-edit-controls[place="palette"] > #edit-controls > #paste-button,
#wrapper-profiler-button[place="palette"] > #profiler-button > #profiler-button-dropmarker {
  align-items: flex-start;
}
#wrapper-edit-controls[place="palette"] > #edit-controls > #copy-button {
  flex: none;
}

#customization-uidensity-touch-spacer {
  border-top: 1px solid var(--panel-separator-color);
  margin: 6px calc(-1 * var(--panel-padding)) 9px;
}

#customization-uidensity-autotouchmode-checkbox {
  margin-bottom: var(--panel-padding);
}

#customization-uidensity-menu {
  font: menu;

  /* Make the panel padding uniform across all platforms due to the
     styling of the section headers and footer. */
  --panel-padding: 8px;
}

.customization-uidensity-menuitem {
  appearance: none;
  color: inherit;
  border: 1px solid transparent;
  border-radius: var(--border-radius-small);
  padding-block: 0;
  padding-inline: 0 5px;
  margin: 2px 0;

  > .menu-icon {
    width: 32px;
    height: 32px;
    margin: 5px;

    &:-moz-locale-dir(rtl) {
      transform: scaleX(-1);
    }
  }

  > .menu-text {
    text-align: start;
  }

  &:hover,
  &:focus-visible {
    background-color: var(--button-background-color-hover);
  }

  &:hover:active,
  &[active="true"] {
    background-color: var(--button-background-color-active);
  }
}

#customization-uidensity-menuitem-normal {
  --menuitem-icon: url("chrome://browser/skin/customizableui/density-normal.svg");
}

#customization-uidensity-menuitem-compact {
  --menuitem-icon: url("chrome://browser/skin/customizableui/density-compact.svg");
}

#customization-uidensity-menuitem-touch {
  --menuitem-icon: url("chrome://browser/skin/customizableui/density-touch.svg");
}

#customization-uidensity-button > .box-inherit > .box-inherit > .button-icon:-moz-locale-dir(rtl) {
  transform: scaleX(-1);
}

#customization-panelWrapper,
#customization-panelWrapper > .panel-arrowcontent,
#customization-panelHolder {
  flex-direction: column;
  display: flex;
  flex-shrink: 1;
  min-height: calc(174px + 9em);
}

#customization-panelWrapper {
  flex: 1;
  align-items: end; /* align to the end on the cross-axis (affects arrow) */

  > .panel-arrowcontent {
    color: var(--panel-text-color);
    background: var(--panel-background-color);
    background-clip: padding-box;
    max-width: 29em;

    @media (-moz-platform: macos) {
      /* Native styling adds more 'oompf' to the popup box-shadow, so simulate that
       * as best as we can here: */
      box-shadow:
        0 0 1px hsla(0, 0%, 0%, 0.3),
        0 4px 10px hsla(0, 0%, 0%, 0.3);
      appearance: none;
      border-radius: var(--panel-border-radius);
    }

    @media not (-moz-platform: macos) {
      border: 1px solid var(--panel-border-color);
      margin: 0;
      box-shadow: 0 0 4px hsla(0, 0%, 0%, 0.2);
    }
  }
}

#customization-panelWrapper > .panel-arrowbox {
  display: block;
  position: relative;
  height: 10px;
  margin-bottom: -1px;

  > .panel-arrow[side="top"] {
    list-style-image: url("chrome://global/skin/arrow/panelarrow-vertical.svg");
    -moz-context-properties: fill, stroke;
    fill: var(--panel-background-color);
    stroke: var(--panel-border-color);
    /* JS code sets --panel-arrow-offset to the distance between the middle of the
     * overflow button and the end of the window. We subtract the padding of our
     * container (#customization-panel-container) and half our own width:
     */
    margin-inline-end: calc(var(--panel-arrow-offset) - var(--customization-panel-padding) - 10px);
    vertical-align: top;

    @media (-moz-platform: macos) {
      /* The OS X image is 2px narrower than the windows/linux one.
       * Add padding to compensate: */
      padding: 0 1px;
      /* specify width for hidpi image to fit correctly */
      width: 20px;
    }
  }
}

#customization-panelDescription {
  font-size: 1.1em;
  padding: 2px 12px 10px;
  margin: 0;
}

#customization-panelHeader {
  font-size: 1.3em;
  font-weight: var(--font-weight-heading);
  padding: 2px 12px;
  margin: 0;
}

#customization-panelHolder {
  padding-block: 10px;

  > #widget-overflow-fixed-list {
    flex: 1; /* Grow within the available space, and allow ourselves to shrink */
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: 10px;

    /**
     * We create a ::before pseudoelement that contains a background image to show the
     * drop dragon. This element fades in and out depending on whether the containing
     * panel list is empty and unhovered, or not.
     */
    &:not(:empty) {
      padding-bottom: 50px; /* Make sure there's always space to drop stuff. */
      border-top: 1px solid var(--panel-separator-color);
    }

    &::before {
      display: block;
      content: "";
      background-image: image-set(
        url("chrome://browser/skin/customizableui/empty-overflow-panel.png"),
        url("chrome://browser/skin/customizableui/empty-overflow-panel@2x.png") 2x
      );
      background-position: center bottom 10px;
      background-size: 218px 134px;
      background-repeat: no-repeat;
      opacity: 0;
      transition: opacity 300ms ease-out;
      padding-bottom: 154px; /* 154 = 134 for the image, 10px space on either side. */
      margin-bottom: -154px; /* don't affect positioning of the actual contents */
      pointer-events: none;
    }

    &:empty::before {
      opacity: 1;
    }
    &[draggingover]:empty::before {
      opacity: 0;
    }
  }
}

#downloads-button-autohide-panel {
  --panel-padding: 5px 12px;
}

#downloads-button-autohide-checkbox {
  margin: 0;
  padding: 0;
}

#whimsy-button {
  /* Don't need HiDPI versions since the size used will be scaled down to 20x20. */
  list-style-image: url("chrome://browser/skin/customizableui/whimsy.png");
}

#whimsy-button > .button-box > .button-icon {
  width: 16px;
  height: 16px;
}

#customization-palette[whimsypong] {
  /* Keep the palette in the render tree but invisible
     so -moz-element() will work. */
  padding: 0;
  min-height: 0;
  max-height: 0;

  > toolbarpaletteitem > toolbarspring {
    margin: 0 -7px;
  }

  @media (-moz-platform: linux) {
    > toolbarpaletteitem[id^="wrapper-customizableui-special-spring"] {
      font-size: 12px;
    }
  }
}

#wp-lives,
#wp-ball {
  /* Don't need HiDPI versions since the size used will be scaled down to 20x20. */
  background-image: url("chrome://browser/skin/customizableui/whimsy.png");
  background-size: contain;
  width: 20px;
}

#customization-pong-arena {
  width: 300px;
  height: 300px;
  border-inline: 1px solid currentColor;
  margin: 16px auto 0;
  box-sizing: content-box;
}

#customization-palette[whimsypong] > toolbarpaletteitem[kcode],
#customization-pong-arena[kcode] {
  animation-name: kcode;
  animation-timing-function: steps(5);
  animation-duration: 1s;
  animation-iteration-count: infinite;
}

#wp-ball {
  margin-inline-start: -10px;
  margin-top: -10px;
  height: 20px;
}

#wp-player1,
#wp-player2 {
  width: 84px;
  height: calc(39px + 3em);
}

#wp-player1,
#wp-player2,
#wp-ball,
#wp-score {
  display: block;
  position: fixed;
}

#wp-score {
  transform: translateX(-4ch);

  &:-moz-locale-dir(rtl) {
    transform: translateX(4ch);
  }
}

#wp-lives {
  transform: translate(-4ch, 1ch);

  &:-moz-locale-dir(rtl) {
    transform: translate(4ch, 1ch);
  }

  &[lives="5"] {
    height: 100px;
  }

  &[lives="4"] {
    height: 80px;
  }

  &[lives="3"] {
    height: 60px;
  }

  &[lives="2"] {
    height: 40px;
  }

  &[lives="1"] {
    height: 20px;
  }
}

#customization-pong-arena[lives="0"] > #wp-ball {
  animation: game-over 4s forwards ease;
}

@keyframes game-over {
  0% {
    transform: scale(1) translateY(0) rotateZ(0);
    opacity: 1;
  }
  15% {
    transform: scale(2) translateY(-10px) rotateZ(-90deg);
  }
  35% {
    opacity: 1;
  }
  65% {
    opacity: 0;
  }
  100% {
    transform: scale(2) translateY(300px) rotateZ(-2.5turn);
    opacity: 0;
  }
}

@keyframes kcode {
  0% {
    border-color: rgb(195, 17, 206);
    color: rgb(195, 17, 206);
  }
  20% {
    border-color: rgb(252, 82, 27);
    color: rgb(252, 82, 27);
  }
  40% {
    border-color: rgb(251, 179, 0);
    color: rgb(251, 179, 0);
  }
  60% {
    border-color: rgb(105, 211, 0);
    color: rgb(105, 211, 0);
  }
  80% {
    border-color: rgb(20, 155, 249);
    color: rgb(20, 155, 249);
  }
  100% {
    border-color: rgb(195, 17, 206);
    color: rgb(195, 17, 206);
  }
}
