/* ==========================================================================
   Media downloaders — shared stylesheet
   Loaded by the TikTok, TikTok Story and Instagram downloaders.

   One file rather than three near-identical ones: they share the hero, the
   input field, the disclosure notice and the result card. Only the slideshow
   grid is specific to the story downloader.
   ========================================================================== */

/* ------------------------------------------------------------------- hero */

.tool-hero {
  text-align: center;
  padding-block: var(--space-7) var(--space-4);
  max-width: 46rem;
  margin-inline: auto;
}

.tool-hero h1 {
  margin-bottom: var(--space-3);
  font-size: clamp(2rem, 1.4rem + 2.4vw, 2.75rem);
}

.tool-hero__sub {
  margin: 0;
  font-size: var(--text-lg);
  color: var(--fg-muted);
}

/* ------------------------------------------------------------------ input */

.tt {
  max-width: 720px;
  margin: 0 auto var(--space-8);
}

.tt__form {
  margin: 0;
}

.tt__field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.tt__field:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ring) 18%, transparent);
}

.tt__field>svg {
  flex: 0 0 auto;
  color: var(--fg-subtle);
}

.tt__input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: var(--text-base);
  outline: none;
}

.tt__input::placeholder {
  color: var(--fg-subtle);
}

.tt__submit {
  flex: 0 0 auto;
  min-height: 48px;
  border-radius: var(--radius-pill);
  padding-inline: var(--space-5);
}

.tt__hint {
  margin: var(--space-3) 0 0;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

.tt__hint code {
  font-family: var(--font-mono);
  font-size: 0.95em;
  color: var(--fg-subtle);
}

/* Disclosure notice — neutral, not the green privacy styling used elsewhere. */
.tt__notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin: var(--space-5) 0 0;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

.tt__notice svg {
  flex: 0 0 auto;
  margin-top: 2px;
  color: var(--fg-subtle);
}

.tt__notice strong {
  color: var(--fg);
}

.tt__status {
  min-height: 22px;
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--fg-muted);
  text-align: center;
}

/* ----------------------------------------------------------------- result */

.tt-result {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
  margin-top: var(--space-5);
  padding: var(--space-5);
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  animation: tt-in var(--dur-slow) var(--ease);
}

.tt-result[hidden] {
  display: none;
}

@keyframes tt-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tt-result {
    animation: none;
  }
}

@media (min-width: 620px) {
  .tt-result {
    grid-template-columns: 220px minmax(0, 1fr);
  }
}

/* Photo stories show every frame in the grid below, so the cover column
   would only repeat slide one. */
.tt-result--no-cover {
  grid-template-columns: 1fr;
}

.tt-result--no-cover .tt-result__cover {
  display: none;
}

@media (min-width: 620px) {
  .tt-result--no-cover {
    grid-template-columns: 1fr;
  }
}

.tt-result__cover {
  /* Reserved box so the card does not jump when the cover finishes loading. */
  aspect-ratio: 9 / 16;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
}

.tt-result__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tt-result__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.tt-result__author {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.tt-result__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  flex: 0 0 auto;
}

.tt-result__name {
  margin: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tt-result__handle {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

.tt-result__title {
  margin: 0;
  color: var(--fg-muted);
  font-size: var(--text-sm);
  line-height: 1.6;
  /* Long captions are clipped rather than allowed to dominate the card. */
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tt-result__stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

.tt-result__stats li {
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

.tt-result__stats b {
  display: block;
  font-size: var(--text-lg);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.tt-result__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: auto;
}

.tt-result__actions .btn {
  flex: 1 1 auto;
  justify-content: center;
}

.tt-result__actions .btn[hidden] {
  display: none;
}

.tt-result__legal {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--fg-subtle);
}

/* --------------------------------------- resolution list (X downloader) */

.quality-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.quality-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 52px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.quality-btn:hover {
  border-color: var(--primary);
  background: var(--surface-2);
  color: var(--fg);
}

/* The first entry is the highest rendition, so it carries the primary weight. */
.quality-btn--best {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--fg-on-primary);
  font-weight: 700;
}

.quality-btn--best:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--fg-on-primary);
}

.quality-btn__label {
  font-weight: 700;
}

.quality-btn__meta {
  margin-inline-start: auto;
  font-size: var(--text-xs);
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ------------------------------------------------- audio preview (X→MP3) */

.audio-preview {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.audio-preview[hidden] {
  display: none;
}

.audio-preview audio {
  width: 100%;
  /* Reserved height so the card does not jump when the player appears. */
  min-height: 44px;
}

.audio-preview__meta {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------- slideshow (story tool) */

.story-panel {
  margin-top: var(--space-5);
}

.story-panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.story-panel__head h2 {
  margin: 0 0 2px;
  font-size: var(--text-lg);
}

.story-panel__head p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

.story-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.story-tile {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-2);
  /* Reserved box: frames load asynchronously and must not shift the grid. */
  aspect-ratio: 9 / 16;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur) var(--ease);
}

.story-tile:hover {
  box-shadow: var(--shadow-md);
}

.story-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.story-tile__index {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: rgba(6, 11, 22, 0.72);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Play badge marks a video frame in a mixed story reel. */
.story-tile__badge {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(6, 11, 22, 0.72);
  color: #fff;
}

/* Shown when a video frame has no still image to preview. */
.story-tile__placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: var(--space-2);
  background: var(--surface-2);
  color: var(--fg-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: center;
}

.story-tile__save {
  position: absolute;
  right: var(--space-2);
  bottom: var(--space-2);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: #0b1220;
  cursor: pointer;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease),
    background-color var(--dur) var(--ease);
}

.story-tile:hover .story-tile__save,
.story-tile:focus-within .story-tile__save {
  opacity: 1;
  transform: none;
}

.story-tile__save:hover {
  background: #fff;
}

.story-tile__save:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* Touch has no hover — keep the save control permanently visible there. */
@media (pointer: coarse) {
  .story-tile__save {
    opacity: 1;
    transform: none;
    width: 44px;
    height: 44px;
  }
}

/* --------------------------------------------------------------- mobile */

@media (max-width: 599px) {
  .story-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 120px), 1fr));
  }

  .story-panel__actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .tt__field {
    flex-wrap: wrap;
    border-radius: var(--radius-lg);
    padding: var(--space-3);
  }

  .tt__input {
    flex-basis: calc(100% - 32px);
  }

  .tt__submit {
    flex-basis: 100%;
  }

  .tt-result {
    padding: var(--space-4);
  }

  .tt-result__cover {
    max-width: 240px;
    margin-inline: auto;
  }

  .tt-result__actions .btn {
    flex-basis: 100%;
  }
}

/* ---------------------------------------------------- YouTube Downloader */

.yt-workspace {
  max-width: 860px;
  margin: 0 auto var(--space-8);
}

.yt-search-wrap {
  width: 100%;
  margin-bottom: var(--space-5);
}

.yt-form {
  margin: 0;
}

.yt-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 6px 6px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.yt-field:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ring) 18%, transparent);
}

.yt-field__icon {
  display: flex;
  align-items: center;
  color: var(--fg-subtle);
  flex-shrink: 0;
}

.yt-field__input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: var(--text-base);
  outline: none;
}

.yt-field__input::placeholder {
  color: var(--fg-subtle);
}

.yt-field__btn {
  flex-shrink: 0;
  min-height: 46px;
  border-radius: var(--radius-pill);
  padding-inline: var(--space-5);
  font-weight: 600;
}

.yt-hint {
  margin: var(--space-2) 0 0;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

.yt-hint code {
  font-family: var(--font-mono);
  font-size: 0.95em;
  color: var(--fg-subtle);
}

/* Redesigned 2-Column Compact Result Card */
.yt-card {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05);
  align-items: start;
  animation: yt-in var(--dur-slow) var(--ease);
}

.yt-card[hidden] {
  display: none;
}

@keyframes yt-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.yt-card__media {
  width: 100%;
}

.yt-card__thumb-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.yt-card__thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.yt-card__duration-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: var(--text-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(4px);
}

.yt-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.yt-card__header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.yt-card__title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--fg);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.yt-card__channel-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

.yt-card__channel {
  font-weight: 600;
  color: var(--fg);
}

.yt-card__dot {
  color: var(--border-strong);
}

.yt-card__meta {
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

.yt-card__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.yt-card__actions-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
}

.yt-qualities-pills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-2);
}

.yt-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--fg);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: all var(--dur) var(--ease);
  cursor: pointer;
}

.yt-pill:hover {
  border-color: var(--primary);
  background: var(--surface-2);
  color: var(--fg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.yt-pill--best {
  background: color-mix(in srgb, var(--primary) 9%, var(--surface));
  border-color: var(--primary);
}

.yt-pill--best:hover {
  background: color-mix(in srgb, var(--primary) 16%, var(--surface));
  border-color: var(--primary-hover);
}

.yt-pill__info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.yt-pill__format {
  font-weight: 700;
  white-space: nowrap;
}

.yt-pill__badge {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  text-transform: uppercase;
}

.yt-pill__meta {
  font-size: var(--text-xs);
  color: var(--fg-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.yt-pill__icon {
  color: var(--primary);
  flex-shrink: 0;
  transition: transform var(--dur) var(--ease);
}

.yt-pill:hover .yt-pill__icon {
  transform: translateY(2px);
}

/* YouTube Audio Downloader Specifics */
.yt-audio-preview {
  width: 100%;
  margin-block: var(--space-1);
}

.yt-audio-player {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-pill);
  outline: none;
}

.yt-audio-dl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 48px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  text-decoration: none;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.yt-audio-dl-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.yt-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
}

.yt-card__legal {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--fg-subtle);
  margin: 0;
}

.yt-card__legal svg {
  color: var(--fg-subtle);
  flex-shrink: 0;
}

@media (max-width: 680px) {
  .yt-card {
    grid-template-columns: 1fr;
    gap: var(--space-4);
    padding: var(--space-4);
  }

  .yt-qualities-pills {
    grid-template-columns: 1fr 1fr;
  }

  .yt-field {
    padding: 4px 4px 4px 12px;
  }

  .yt-field__btn {
    padding-inline: var(--space-4);
  }
}

@media (max-width: 440px) {
  .yt-qualities-pills {
    grid-template-columns: 1fr;
  }
}