.popup {
  font-family: var(--font-family--sans-serif);
  min-height: var(--height--body);
  max-width: var(--width--body);
  min-width: var(--width--body);
  user-select: none;
  padding: 0 4px;
  background: var(--color--chrome-bg);

  div.popup-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    height: 100%;
    width: 100%;
    gap: 2px;
    padding: 0 2px;
  }


  .container {
    display: flex;
    align-items: center;
    height: 100%;
  }

  #paletteContainer {
    flex: 1;
    height: 100%;
    transition: all 0.2s ease;
    overflow: hidden;
    display: flex;
    gap: 2px;
    position: relative;
  }

  .divider {
    width: 1px;
    height: 32px;
    margin: 0 2px;
    background: rgba(0,0,0,0.1);
  }

  .spacebar-hint {
    position: absolute;
    right: 1px;
    bottom: 0;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: rgba(0, 0, 0, 0.6);
    pointer-events: none;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0;
  }

  #marquee {
    position: relative;
    display: flex;
    align-items: center;
    height: 100%;
    min-width: var(--width--marquee);
    max-width: var(--width--marquee);

    .notification {
      height: 100%;
      width: var(--width--marquee);
      position: absolute;
      display: flex;
      align-items: center;
      top: 0;
      left: 0;
      background: var(--color--chrome-bg);
      color: #000;
      animation: marqueeSlideIn 2s ease forwards, notificationGlow 0.4s ease-out;
      padding-left: 2px;
      font-weight: 800;
      font-size: 13px;
      letter-spacing: -1px;
    }
  }

  .logo {
    font-family: var(--font-family--display);
    font-weight: 900;
    font-size: 28px;
    letter-spacing: -2px;
    padding: 0 4px;
    color: #000;
    cursor: pointer;
    text-decoration: underline;
  }

  .palette {
    flex: 1;
    position: relative;
    height: var(--height--keys);
    padding: 3px calc(var(--height--body) * sin(var(--rotation--swatches)));
    display: flex;
    align-items: center;
    flex-direction: row;
    overflow: hidden;
    gap: 3px;
    background: var(--background--07-mac);
    box-shadow: var(--box-shadow--07-mac);
    border: var(--border--07-mac);
    border-radius: var(--border-radius--keyboard);
    /* animation: spacebarPulse 1s ease-in-out infinite; */

    &::before {
      content: attr(data-key-left); 
      position: absolute;
      top: 1px; 
      left: 1px;
      text-transform: uppercase;
      transform: translateX(50%);
      font-size: 8px;
      font-weight: 800;
      color: rgba(0,0,0,0.6);
    }

    &::after {
      content: attr(data-key-right); 
      position: absolute;
      top: 1px; 
      right: 1px;
      text-transform: uppercase;
      transform: translateX(-50%);
      font-size: 8px;
      font-weight: 800;
      color: rgba(0,0,0,0.6);
    }

    &.flash-hover {
      transform: scale(0.98);
    }
  
    .swatch {
      rotate: var(--rotation--swatches);
      height: 26px;
      width: 26px;
      border-radius: var(--border-radius--swatch);
      transition: all 0.2s ease;
      background: transparent;
      border: var(--border--swatch);
      cursor: grab;
      z-index: 1000;

      &:nth-child(1) {
        rotate: calc(var(--rotation--swatches) + 0deg);
      }

      &:nth-child(2) {
        rotate: calc(var(--rotation--swatches) + 20deg);
      }

      &:nth-child(3) {
        rotate: calc(var(--rotation--swatches) + 10deg);
      }

      &:nth-child(4) {
        rotate: calc(var(--rotation--swatches) + 40deg);
      }

      &:nth-child(5) {
        rotate: calc(var(--rotation--swatches) + 30deg);
      }

      &:nth-child(6) {
        rotate: calc(var(--rotation--swatches) + 60deg);
      }

      &:nth-child(7) {
        rotate: calc(var(--rotation--swatches) + 50deg);
      }

      &.checkered {
        background-color: transparent !important;
        background-image: linear-gradient(45deg, rgba(0,0,0,0.2) 25%, transparent 25%), 
                          linear-gradient(-45deg, rgba(0,0,0,0.2) 25%, transparent 25%), 
                          linear-gradient(45deg, transparent 75%, rgba(0,0,0,0.2) 75%), 
                          linear-gradient(-45deg, transparent 75%, rgba(0,0,0,0.2) 75%);
        background-size: 8px 8px;
        background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
      }
      
      &:hover {
        transform: scale(1.05);
        box-shadow: 0 2px 8px rgba(0,0,0,0.25);
      }
      
      &.selected {
        transform: scale(1.25);
        box-shadow: 0 0 2px 2px rgba(0,0,0,0.25);
        z-index: 10;
      }

      &.copying {
        animation: copyPulse 0.3s ease-out;
      }
    }
  }

  /* Saved palettes */
  .saved-palettes-panel {
    width: 100%;
    background: var(--color--chrome-bg);
    margin-top: 2px;
    padding: 10px 0;
    border-top: dotted 1px var(--color--chrome-border);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .saved-palettes-header {
    position: relative;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.5px;
    text-align: center;
    margin-bottom: 6px;
  }

  .saved-palettes-list {
    display: flex;
    width: 100%;
    flex-direction: column;
    border: var(--border--07-mac);
    border-radius: var(--border-radius--keyboard);
    overflow: hidden;
    box-shadow: var(--box-shadow--07-mac);
  }

  .saved-palette-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 2px 8px;
    background: var(--background--07-mac);
  }

  .saved-palette-name-input {
    width: 110px;
    padding: 4px 6px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.5px;
    border: none;
    background: transparent;
    outline: none;
    color: #333;
    cursor: text;
    border-radius: 4px;

    &:hover {
      background: rgba(255, 255, 255, 0.5);
    }

    &:focus {
      background: rgba(255, 255, 255, 0.5);
    }
  }

  .saved-palette {
    width: 250px;
    display: flex;
    gap: 4px;
    padding: 4px 6px 4px 24px;
    cursor: pointer;
    position: relative;

    &:hover .saved-palette-arrow {
      opacity: 1;
      transform: translateY(-50%);
    }
  }

  .saved-palette-arrow {
    position: absolute;
    top: 50%;
    left: 0px;
    transform: translateY(-25%);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
  }

  .saved-palette-color-dot {
    width: 26px;
    height: 26px;
    border-radius: var(--border-radius--swatch);
    transition: transform 0.2s ease;
    border: var(--border--swatch);

    &:nth-child(1) {
      rotate: calc(var(--rotation--swatches) + 0deg);
    }

    &:nth-child(2) {
      rotate: calc(var(--rotation--swatches) + 20deg);
    }

    &:nth-child(3) {
      rotate: calc(var(--rotation--swatches) + 10deg);
    }

    &:nth-child(4) {
      rotate: calc(var(--rotation--swatches) + 40deg);
    }

    &:nth-child(5) {
      rotate: calc(var(--rotation--swatches) + 30deg);
    }

    &:nth-child(6) {
      rotate: calc(var(--rotation--swatches) + 60deg);
    }

    &:nth-child(7) {
      rotate: calc(var(--rotation--swatches) + 50deg);
    }
  }

  .saved-palette-actions {
    margin-left: auto;
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: center;

    button {
      width: 24px;
      height: 24px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s ease;

      &:hover {
        transform: scale(1.1);
      }
    }
  }

  #toggleSavedPalettesBtn {
    height: var(--height--keys);
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;

    &:hover {
      transform: scale(1.4);
    }

    &.disabled {
      opacity: 0.3;
      cursor: not-allowed;
    }

    &.disabled:hover {
      transform: none;
      box-shadow: none;
    }

    &.active {
      transform: rotate(180deg);
      transition: transform 0.3s ease;
    }
    
    svg {
      transition: transform 0.3s ease;
    }
  }
}

button {
  outline: none;
}

.btn-format {
  height: var(--height--keys);  
  width: 54px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.5px;
  position: relative;
  transition: all 0.1s;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
  text-transform: lowercase;
  background: var(--background--07-mac);
  box-shadow: var(--box-shadow--07-mac);
  border: var(--border--07-mac);
  border-radius: var(--border-radius--keyboard);

  .btn-format-label {
    transition: all 0.1s ease;
  }

  &::before {
    content: '';
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    height: 6px;
    width: 50%;
    background: var(--current-color);
    border-radius: var(--border-radius--rounded);
    border: solid 1px rgba(0, 0, 0, 0.2);
  }
}

.btn-semicolon {
  aspect-ratio: 1/1;
  height: var(--height--keys);
  width: var(--height--keys);
  font-size: 16px;
  font-weight: 900;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  color: rgba(0, 0, 0, 0.7);
  background: var(--background--07-mac);
  box-shadow: var(--box-shadow--07-mac);
  border: var(--border--07-mac);
  border-radius: var(--border-radius--keyboard);

  span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  &::before {
    content: '';
    position: absolute;
    width: 4px;
    height: 200%;
    background: red;
    transform: rotate(-45deg) translateX(50%);
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
  }

  &.selected {
    &::before {
      display: none;
    }
  }
}

.btn-remove-swatch {
  aspect-ratio: 1/1;
  height: var(--height--keys);
  width: var(--height--keys);
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  color: rgba(0, 0, 0, 0.7);
  background: var(--background--07-mac);
  box-shadow: var(--box-shadow--07-mac);
  border: var(--border--07-mac);
  border-radius: var(--border-radius--keyboard);

  span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin-top: -2px;
  }
}

.btn-key {
  padding-top: 7px;
  
  &::after {
    content: attr(data-key); 
    position: absolute;
    top: 1px; 
    right: 1px;
    text-transform: uppercase;
    transform: translateX(-50%);
    font-size: 8px;
    font-weight: 800;
    color: rgba(0, 0, 0, 0.6);
  }

  &:hover {
    transform: scale(0.96);
  }

  &:active {
    transform: scale(0.9);
  }
}

.btn-icon {
  height: var(--height--keys);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  background: #444;
  color: white;
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.5),
              inset 0 -1px 0 0 rgba(0, 0, 0, 0.1),
              inset 1px 0 0 0 rgba(255, 255, 255, 0.2),
              inset -1px 0 0 0 rgba(0, 0, 0, 0.08),
              0 1px 2px rgba(0, 0, 0, 0.15);
  border: var(--border--07-mac);
  border-radius: var(--border-radius--rounded);

  &:hover {
    transform: scale(1.04);
  }

  &:active {
    transform: scale(0.9);
  }

  &.disabled {
    opacity: 0.3;
    cursor: not-allowed;
  }

  &.disabled:hover {
    transform: none;
    box-shadow: none;
  }
}

.flash-hover {
  transform: scale(0.9);
  transition: transform 0.2s ease;
}

@keyframes marqueeSlideIn {
  0% {
    transform: translateY(100%);
    opacity: 0;
  }
  10% {
    transform: translateY(0);
    opacity: 1;
  }
  95% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    transform: translateY(-20%);
    opacity: 0;
    display: none;
  }
}

@keyframes copyPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(255, 255, 0, 0);
  }
  50% {
    transform: scale(1.4);
    box-shadow: 0 0 20px 4px rgba(255, 255, 0, 0.8);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(255, 255, 0, 0);
  }
}

@keyframes notificationGlow {
  0% {
    text-shadow: 0 0 0 rgba(255, 255, 0, 0);
  }
  50% {
    transform: scale(1.1);
    text-shadow: 0 0 10px rgba(255, 255, 0, 0.8), 0 0 20px rgba(255, 255, 0, 0.6);
  }
  100% {
    text-shadow: 0 0 0 rgba(255, 255, 0, 0);
  }
}

@keyframes spacebarPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.98);
  }
}