@use 'sass:color';

// Variables - More vibrant color palette
$bg-primary: #0f0f1a;
$bg-secondary: #1a1a2e;
$bg-tertiary: #252542;
$bg-darker: #0a0a12;
$text-primary: #ffffff;
$text-secondary: rgba(255, 255, 255, 0.8);
$text-tertiary: rgba(255, 255, 255, 0.5);
$accent-secondary: #ec4899;
$accent-tertiary: #06b6d4;
$border-color: rgba(255, 255, 255, 0.1);

// CSS variable for primary color from theme
:host {
  --accent-color: var(--primary-color, #8b5cf6);
  --accent-hover: var(--primary-hover-color, #a78bfa);
}

// Gradient mixins
@mixin gradient-bg {
  background: linear-gradient(135deg, $bg-secondary 0%, $bg-primary 50%, $bg-darker 100%);
}

@mixin accent-gradient {
  background: linear-gradient(135deg, var(--accent-color) 0%, $accent-secondary 100%);
}

@mixin glow-effect($color, $intensity: 0.4) {
  box-shadow: 0 0 40px rgba($color, $intensity),
              0 0 80px rgba($color, $intensity * 0.5);
}

// Loading container
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  @include gradient-bg;
  gap: 1rem;

  .loading-text {
    color: $text-secondary;
    font-size: 0.9rem;
  }

  ::ng-deep .p-progress-spinner-circle {
    stroke: var(--accent-color) !important;
  }
}

// Main container
.audiobook-player {
  display: flex;
  flex-direction: column;
  height: 100vh;
  @include gradient-bg;
  color: $text-primary;
  overflow: hidden;
  position: relative;

  // Subtle animated gradient overlay
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at 20% 0%, color-mix(in srgb, var(--accent-color) 15%, transparent) 0%, transparent 50%),
                radial-gradient(ellipse at 80% 100%, rgba($accent-secondary, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
  }
}

// Header
.reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid $border-color;
  z-index: 10;
  position: relative;

  .header-info {
    flex: 1;
    text-align: center;
    padding: 0 1rem;
    overflow: hidden;

    .book-title {
      font-size: 1.1rem;
      font-weight: 600;
      margin: 0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      background: linear-gradient(90deg, $text-primary, var(--accent-color));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }

    .book-author {
      font-size: 0.85rem;
      color: $text-secondary;
    }
  }

  .header-actions {
    display: flex;
    gap: 0.25rem;
  }

  ::ng-deep .p-button {
    &.p-button-text {
      color: $text-secondary;

      &:hover {
        color: $text-primary;
        background: color-mix(in srgb, var(--accent-color) 20%, transparent);
      }
    }
  }
}

// Main content
.reader-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1.5rem;
  overflow-y: auto;
  gap: 1.5rem;
  position: relative;
  z-index: 1;
}

// Cover art
.cover-container {
  flex-shrink: 0;
  width: 100%;
  max-width: min(480px, 40vh);
  aspect-ratio: 1;

  .cover-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 16px;
    overflow: hidden;
    box-shadow:
      0 25px 60px -12px rgba(0, 0, 0, 0.6),
      0 0 0 1px rgba(255, 255, 255, 0.1),
      0 0 60px color-mix(in srgb, var(--accent-color) 20%, transparent),
      0 0 100px rgba($accent-secondary, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;

    &:hover {
      transform: scale(1.02);
      box-shadow:
        0 30px 70px -12px rgba(0, 0, 0, 0.7),
        0 0 0 1px rgba(255, 255, 255, 0.15),
        0 0 80px color-mix(in srgb, var(--accent-color) 30%, transparent),
        0 0 120px rgba($accent-secondary, 0.15);
    }

    .cover-image {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .cover-loading {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(0, 0, 0, 0.7);
      backdrop-filter: blur(4px);
    }

    .cover-placeholder {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      @include accent-gradient;
      opacity: 0.8;

      i {
        font-size: 5rem;
        color: rgba(255, 255, 255, 0.9);
        text-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
      }
    }
  }
}

// Track info
.track-info {
  text-align: center;
  min-height: 3rem;

  .track-title {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    color: $text-primary;
    margin-bottom: 0.25rem;
  }

  .track-number {
    font-size: 0.85rem;
    color: var(--accent-color);
    font-weight: 500;
  }
}

// Progress bar
.progress-container {
  width: 100%;
  max-width: 500px;

  .time-display {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: $text-secondary;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
  }

  .progress-bar-wrapper {
    position: relative;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: visible;

    .buffered-bar {
      position: absolute;
      top: 0;
      left: 0;
      height: 100%;
      background: rgba(255, 255, 255, 0.15);
      border-radius: 4px;
      transition: width 0.3s ease;
    }

    ::ng-deep .progress-slider {
      position: absolute;
      top: 50%;
      left: 0;
      right: 0;
      transform: translateY(-50%);

      .p-slider {
        background: transparent;
        height: 8px;

        .p-slider-range {
          @include accent-gradient;
          border-radius: 4px;
          box-shadow: 0 0 10px color-mix(in srgb, var(--accent-color) 50%, transparent);
        }

        .p-slider-handle {
          width: 18px;
          height: 18px;
          background: $text-primary;
          border: 3px solid var(--accent-color);
          box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4),
                      0 0 15px color-mix(in srgb, var(--accent-color) 40%, transparent);
          transition: transform 0.15s ease, box-shadow 0.15s ease;

          &:hover {
            transform: scale(1.2);
            box-shadow: 0 2px 15px rgba(0, 0, 0, 0.5),
                        0 0 25px color-mix(in srgb, var(--accent-color) 60%, transparent);
          }
        }
      }
    }
  }
}

// Playback controls
.playback-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;

  ::ng-deep .play-button {
    .p-button {
      width: 72px;
      height: 72px;
      font-size: 1.75rem;
      @include accent-gradient;
      border: none;
      box-shadow: 0 8px 30px color-mix(in srgb, var(--accent-color) 40%, transparent),
                  0 0 50px color-mix(in srgb, var(--accent-color) 20%, transparent);
      transition: transform 0.2s ease, box-shadow 0.2s ease;

      &:hover {
        transform: scale(1.05);
        box-shadow: 0 10px 40px color-mix(in srgb, var(--accent-color) 50%, transparent),
                    0 0 70px color-mix(in srgb, var(--accent-color) 30%, transparent);
      }

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

      .p-button-icon {
        font-size: 1.75rem;
      }
    }
  }

  ::ng-deep .p-button {
    &.p-button-text {
      color: $text-secondary;
      transition: all 0.2s ease;

      &:hover {
        color: $text-primary;
        background: color-mix(in srgb, var(--accent-color) 20%, transparent);
        transform: scale(1.1);
      }

      &:disabled {
        color: $text-tertiary;
        opacity: 0.4;
        transform: none;
      }
    }

    &.p-button-lg {
      width: 48px;
      height: 48px;
    }
  }
}

// Secondary controls
.secondary-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  width: 100%;
  max-width: 500px;
  padding: 1rem 0;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;

  ::ng-deep .p-button.p-button-text {
    color: $text-secondary;

    &:hover {
      color: var(--accent-color);
      background: color-mix(in srgb, var(--accent-color) 15%, transparent);
    }
  }

  ::ng-deep .volume-slider {
    width: 100px;

    .p-slider {
      background: rgba(255, 255, 255, 0.15);
      height: 5px;
      border-radius: 3px;

      .p-slider-range {
        background: $accent-tertiary;
        border-radius: 3px;
      }

      .p-slider-handle {
        width: 14px;
        height: 14px;
        background: $text-primary;
        border: 2px solid $accent-tertiary;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
      }
    }
  }
}

.speed-control {
  ::ng-deep .p-selectbutton {
    .p-button {
      padding: 0.5rem 0.75rem;
      font-size: 0.8rem;
      font-weight: 600;
      background: rgba(255, 255, 255, 0.08);
      border: 1px solid rgba(255, 255, 255, 0.1);
      color: $text-secondary;
      transition: all 0.2s ease;

      &:hover {
        background: rgba(255, 255, 255, 0.12);
        color: $text-primary;
        border-color: rgba(255, 255, 255, 0.2);
      }

      &.p-highlight {
        @include accent-gradient;
        color: $text-primary;
        border-color: transparent;
        box-shadow: 0 4px 15px color-mix(in srgb, var(--accent-color) 30%, transparent);
      }
    }
  }
}

// Audio details
.audio-details {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 1rem;
  color: $text-tertiary;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  margin-top: 0.5rem;

  .detail-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    white-space: nowrap;

    i {
      font-size: 0.9rem;
      color: $accent-tertiary;
    }
  }
}

// Extra controls (bookmark, sleep timer)
.extra-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding-top: 0.5rem;

  ::ng-deep .p-button {
    &.p-button-text {
      color: $text-secondary;
      font-size: 0.85rem;

      &:hover {
        color: $text-primary;
        background: color-mix(in srgb, var(--accent-color) 15%, transparent);
      }

      .p-button-icon {
        font-size: 1rem;
      }
    }

    &.sleep-timer-active {
      color: #fbbf24 !important;

      &:hover {
        background: rgba(251, 191, 36, 0.15) !important;
      }
    }
  }
}

// Empty bookmarks
.empty-bookmarks {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  color: $text-tertiary;

  i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
  }

  p {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    color: $text-secondary;
  }

  span {
    font-size: 0.85rem;
  }
}

// Bookmark item
.bookmark-item {
  .bookmark-icon {
    color: var(--accent-color);
    font-size: 1.1rem;
    flex-shrink: 0;
  }

  ::ng-deep .p-button {
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  &:hover {
    ::ng-deep .p-button {
      opacity: 1;
    }
  }
}

// Track list sidebar
.track-list-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 400px;
  height: 100vh;
  background: linear-gradient(180deg, $bg-tertiary 0%, $bg-secondary 100%);
  border-left: 1px solid color-mix(in srgb, var(--accent-color) 20%, transparent);
  z-index: 100;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.25s ease-out;
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.5);

  @keyframes slideIn {
    from {
      transform: translateX(100%);
      opacity: 0.5;
    }
    to {
      transform: translateX(0);
      opacity: 1;
    }
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid $border-color;
    background: rgba(0, 0, 0, 0.2);

    h2 {
      margin: 0;
      font-size: 1.2rem;
      font-weight: 600;
      background: linear-gradient(90deg, $text-primary, var(--accent-color));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }

    ::ng-deep .p-button.p-button-text {
      color: $text-secondary;

      &:hover {
        color: $text-primary;
        background: color-mix(in srgb, var(--accent-color) 20%, transparent);
      }
    }
  }

  .sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;

    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: transparent;
    }

    &::-webkit-scrollbar-thumb {
      background: color-mix(in srgb, var(--accent-color) 30%, transparent);
      border-radius: 3px;

      &:hover {
        background: color-mix(in srgb, var(--accent-color) 50%, transparent);
      }
    }
  }
}

.track-list {
  list-style: none;
  margin: 0;
  padding: 0;

  .track-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 1rem;
    border-left: 3px solid transparent;

    &:hover {
      background: color-mix(in srgb, var(--accent-color) 10%, transparent);
      border-left-color: color-mix(in srgb, var(--accent-color) 50%, transparent);
    }

    &.active {
      background: linear-gradient(90deg, color-mix(in srgb, var(--accent-color) 20%, transparent) 0%, transparent 100%);
      border-left-color: var(--accent-color);

      .track-index {
        color: var(--accent-color);
        font-weight: 700;
      }

      .track-name {
        color: var(--accent-color);
      }
    }

    .track-index {
      width: 2rem;
      text-align: center;
      font-size: 0.9rem;
      color: $text-tertiary;
      flex-shrink: 0;
      font-weight: 600;
    }

    .track-details {
      flex: 1;
      min-width: 0;

      .track-name {
        display: block;
        font-size: 0.95rem;
        color: $text-primary;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-weight: 500;
      }

      .track-duration {
        font-size: 0.8rem;
        color: $text-tertiary;
        margin-top: 0.2rem;
      }
    }

    .playing-indicator {
      color: var(--accent-color);
      animation: pulse 1.5s ease-in-out infinite;
      font-size: 1.1rem;
    }

    @keyframes pulse {
      0%, 100% {
        opacity: 1;
        transform: scale(1);
      }
      50% {
        opacity: 0.6;
        transform: scale(0.95);
      }
    }
  }
}

// Responsive adjustments
@media (max-width: 768px) {
  .reader-main {
    padding: 1rem;
    gap: 1rem;
  }

  .cover-container {
    max-width: min(360px, 35vh);
  }

  .secondary-controls {
    flex-direction: column;
    gap: 1rem;
  }

  .volume-control {
    ::ng-deep .volume-slider {
      width: 150px;
    }
  }

  .track-list-sidebar {
    max-width: 75%;
  }

  .audio-details {
    gap: 0.75rem;
    padding: 0.75rem;

    .detail-item {
      padding: 0.4rem 0.6rem;
      font-size: 0.75rem;

      i {
        font-size: 0.8rem;
      }
    }
  }
}

@media (max-width: 480px) {
  .cover-container {
    max-width: min(300px, 30vh);
  }

  .playback-controls {
    gap: 0.5rem;

    ::ng-deep .play-button {
      .p-button {
        width: 64px;
        height: 64px;
      }
    }

    ::ng-deep .p-button.p-button-lg {
      width: 40px;
      height: 40px;
    }
  }

  .audio-details {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;

    .detail-item {
      flex: 0 1 auto;
    }
  }
}

// Landscape mode optimization
@media (max-height: 600px) and (orientation: landscape) {
  .reader-main {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
  }

  .cover-container {
    max-width: 180px;
  }

  .track-info,
  .progress-container,
  .playback-controls,
  .secondary-controls {
    width: auto;
  }

  .audio-details {
    flex-direction: row;
  }
}
