@layer components {
  .bookmark-favicon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    flex-shrink: 0;
  }

  /* Bookmark grid layout */
  .bookmark-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 4rem;

    @media (max-width: 480px) {
      grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
      gap: 0.6rem;
    }
  }

  .bookmark-grid-item {
    position: relative;
    background: transparent;
    border-radius: 12px;
    transition: background-color 0.4s ease;
  }

  .bookmark-grid-item[data-favorite-favorite=true] {
    background-color: #e4ffed;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.5);
  }

  .bookmark-grid-item[data-favorite-favorite=true] .bookmark-grid-favorite .grid-favorite-button {
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    color: white;
    background: #15803d;
    border-radius: 50%;
    filter: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 2px rgba(255, 255, 255, 0.9);
    --icon-size: 0.95rem;
  }

  @media (hover: hover) {
    .bookmark-grid-item[data-favorite-favorite=true] .bookmark-grid-favorite .grid-favorite-button:hover {
      background: #16a34a;
      color: white;
    }
  }

  .bookmark-grid-thumb {
    position: relative;
    display: block;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #111;
    border-radius: 12px;
  }

  .bookmark-grid-media {
    position: relative;
  }

  .bookmark-grid-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease-out;
  }

  .bookmark-grid-item:hover .bookmark-grid-thumb img {
    transform: scale(1.05);
  }

  .bookmark-grid-thumb-state {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #bbb;
    --icon-size: 1.75rem;
  }

  .bookmark-grid-thumb-spinner {
    animation: spin 1s linear infinite;
  }

  .bookmark-grid-thumb-empty {
    flex-direction: column;
    gap: 0.6rem;
    padding: 1rem;
    background: linear-gradient(135deg, #1f2937 0%, #312e81 50%, #4c1d95 100%);
    color: #c4b5fd;
  }

  .bookmark-grid-thumb-empty .bookmark-grid-placeholder-favicon {
    width: 2.25rem;
    height: 2.25rem;
    object-fit: contain;
  }

  .bookmark-grid-thumb-empty .bookmark-grid-placeholder-icon {
    --icon-size: 2.25rem;
  }

  .bookmark-grid-placeholder-domain {
    max-width: 100%;
    padding: 0 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: #ddd6fe;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .bookmark-grid-read-badge {
    position: absolute;
    left: 0.5rem;
    bottom: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.15rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
    color: white;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 4px;
    pointer-events: none;
    opacity: 0;
    --icon-size: 0.85rem;
  }

  .bookmark-grid-read-action {
    position: absolute;
    left: 0.35rem;
    bottom: 0.35rem;
    color: white;
    --icon-size: 1rem;
  }

  .bookmark-grid-read-action form {
    margin: 0;
  }

  .bookmark-grid-read-action .grid-read-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    color: white;
    background: rgba(17, 24, 39, 0.55);
    border: none;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 2px rgba(255, 255, 255, 0.9);
    filter: none;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  @media (hover: hover) {
    .bookmark-grid-read-action .grid-read-button:hover {
      background: rgba(17, 24, 39, 0.75);
    }
  }

  .bookmark-grid-item.is-read .bookmark-grid-read-action .grid-read-button {
    background: #7c3aed;
    color: white;
  }

  @media (hover: hover) {
    .bookmark-grid-item.is-read .bookmark-grid-read-action .grid-read-button:hover {
      background: #6d28d9;
      color: white;
    }
  }

  .bookmark-grid-body {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 0.75rem;
    padding: 0.75rem 0.25rem 0.5rem;
  }

  .bookmark-grid-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: #e5e7eb;
    flex-shrink: 0;
  }

  .bookmark-grid-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    --icon-size: 1rem;
  }

  .bookmark-grid-caption {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
  }

  .bookmark-grid-title {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    color: #111;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
  }

  .bookmark-grid-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: #6b7280;
    overflow: hidden;
  }

  .bookmark-grid-channel {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  .bookmark-grid-meta-sep {
    color: #9ca3af;
  }

  .bookmark-grid-item.is-read .bookmark-grid-thumb img,
  .bookmark-grid-item.is-read .bookmark-grid-thumb-state {
    opacity: 0.55;
  }

  .bookmark-grid-item.is-read .bookmark-grid-read-badge {
    opacity: 1;
  }

  .bookmark-grid-item.is-read:hover .bookmark-grid-read-badge,
  .bookmark-grid-item.is-read:focus-within .bookmark-grid-read-badge {
    opacity: 0;
  }

  .bookmark-grid-item.is-read .bookmark-grid-title,
  .bookmark-grid-item.is-read .bookmark-grid-meta,
  .bookmark-grid-item.is-read .bookmark-grid-avatar {
    color: #6b7280;
    opacity: 0.75;
  }

  .bookmark-grid-favorite,
  .bookmark-grid-menu {
    position: absolute;
    top: 0.35rem;
    color: white;
    --icon-size: 1rem;
  }

  .bookmark-grid-favorite {
    left: 0.35rem;
  }

  .bookmark-grid-menu {
    right: 0.35rem;
  }

  .bookmark-grid-favorite form {
    margin: 0;
  }

  .bookmark-grid-favorite .grid-favorite-button,
  .video-grid-favorite .grid-favorite-button,
  .image-grid-favorite .grid-favorite-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    color: white;
    background: rgba(17, 24, 39, 0.55);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 2px rgba(255, 255, 255, 0.9);
    filter: none;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  @media (hover: hover) {
    .bookmark-grid-favorite .grid-favorite-button:hover,
    .video-grid-favorite .grid-favorite-button:hover,
    .image-grid-favorite .grid-favorite-button:hover {
      background: rgba(17, 24, 39, 0.75);
    }
  }

  .bookmark-grid-menu .dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    border-radius: 50%;
    color: white;
    background: #7c3aed;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 2px rgba(255, 255, 255, 0.9);
    transition: background-color 0.15s ease;
    --icon-size: 1.25rem;
  }

  @media (hover: hover) {
    .bookmark-grid-menu .dropdown-toggle:hover {
      background: #6d28d9;
    }
  }

  @media (hover: hover) {
    .bookmark-grid-favorite,
    .bookmark-grid-menu,
    .bookmark-grid-read-action {
      opacity: 0;
      transition: opacity 0.15s ease;
    }

    .bookmark-grid-item:hover .bookmark-grid-favorite,
    .bookmark-grid-item:hover .bookmark-grid-menu,
    .bookmark-grid-item:hover .bookmark-grid-read-action,
    .bookmark-grid-item:focus-within .bookmark-grid-favorite,
    .bookmark-grid-item:focus-within .bookmark-grid-menu,
    .bookmark-grid-item:focus-within .bookmark-grid-read-action,
    .bookmark-grid-item[data-favorite-favorite=true] .bookmark-grid-favorite,
    .bookmark-grid-item.is-read .bookmark-grid-read-action {
      opacity: 1;
    }
  }

  /* Touch devices never fire the hover reveal above, so the action buttons
     would otherwise sit at full strength on every tile. Keep them one-tap
     reachable but quiet: smaller, glassy, monochrome. The favourite *state*
     is already legible from the tile's green ring/tint, so the buttons can
     recede. (Mirrors the photo grid treatment in images.css.) */
  @media (hover: none) {
    .bookmark-grid-favorite .grid-favorite-button,
    .bookmark-grid-menu .dropdown-toggle,
    .bookmark-grid-read-action .grid-read-button {
      width: 1.5rem;
      height: 1.5rem;
      background: rgba(15, 15, 15, 0.4);
      backdrop-filter: blur(8px);
      box-shadow: none;
      opacity: 0.65;
      --icon-size: 0.95rem;
    }

    .bookmark-grid-menu .dropdown-toggle {
      color: #fff;
    }

    /* Active states keep their colour so they still read as a status. */
    .bookmark-grid-item[data-favorite-favorite=true] .bookmark-grid-favorite .grid-favorite-button {
      width: 1.5rem;
      height: 1.5rem;
      background: #15803d;
      box-shadow: none;
      opacity: 1;
    }

    .bookmark-grid-item.is-read .bookmark-grid-read-action .grid-read-button {
      width: 1.5rem;
      height: 1.5rem;
      background: #7c3aed;
      box-shadow: none;
      opacity: 1;
    }
  }

  /* Leading favicon / fallback icon (fills the shared .item-row-lead slot). */
  .bookmark-row-icon-wrap {
    display: inline-flex;

    & > .icon {
      width: 24px;
      flex-shrink: 0;
    }

    & > .bookmark-favicon {
      width: 24px;
      height: 24px;
      object-fit: contain;
      flex-shrink: 0;
    }
  }

  .bookmark-row-read-badge {
    position: absolute;
    top: -0.1rem;
    right: -0.15rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    color: white;
    background: #7c3aed;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.95);
    opacity: 0;
    transition: opacity 0.15s ease;
    --icon-size: 0.65rem;
    pointer-events: none;
  }

  /* Read state */
  .bookmark-row.is-read .item-row-title-text,
  .bookmark-row.is-read .item-row-meta {
    color: #6b7280;
  }

  .bookmark-row.is-read .bookmark-row-icon-wrap {
    opacity: 0.65;
  }

  .bookmark-row.is-read .bookmark-row-read-badge {
    opacity: 1;
  }

  .bookmark-row-read {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #d1d5db;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    transition: color 0.3s ease, background-color 0.15s ease;
  }

  .bookmark-row-read:hover {
    color: #c4b5fd;
  }

  .bookmark-row.is-read .bookmark-row-read {
    color: white;
    background: #7c3aed;
    border-radius: 999px;
  }

  .bookmark-row.is-read .bookmark-row-read:hover {
    color: white;
    background: #6d28d9;
  }

  @media (max-width: 640px) {
    .bookmark-row-read {
      width: 1.55rem;
      height: 1.55rem;
      padding: 0;
      justify-content: center;
    }
  }
}
