
.date-picker {
  display: flex;
  flex-direction: column;

  position: relative;
}

.date-picker-container {
  position: relative;
  /* needed for absolute indicator */
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  max-width: 50rem;
  align-self: center;

  background-color: var(--background-color-secondary);
  border-radius: 999px;
  overflow: hidden;
  padding: 0.5rem 0.75rem;

  margin-top: 2rem;

  cursor: pointer;
  user-select: none;

  opacity: 0; /* Hidden until JS populates dates */
  transition: opacity 0.4s ease;

  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.3),
    inset -1px -1px rgba(255, 255, 255, 0.1),
    var(--shadow);
}

@media (max-width: 600px) {
  .date-picker-container {
    max-width: 90%;
  }
}

.date-indicator {
  position: absolute;
  opacity: 0; /* Hidden until JS positions it */

  background: rgba(218, 218, 218, 0.821);
  border-radius: 999px;

  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.3),
    inset -1px -1px rgba(255, 255, 255, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.12),
    0 0 0 0.5px rgba(0, 0, 0, 0.04);

  will-change: transform, width;
  transition:
    transform 0.3s cubic-bezier(0.34, 1.32, 0.64, 1),
    width 0.3s cubic-bezier(0.34, 1.12, 0.64, 1);

  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .date-indicator {
    background: #5e5e5e70;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
}

@keyframes date-indicator-shake {
  0% {
    transform: translateX(var(--indicator-x)) rotate(0deg);
  }

  20% {
    transform: translateX(calc(var(--indicator-x) - 6px)) rotate(-4deg);
  }

  40% {
    transform: translateX(calc(var(--indicator-x) + 6px)) rotate(4deg);
  }

  60% {
    transform: translateX(calc(var(--indicator-x) - 4px)) rotate(-2deg);
  }

  80% {
    transform: translateX(calc(var(--indicator-x) + 4px)) rotate(2deg);
  }

  100% {
    transform: translateX(var(--indicator-x)) rotate(0deg);
  }
}

.date-indicator.shake {
  animation: date-indicator-shake 0.4s cubic-bezier(.2, .8, .2, 1) forwards;
}

#today-indicator {
  position: absolute;
  transform: translateX(-50%);

  background: var(--text-color-accent);
  color: white;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--text-color-accent) 40%, transparent);
  transform-origin: bottom center;

  opacity: 0;
  /* hidden before animation fires */
  animation: today-indicator-appear 0.65s linear 0.15s forwards;
  animation-delay: 0.35s;

  will-change: transform scale;
  transition: scale 0.15s ease, background-color 0.2s ease;

  &::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--text-color-accent);
  }

  &.hidden {
    display: none;
  }

  &:hover {
    scale: 1.05;
    background: color-mix(in srgb, var(--text-color-accent) 85%, black);
  }
}

@media (prefers-color-scheme: dark) {
  #today-indicator {
    /* Use a slightly darker/more saturated green for better white text contrast on dark background */
    background: #28a745;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.4);
  }
  #today-indicator::after {
    border-top-color: #28a745;
  }
  #today-indicator:hover {
    background: #218838;
  }
}

@keyframes today-indicator-appear {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(82px) scale(0, 0);
    filter: blur(16px);
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }

  25% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(0.25, 0.85);
    filter: blur(2px);
    animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  75% {
    transform: translateX(-50%) translateY(0) scale(1.08, 1.06);
    filter: blur(0);
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }

  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1, 1);
    filter: blur(0);
  }
}

.date-element-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  aspect-ratio: 1;
  width: 2.5rem;

  padding: 0.4rem;

  z-index: 1;
  /* sit above the indicator */

  will-change: color;
  transition: color 0.2s ease;

  -webkit-tap-highlight-color: transparent;
}

.date-element-container.date-skipped {
  cursor: not-allowed;
}

.date-picker--hide-sundays .date-element-container:has(.date-sunday) {
  display: none;
}

.date-element-container.active .date-day-of-week,
.date-element-container.active .date-number {
  color: var(--text-color-accent);
  font-weight: bold;
}

.date-day-of-week {
  font-weight: bold;
  color: var(--text-color-primary);
}

.date-sunday {
  color: #e53935;
}

@media (prefers-color-scheme: dark) {
  .date-sunday {
    color: #cc3535;
  }
}

.date-number {
  color: var(--text-color-secondary);
  opacity: 0.5;
}